mirror of
https://github.com/bkaradzic/bgfx.git
synced 2026-02-18 04:53:06 +01:00
Cleanup.
This commit is contained in:
@@ -16,6 +16,8 @@ namespace stl = tinystl;
|
||||
#include "entry/entry.h"
|
||||
#include <ib-compress/indexbufferdecompression.h>
|
||||
|
||||
#include "bgfx_utils.h"
|
||||
|
||||
void* load(bx::FileReaderI* _reader, const char* _filePath)
|
||||
{
|
||||
if (0 == bx::open(_reader, _filePath) )
|
||||
@@ -214,7 +216,7 @@ void calcTangents(void* _vertices, uint16_t _numVertices, bgfx::VertexDecl _decl
|
||||
}
|
||||
|
||||
delete [] tangents;
|
||||
}
|
||||
}
|
||||
|
||||
struct Aabb
|
||||
{
|
||||
@@ -288,6 +290,8 @@ struct Mesh
|
||||
|
||||
Group group;
|
||||
|
||||
bx::ReallocatorI* allocator = entry::getAllocator();
|
||||
|
||||
uint32_t chunk;
|
||||
while (4 == bx::read(_reader, chunk) )
|
||||
{
|
||||
@@ -332,15 +336,14 @@ struct Mesh
|
||||
uint32_t compressedSize;
|
||||
bx::read(_reader, compressedSize);
|
||||
|
||||
bx::CrtAllocator allocator;
|
||||
void* compressedIndices = BX_ALLOC(&allocator, compressedSize);
|
||||
void* compressedIndices = BX_ALLOC(allocator, compressedSize);
|
||||
|
||||
bx::read(_reader, compressedIndices, compressedSize);
|
||||
|
||||
ReadBitstream rbs( (const uint8_t*)compressedIndices, compressedSize);
|
||||
DecompressIndexBuffer( (uint16_t*)mem->data, numIndices / 3, rbs);
|
||||
|
||||
BX_FREE(&allocator, compressedIndices);
|
||||
BX_FREE(allocator, compressedIndices);
|
||||
|
||||
group.m_ibh = bgfx::createIndexBuffer(mem);
|
||||
}
|
||||
@@ -405,7 +408,7 @@ struct Mesh
|
||||
m_groups.clear();
|
||||
}
|
||||
|
||||
void submit(uint8_t _id, bgfx::ProgramHandle _program, float* _mtx, uint64_t _state)
|
||||
void submit(uint8_t _id, bgfx::ProgramHandle _program, const float* _mtx, uint64_t _state) const
|
||||
{
|
||||
if (BGFX_STATE_MASK == _state)
|
||||
{
|
||||
@@ -419,12 +422,13 @@ struct Mesh
|
||||
;
|
||||
}
|
||||
|
||||
uint32_t cached = bgfx::setTransform(_mtx);
|
||||
|
||||
for (GroupArray::const_iterator it = m_groups.begin(), itEnd = m_groups.end(); it != itEnd; ++it)
|
||||
{
|
||||
const Group& group = *it;
|
||||
|
||||
// Set model matrix for rendering.
|
||||
bgfx::setTransform(_mtx);
|
||||
bgfx::setTransform(cached);
|
||||
bgfx::setProgram(_program);
|
||||
bgfx::setIndexBuffer(group.m_ibh);
|
||||
bgfx::setVertexBuffer(group.m_vbh);
|
||||
@@ -433,6 +437,37 @@ struct Mesh
|
||||
}
|
||||
}
|
||||
|
||||
void submit(const MeshState*const* _state, uint8_t _numPasses, const float* _mtx, uint16_t _numMatrices) const
|
||||
{
|
||||
uint32_t cached = bgfx::setTransform(_mtx, _numMatrices);
|
||||
|
||||
for (uint32_t pass = 0; pass < _numPasses; ++pass)
|
||||
{
|
||||
const MeshState& state = *_state[pass];
|
||||
|
||||
for (GroupArray::const_iterator it = m_groups.begin(), itEnd = m_groups.end(); it != itEnd; ++it)
|
||||
{
|
||||
const Group& group = *it;
|
||||
|
||||
bgfx::setTransform(cached, _numMatrices);
|
||||
for (uint8_t tex = 0; tex < state.m_numTextures; ++tex)
|
||||
{
|
||||
const MeshState::Texture& texture = state.m_textures[tex];
|
||||
bgfx::setTexture(texture.m_stage
|
||||
, texture.m_sampler
|
||||
, texture.m_texture
|
||||
, texture.m_flags
|
||||
);
|
||||
}
|
||||
bgfx::setProgram(state.m_program);
|
||||
bgfx::setIndexBuffer(group.m_ibh);
|
||||
bgfx::setVertexBuffer(group.m_vbh);
|
||||
bgfx::setState(state.m_state);
|
||||
bgfx::submit(state.m_viewId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bgfx::VertexDecl m_decl;
|
||||
typedef stl::vector<Group> GroupArray;
|
||||
GroupArray m_groups;
|
||||
@@ -460,7 +495,23 @@ void meshUnload(Mesh* _mesh)
|
||||
delete _mesh;
|
||||
}
|
||||
|
||||
void meshSubmit(Mesh* _mesh, uint8_t _id, bgfx::ProgramHandle _program, float* _mtx, uint64_t _state)
|
||||
MeshState* meshStateCreate()
|
||||
{
|
||||
MeshState* state = (MeshState*)BX_ALLOC(entry::getAllocator(), sizeof(MeshState) );
|
||||
return state;
|
||||
}
|
||||
|
||||
void meshStateDestroy(MeshState* _meshState)
|
||||
{
|
||||
BX_FREE(entry::getAllocator(), _meshState);
|
||||
}
|
||||
|
||||
void meshSubmit(const Mesh* _mesh, uint8_t _id, bgfx::ProgramHandle _program, const float* _mtx, uint64_t _state)
|
||||
{
|
||||
_mesh->submit(_id, _program, _mtx, _state);
|
||||
}
|
||||
|
||||
void meshSubmit(const Mesh* _mesh, const MeshState*const* _state, uint8_t _numPasses, const float* _mtx, uint16_t _numMatrices)
|
||||
{
|
||||
_mesh->submit(_state, _numPasses, _mtx, _numMatrices);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user