mirror of https://github.com/bkaradzic/bgfx
14-shadowvolumes uses common mesh loader
This commit is contained in:
parent
d1ab0c175f
commit
04d532e085
|
@ -556,37 +556,6 @@ void touch(bgfx::ViewId _id)
|
|||
::submit(_id, handle);
|
||||
}
|
||||
|
||||
struct Aabb
|
||||
{
|
||||
float m_min[3];
|
||||
float m_max[3];
|
||||
};
|
||||
|
||||
struct Obb
|
||||
{
|
||||
float m_mtx[16];
|
||||
};
|
||||
|
||||
struct Sphere
|
||||
{
|
||||
float m_center[3];
|
||||
float m_radius;
|
||||
};
|
||||
|
||||
struct Primitive
|
||||
{
|
||||
uint32_t m_startIndex;
|
||||
uint32_t m_numIndices;
|
||||
uint32_t m_startVertex;
|
||||
uint32_t m_numVertices;
|
||||
|
||||
Sphere m_sphere;
|
||||
Aabb m_aabb;
|
||||
Obb m_obb;
|
||||
};
|
||||
|
||||
typedef std::vector<Primitive> PrimitiveArray;
|
||||
|
||||
struct Face
|
||||
{
|
||||
uint16_t m_i[3];
|
||||
|
@ -995,96 +964,37 @@ struct Mesh
|
|||
|
||||
void load(const char* _filePath)
|
||||
{
|
||||
#define BGFX_CHUNK_MAGIC_VB BX_MAKEFOURCC('V', 'B', ' ', 0x1)
|
||||
#define BGFX_CHUNK_MAGIC_IB BX_MAKEFOURCC('I', 'B', ' ', 0x0)
|
||||
#define BGFX_CHUNK_MAGIC_PRI BX_MAKEFOURCC('P', 'R', 'I', 0x0)
|
||||
|
||||
bx::FileReaderI* reader = entry::getFileReader();
|
||||
bx::open(reader, _filePath);
|
||||
|
||||
Group group;
|
||||
|
||||
uint32_t chunk;
|
||||
while (4 == bx::read(reader, chunk) )
|
||||
{
|
||||
switch (chunk)
|
||||
{
|
||||
case BGFX_CHUNK_MAGIC_VB:
|
||||
{
|
||||
bx::read(reader, group.m_sphere);
|
||||
bx::read(reader, group.m_aabb);
|
||||
bx::read(reader, group.m_obb);
|
||||
|
||||
bgfx::read(reader, m_decl);
|
||||
::Mesh* mesh = ::meshLoad(_filePath, true);
|
||||
m_decl = mesh->m_decl;
|
||||
uint16_t stride = m_decl.getStride();
|
||||
|
||||
bx::read(reader, group.m_numVertices);
|
||||
const uint32_t size = group.m_numVertices*stride;
|
||||
group.m_vertices = (uint8_t*)malloc(size);
|
||||
bx::read(reader, group.m_vertices, size);
|
||||
for (::GroupArray::iterator it = mesh->m_groups.begin(), itEnd = mesh->m_groups.end(); it != itEnd; ++it)
|
||||
{
|
||||
Group group;
|
||||
group.m_numVertices = it->m_numVertices;
|
||||
const uint32_t vertexSize = group.m_numVertices*stride;
|
||||
group.m_vertices = (uint8_t*)malloc(vertexSize);
|
||||
bx::memCopy(group.m_vertices, it->m_vertices, vertexSize);
|
||||
|
||||
const bgfx::Memory* mem = bgfx::makeRef(group.m_vertices, size);
|
||||
const bgfx::Memory* mem = bgfx::makeRef(group.m_vertices, vertexSize);
|
||||
group.m_vbh = bgfx::createVertexBuffer(mem, m_decl);
|
||||
}
|
||||
break;
|
||||
|
||||
case BGFX_CHUNK_MAGIC_IB:
|
||||
{
|
||||
bx::read(reader, group.m_numIndices);
|
||||
const uint32_t size = group.m_numIndices*2;
|
||||
group.m_indices = (uint16_t*)malloc(size);
|
||||
bx::read(reader, group.m_indices, size);
|
||||
group.m_numIndices = it->m_numIndices;
|
||||
const uint32_t indexSize = 2 * group.m_numIndices;
|
||||
group.m_indices = (uint16_t*)malloc(indexSize);
|
||||
bx::memCopy(group.m_indices, it->m_indices, indexSize);
|
||||
|
||||
const bgfx::Memory* mem = bgfx::makeRef(group.m_indices, size);
|
||||
mem = bgfx::makeRef(group.m_indices, indexSize);
|
||||
group.m_ibh = bgfx::createIndexBuffer(mem);
|
||||
}
|
||||
break;
|
||||
|
||||
case BGFX_CHUNK_MAGIC_PRI:
|
||||
{
|
||||
uint16_t len;
|
||||
bx::read(reader, len);
|
||||
|
||||
std::string material;
|
||||
material.resize(len);
|
||||
bx::read(reader, const_cast<char*>(material.c_str() ), len);
|
||||
|
||||
uint16_t num;
|
||||
bx::read(reader, num);
|
||||
|
||||
for (uint32_t ii = 0; ii < num; ++ii)
|
||||
{
|
||||
bx::read(reader, len);
|
||||
|
||||
std::string name;
|
||||
name.resize(len);
|
||||
bx::read(reader, const_cast<char*>(name.c_str() ), len);
|
||||
|
||||
Primitive prim;
|
||||
bx::read(reader, prim.m_startIndex);
|
||||
bx::read(reader, prim.m_numIndices);
|
||||
bx::read(reader, prim.m_startVertex);
|
||||
bx::read(reader, prim.m_numVertices);
|
||||
bx::read(reader, prim.m_sphere);
|
||||
bx::read(reader, prim.m_aabb);
|
||||
bx::read(reader, prim.m_obb);
|
||||
|
||||
group.m_prims.push_back(prim);
|
||||
}
|
||||
group.m_sphere = it->m_sphere;
|
||||
group.m_aabb = it->m_aabb;
|
||||
group.m_obb = it->m_obb;
|
||||
group.m_prims = it->m_prims;
|
||||
|
||||
m_groups.push_back(group);
|
||||
group.reset();
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
DBG("%08x at %d", chunk, bx::seek(reader) );
|
||||
abort();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bx::close(reader);
|
||||
::meshUnload(mesh);
|
||||
|
||||
for (GroupArray::iterator it = m_groups.begin(), itEnd = m_groups.end(); it != itEnd; ++it)
|
||||
{
|
||||
|
@ -1774,17 +1684,17 @@ bool clipTest(const float* _planes, uint8_t _planeNum, const Mesh& _mesh, const
|
|||
const Group& group = *it;
|
||||
|
||||
Sphere sphere = group.m_sphere;
|
||||
sphere.m_center[0] = sphere.m_center[0] * scale + _translate[0];
|
||||
sphere.m_center[1] = sphere.m_center[1] * scale + _translate[1];
|
||||
sphere.m_center[2] = sphere.m_center[2] * scale + _translate[2];
|
||||
sphere.m_radius *= (scale+0.4f);
|
||||
sphere.center.x = sphere.center.x * scale + _translate[0];
|
||||
sphere.center.y = sphere.center.y * scale + _translate[1];
|
||||
sphere.center.z = sphere.center.z * scale + _translate[2];
|
||||
sphere.radius *= (scale+0.4f);
|
||||
|
||||
bool isInside = true;
|
||||
for (uint8_t ii = 0; ii < _planeNum; ++ii)
|
||||
{
|
||||
const float* plane = volumePlanes[ii];
|
||||
|
||||
float positiveSide = bx::dot(bx::load<bx::Vec3>(plane), bx::load<bx::Vec3>(sphere.m_center) ) + plane[3] + sphere.m_radius;
|
||||
float positiveSide = bx::dot(bx::load<bx::Vec3>(plane), sphere.center ) + plane[3] + sphere.radius;
|
||||
|
||||
if (positiveSide < 0.0f)
|
||||
{
|
||||
|
|
|
@ -355,67 +355,30 @@ void calcTangents(void* _vertices, uint16_t _numVertices, bgfx::VertexDecl _decl
|
|||
delete [] tangents;
|
||||
}
|
||||
|
||||
struct Aabb
|
||||
{
|
||||
float m_min[3];
|
||||
float m_max[3];
|
||||
};
|
||||
|
||||
struct Obb
|
||||
{
|
||||
float m_mtx[16];
|
||||
};
|
||||
|
||||
struct Sphere
|
||||
{
|
||||
float m_center[3];
|
||||
float m_radius;
|
||||
};
|
||||
|
||||
struct Primitive
|
||||
{
|
||||
uint32_t m_startIndex;
|
||||
uint32_t m_numIndices;
|
||||
uint32_t m_startVertex;
|
||||
uint32_t m_numVertices;
|
||||
|
||||
Sphere m_sphere;
|
||||
Aabb m_aabb;
|
||||
Obb m_obb;
|
||||
};
|
||||
|
||||
typedef stl::vector<Primitive> PrimitiveArray;
|
||||
|
||||
struct Group
|
||||
{
|
||||
Group()
|
||||
Group::Group()
|
||||
{
|
||||
reset();
|
||||
}
|
||||
|
||||
void reset()
|
||||
void Group::reset()
|
||||
{
|
||||
m_vbh.idx = bgfx::kInvalidHandle;
|
||||
m_ibh.idx = bgfx::kInvalidHandle;
|
||||
m_numVertices = 0;
|
||||
m_vertices = NULL;
|
||||
m_numIndices = 0;
|
||||
m_indices = NULL;
|
||||
m_prims.clear();
|
||||
}
|
||||
|
||||
bgfx::VertexBufferHandle m_vbh;
|
||||
bgfx::IndexBufferHandle m_ibh;
|
||||
Sphere m_sphere;
|
||||
Aabb m_aabb;
|
||||
Obb m_obb;
|
||||
PrimitiveArray m_prims;
|
||||
};
|
||||
|
||||
namespace bgfx
|
||||
{
|
||||
int32_t read(bx::ReaderI* _reader, bgfx::VertexDecl& _decl, bx::Error* _err = NULL);
|
||||
}
|
||||
|
||||
struct Mesh
|
||||
{
|
||||
void load(bx::ReaderSeekerI* _reader)
|
||||
void Mesh::load(bx::ReaderSeekerI* _reader, bool _ramcopy)
|
||||
{
|
||||
#define BGFX_CHUNK_MAGIC_VB BX_MAKEFOURCC('V', 'B', ' ', 0x1)
|
||||
#define BGFX_CHUNK_MAGIC_VBC BX_MAKEFOURCC('V', 'B', 'C', 0x0)
|
||||
|
@ -447,11 +410,14 @@ struct Mesh
|
|||
|
||||
uint16_t stride = m_decl.getStride();
|
||||
|
||||
uint16_t numVertices;
|
||||
read(_reader, numVertices);
|
||||
const bgfx::Memory* mem = bgfx::alloc(numVertices*stride);
|
||||
read(_reader, group.m_numVertices);
|
||||
const bgfx::Memory* mem = bgfx::alloc(group.m_numVertices*stride);
|
||||
read(_reader, mem->data, mem->size);
|
||||
|
||||
if ( _ramcopy )
|
||||
{
|
||||
group.m_vertices = (uint8_t*)BX_ALLOC(allocator, group.m_numVertices*stride);
|
||||
bx::memCopy(group.m_vertices, mem->data, mem->size);
|
||||
}
|
||||
group.m_vbh = bgfx::createVertexBuffer(mem, m_decl);
|
||||
}
|
||||
break;
|
||||
|
@ -466,10 +432,9 @@ struct Mesh
|
|||
|
||||
uint16_t stride = m_decl.getStride();
|
||||
|
||||
uint16_t numVertices;
|
||||
read(_reader, numVertices);
|
||||
read(_reader, group.m_numVertices);
|
||||
|
||||
const bgfx::Memory* mem = bgfx::alloc(numVertices*stride);
|
||||
const bgfx::Memory* mem = bgfx::alloc(group.m_numVertices*stride);
|
||||
|
||||
uint32_t compressedSize;
|
||||
bx::read(_reader, compressedSize);
|
||||
|
@ -477,30 +442,40 @@ struct Mesh
|
|||
void* compressedVertices = BX_ALLOC(allocator, compressedSize);
|
||||
bx::read(_reader, compressedVertices, compressedSize);
|
||||
|
||||
meshopt_decodeVertexBuffer(mem->data, numVertices, stride, (uint8_t*)compressedVertices, compressedSize);
|
||||
meshopt_decodeVertexBuffer(mem->data, group.m_numVertices, stride, (uint8_t*)compressedVertices, compressedSize);
|
||||
|
||||
BX_FREE(allocator, compressedVertices);
|
||||
|
||||
if ( _ramcopy )
|
||||
{
|
||||
group.m_vertices = (uint8_t*)BX_ALLOC(allocator, group.m_numVertices*stride);
|
||||
bx::memCopy(group.m_vertices, mem->data, mem->size);
|
||||
}
|
||||
|
||||
group.m_vbh = bgfx::createVertexBuffer(mem, m_decl);
|
||||
}
|
||||
break;
|
||||
|
||||
case BGFX_CHUNK_MAGIC_IB:
|
||||
{
|
||||
uint32_t numIndices;
|
||||
read(_reader, numIndices);
|
||||
const bgfx::Memory* mem = bgfx::alloc(numIndices*2);
|
||||
read(_reader, group.m_numIndices);
|
||||
const bgfx::Memory* mem = bgfx::alloc(group.m_numIndices*2);
|
||||
read(_reader, mem->data, mem->size);
|
||||
if ( _ramcopy )
|
||||
{
|
||||
group.m_indices = (uint16_t*)BX_ALLOC(allocator, group.m_numIndices*2);
|
||||
bx::memCopy(group.m_indices, mem->data, mem->size);
|
||||
}
|
||||
|
||||
group.m_ibh = bgfx::createIndexBuffer(mem);
|
||||
}
|
||||
break;
|
||||
|
||||
case BGFX_CHUNK_MAGIC_IBC:
|
||||
{
|
||||
uint32_t numIndices;
|
||||
bx::read(_reader, numIndices);
|
||||
bx::read(_reader, group.m_numIndices);
|
||||
|
||||
const bgfx::Memory* mem = bgfx::alloc(numIndices*2);
|
||||
const bgfx::Memory* mem = bgfx::alloc(group.m_numIndices*2);
|
||||
|
||||
uint32_t compressedSize;
|
||||
bx::read(_reader, compressedSize);
|
||||
|
@ -509,10 +484,16 @@ struct Mesh
|
|||
|
||||
bx::read(_reader, compressedIndices, compressedSize);
|
||||
|
||||
meshopt_decodeIndexBuffer(mem->data, numIndices, 2, (uint8_t*)compressedIndices, compressedSize);
|
||||
meshopt_decodeIndexBuffer(mem->data, group.m_numIndices, 2, (uint8_t*)compressedIndices, compressedSize);
|
||||
|
||||
BX_FREE(allocator, compressedIndices);
|
||||
|
||||
if ( _ramcopy )
|
||||
{
|
||||
group.m_indices = (uint16_t*)BX_ALLOC(allocator, group.m_numIndices*2);
|
||||
bx::memCopy(group.m_indices, mem->data, mem->size);
|
||||
}
|
||||
|
||||
group.m_ibh = bgfx::createIndexBuffer(mem);
|
||||
}
|
||||
break;
|
||||
|
@ -561,8 +542,10 @@ struct Mesh
|
|||
}
|
||||
}
|
||||
|
||||
void unload()
|
||||
void Mesh::unload()
|
||||
{
|
||||
bx::AllocatorI* allocator = entry::getAllocator();
|
||||
|
||||
for (GroupArray::const_iterator it = m_groups.begin(), itEnd = m_groups.end(); it != itEnd; ++it)
|
||||
{
|
||||
const Group& group = *it;
|
||||
|
@ -572,11 +555,21 @@ struct Mesh
|
|||
{
|
||||
bgfx::destroy(group.m_ibh);
|
||||
}
|
||||
|
||||
if ( NULL != group.m_vertices )
|
||||
{
|
||||
BX_FREE(allocator, group.m_vertices);
|
||||
}
|
||||
|
||||
if ( NULL != group.m_indices )
|
||||
{
|
||||
BX_FREE(allocator, group.m_indices);
|
||||
}
|
||||
}
|
||||
m_groups.clear();
|
||||
}
|
||||
|
||||
void submit(bgfx::ViewId _id, bgfx::ProgramHandle _program, const float* _mtx, uint64_t _state) const
|
||||
void Mesh::submit(bgfx::ViewId _id, bgfx::ProgramHandle _program, const float* _mtx, uint64_t _state) const
|
||||
{
|
||||
if (BGFX_STATE_MASK == _state)
|
||||
{
|
||||
|
@ -603,7 +596,7 @@ struct Mesh
|
|||
}
|
||||
}
|
||||
|
||||
void submit(const MeshState*const* _state, uint8_t _numPasses, const float* _mtx, uint16_t _numMatrices) const
|
||||
void Mesh::submit(const MeshState*const* _state, uint8_t _numPasses, const float* _mtx, uint16_t _numMatrices) const
|
||||
{
|
||||
uint32_t cached = bgfx::setTransform(_mtx, _numMatrices);
|
||||
|
||||
|
@ -635,24 +628,19 @@ struct Mesh
|
|||
}
|
||||
}
|
||||
|
||||
bgfx::VertexDecl m_decl;
|
||||
typedef stl::vector<Group> GroupArray;
|
||||
GroupArray m_groups;
|
||||
};
|
||||
|
||||
Mesh* meshLoad(bx::ReaderSeekerI* _reader)
|
||||
Mesh* meshLoad(bx::ReaderSeekerI* _reader, bool _ramcopy)
|
||||
{
|
||||
Mesh* mesh = new Mesh;
|
||||
mesh->load(_reader);
|
||||
mesh->load(_reader, _ramcopy);
|
||||
return mesh;
|
||||
}
|
||||
|
||||
Mesh* meshLoad(const char* _filePath)
|
||||
Mesh* meshLoad(const char* _filePath, bool _ramcopy)
|
||||
{
|
||||
bx::FileReaderI* reader = entry::getFileReader();
|
||||
if (bx::open(reader, _filePath) )
|
||||
{
|
||||
Mesh* mesh = meshLoad(reader);
|
||||
Mesh* mesh = meshLoad(reader, _ramcopy);
|
||||
bx::close(reader);
|
||||
return mesh;
|
||||
}
|
||||
|
|
|
@ -9,6 +9,12 @@
|
|||
#include <bx/pixelformat.h>
|
||||
#include <bgfx/bgfx.h>
|
||||
#include <bimg/bimg.h>
|
||||
#include "bounds.h"
|
||||
|
||||
#include <tinystl/allocator.h>
|
||||
#include <tinystl/vector.h>
|
||||
namespace stl = tinystl;
|
||||
|
||||
|
||||
///
|
||||
void* load(const char* _filePath, uint32_t* _size = NULL);
|
||||
|
@ -78,10 +84,51 @@ struct MeshState
|
|||
bgfx::ViewId m_viewId;
|
||||
};
|
||||
|
||||
struct Mesh;
|
||||
struct Primitive
|
||||
{
|
||||
uint32_t m_startIndex;
|
||||
uint32_t m_numIndices;
|
||||
uint32_t m_startVertex;
|
||||
uint32_t m_numVertices;
|
||||
|
||||
Sphere m_sphere;
|
||||
Aabb m_aabb;
|
||||
Obb m_obb;
|
||||
};
|
||||
|
||||
typedef stl::vector<Primitive> PrimitiveArray;
|
||||
|
||||
struct Group
|
||||
{
|
||||
Group();
|
||||
void reset();
|
||||
|
||||
bgfx::VertexBufferHandle m_vbh;
|
||||
bgfx::IndexBufferHandle m_ibh;
|
||||
uint16_t m_numVertices;
|
||||
uint8_t* m_vertices;
|
||||
uint32_t m_numIndices;
|
||||
uint16_t* m_indices;
|
||||
Sphere m_sphere;
|
||||
Aabb m_aabb;
|
||||
Obb m_obb;
|
||||
PrimitiveArray m_prims;
|
||||
};
|
||||
typedef stl::vector<Group> GroupArray;
|
||||
|
||||
struct Mesh
|
||||
{
|
||||
void load(bx::ReaderSeekerI* _reader, bool _ramcopy);
|
||||
void unload();
|
||||
void submit(bgfx::ViewId _id, bgfx::ProgramHandle _program, const float* _mtx, uint64_t _state) const;
|
||||
void submit(const MeshState*const* _state, uint8_t _numPasses, const float* _mtx, uint16_t _numMatrices) const;
|
||||
|
||||
bgfx::VertexDecl m_decl;
|
||||
GroupArray m_groups;
|
||||
};
|
||||
|
||||
///
|
||||
Mesh* meshLoad(const char* _filePath);
|
||||
Mesh* meshLoad(const char* _filePath, bool _ramcopy = false);
|
||||
|
||||
///
|
||||
void meshUnload(Mesh* _mesh);
|
||||
|
|
|
@ -528,7 +528,7 @@ struct Program
|
|||
};
|
||||
};
|
||||
|
||||
struct Mesh
|
||||
struct DebugMesh
|
||||
{
|
||||
enum Enum
|
||||
{
|
||||
|
@ -640,8 +640,8 @@ struct DebugDrawShared
|
|||
s_texColor = bgfx::createUniform("s_texColor", bgfx::UniformType::Sampler);
|
||||
m_texture = bgfx::createTexture2D(SPRITE_TEXTURE_SIZE, SPRITE_TEXTURE_SIZE, false, 1, bgfx::TextureFormat::BGRA8);
|
||||
|
||||
void* vertices[Mesh::Count] = {};
|
||||
uint16_t* indices[Mesh::Count] = {};
|
||||
void* vertices[DebugMesh::Count] = {};
|
||||
uint16_t* indices[DebugMesh::Count] = {};
|
||||
uint16_t stride = DebugShapeVertex::ms_decl.getStride();
|
||||
|
||||
uint32_t startVertex = 0;
|
||||
|
@ -649,7 +649,7 @@ struct DebugDrawShared
|
|||
|
||||
for (uint32_t mesh = 0; mesh < 4; ++mesh)
|
||||
{
|
||||
Mesh::Enum id = Mesh::Enum(Mesh::Sphere0+mesh);
|
||||
DebugMesh::Enum id = DebugMesh::Enum(DebugMesh::Sphere0+mesh);
|
||||
|
||||
const uint8_t tess = uint8_t(3-mesh);
|
||||
const uint32_t numVertices = genSphere(tess);
|
||||
|
@ -701,7 +701,7 @@ struct DebugDrawShared
|
|||
|
||||
for (uint32_t mesh = 0; mesh < 4; ++mesh)
|
||||
{
|
||||
Mesh::Enum id = Mesh::Enum(Mesh::Cone0+mesh);
|
||||
DebugMesh::Enum id = DebugMesh::Enum(DebugMesh::Cone0+mesh);
|
||||
|
||||
const uint32_t num = getCircleLod(uint8_t(mesh) );
|
||||
const float step = bx::kPi * 2.0f / num;
|
||||
|
@ -762,7 +762,7 @@ struct DebugDrawShared
|
|||
|
||||
for (uint32_t mesh = 0; mesh < 4; ++mesh)
|
||||
{
|
||||
Mesh::Enum id = Mesh::Enum(Mesh::Cylinder0+mesh);
|
||||
DebugMesh::Enum id = DebugMesh::Enum(DebugMesh::Cylinder0+mesh);
|
||||
|
||||
const uint32_t num = getCircleLod(uint8_t(mesh) );
|
||||
const float step = bx::kPi * 2.0f / num;
|
||||
|
@ -832,7 +832,7 @@ struct DebugDrawShared
|
|||
|
||||
for (uint32_t mesh = 0; mesh < 4; ++mesh)
|
||||
{
|
||||
Mesh::Enum id = Mesh::Enum(Mesh::Capsule0+mesh);
|
||||
DebugMesh::Enum id = DebugMesh::Enum(DebugMesh::Capsule0+mesh);
|
||||
|
||||
const uint32_t num = getCircleLod(uint8_t(mesh) );
|
||||
const float step = bx::kPi * 2.0f / num;
|
||||
|
@ -900,30 +900,30 @@ struct DebugDrawShared
|
|||
startIndex += numIndices + numLineListIndices;
|
||||
}
|
||||
|
||||
m_mesh[Mesh::Quad].m_startVertex = startVertex;
|
||||
m_mesh[Mesh::Quad].m_numVertices = BX_COUNTOF(s_quadVertices);
|
||||
m_mesh[Mesh::Quad].m_startIndex[0] = startIndex;
|
||||
m_mesh[Mesh::Quad].m_numIndices[0] = BX_COUNTOF(s_quadIndices);
|
||||
m_mesh[Mesh::Quad].m_startIndex[1] = 0;
|
||||
m_mesh[Mesh::Quad].m_numIndices[1] = 0;
|
||||
m_mesh[DebugMesh::Quad].m_startVertex = startVertex;
|
||||
m_mesh[DebugMesh::Quad].m_numVertices = BX_COUNTOF(s_quadVertices);
|
||||
m_mesh[DebugMesh::Quad].m_startIndex[0] = startIndex;
|
||||
m_mesh[DebugMesh::Quad].m_numIndices[0] = BX_COUNTOF(s_quadIndices);
|
||||
m_mesh[DebugMesh::Quad].m_startIndex[1] = 0;
|
||||
m_mesh[DebugMesh::Quad].m_numIndices[1] = 0;
|
||||
startVertex += BX_COUNTOF(s_quadVertices);
|
||||
startIndex += BX_COUNTOF(s_quadIndices);
|
||||
|
||||
m_mesh[Mesh::Cube].m_startVertex = startVertex;
|
||||
m_mesh[Mesh::Cube].m_numVertices = BX_COUNTOF(s_cubeVertices);
|
||||
m_mesh[Mesh::Cube].m_startIndex[0] = startIndex;
|
||||
m_mesh[Mesh::Cube].m_numIndices[0] = BX_COUNTOF(s_cubeIndices);
|
||||
m_mesh[Mesh::Cube].m_startIndex[1] = 0;
|
||||
m_mesh[Mesh::Cube].m_numIndices[1] = 0;
|
||||
startVertex += m_mesh[Mesh::Cube].m_numVertices;
|
||||
startIndex += m_mesh[Mesh::Cube].m_numIndices[0];
|
||||
m_mesh[DebugMesh::Cube].m_startVertex = startVertex;
|
||||
m_mesh[DebugMesh::Cube].m_numVertices = BX_COUNTOF(s_cubeVertices);
|
||||
m_mesh[DebugMesh::Cube].m_startIndex[0] = startIndex;
|
||||
m_mesh[DebugMesh::Cube].m_numIndices[0] = BX_COUNTOF(s_cubeIndices);
|
||||
m_mesh[DebugMesh::Cube].m_startIndex[1] = 0;
|
||||
m_mesh[DebugMesh::Cube].m_numIndices[1] = 0;
|
||||
startVertex += m_mesh[DebugMesh::Cube].m_numVertices;
|
||||
startIndex += m_mesh[DebugMesh::Cube].m_numIndices[0];
|
||||
|
||||
const bgfx::Memory* vb = bgfx::alloc(startVertex*stride);
|
||||
const bgfx::Memory* ib = bgfx::alloc(startIndex*sizeof(uint16_t) );
|
||||
|
||||
for (uint32_t mesh = Mesh::Sphere0; mesh < Mesh::Quad; ++mesh)
|
||||
for (uint32_t mesh = DebugMesh::Sphere0; mesh < DebugMesh::Quad; ++mesh)
|
||||
{
|
||||
Mesh::Enum id = Mesh::Enum(mesh);
|
||||
DebugMesh::Enum id = DebugMesh::Enum(mesh);
|
||||
bx::memCopy(&vb->data[m_mesh[id].m_startVertex * stride]
|
||||
, vertices[id]
|
||||
, m_mesh[id].m_numVertices*stride
|
||||
|
@ -938,22 +938,22 @@ struct DebugDrawShared
|
|||
BX_FREE(m_allocator, indices[id]);
|
||||
}
|
||||
|
||||
bx::memCopy(&vb->data[m_mesh[Mesh::Quad].m_startVertex * stride]
|
||||
bx::memCopy(&vb->data[m_mesh[DebugMesh::Quad].m_startVertex * stride]
|
||||
, s_quadVertices
|
||||
, sizeof(s_quadVertices)
|
||||
);
|
||||
|
||||
bx::memCopy(&ib->data[m_mesh[Mesh::Quad].m_startIndex[0] * sizeof(uint16_t)]
|
||||
bx::memCopy(&ib->data[m_mesh[DebugMesh::Quad].m_startIndex[0] * sizeof(uint16_t)]
|
||||
, s_quadIndices
|
||||
, sizeof(s_quadIndices)
|
||||
);
|
||||
|
||||
bx::memCopy(&vb->data[m_mesh[Mesh::Cube].m_startVertex * stride]
|
||||
bx::memCopy(&vb->data[m_mesh[DebugMesh::Cube].m_startVertex * stride]
|
||||
, s_cubeVertices
|
||||
, sizeof(s_cubeVertices)
|
||||
);
|
||||
|
||||
bx::memCopy(&ib->data[m_mesh[Mesh::Cube].m_startIndex[0] * sizeof(uint16_t)]
|
||||
bx::memCopy(&ib->data[m_mesh[DebugMesh::Cube].m_startIndex[0] * sizeof(uint16_t)]
|
||||
, s_cubeIndices
|
||||
, sizeof(s_cubeIndices)
|
||||
);
|
||||
|
@ -1017,7 +1017,7 @@ struct DebugDrawShared
|
|||
Sprite m_sprite;
|
||||
Geometry m_geometry;
|
||||
|
||||
Mesh m_mesh[Mesh::Count];
|
||||
DebugMesh m_mesh[DebugMesh::Count];
|
||||
|
||||
bgfx::UniformHandle s_texColor;
|
||||
bgfx::TextureHandle m_texture;
|
||||
|
@ -1432,7 +1432,7 @@ struct DebugDrawEncoderImpl
|
|||
{
|
||||
Obb obb;
|
||||
toObb(obb, _aabb);
|
||||
draw(Mesh::Cube, obb.mtx, 1, false);
|
||||
draw(DebugMesh::Cube, obb.mtx, 1, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1481,7 +1481,7 @@ struct DebugDrawEncoderImpl
|
|||
}
|
||||
else
|
||||
{
|
||||
draw(Mesh::Cube, _obb.mtx, 1, false);
|
||||
draw(DebugMesh::Cube, _obb.mtx, 1, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1500,11 +1500,11 @@ struct DebugDrawEncoderImpl
|
|||
, _sphere.center.y
|
||||
, _sphere.center.z
|
||||
);
|
||||
uint8_t lod = attrib.m_lod > Mesh::SphereMaxLod
|
||||
? uint8_t(Mesh::SphereMaxLod)
|
||||
uint8_t lod = attrib.m_lod > DebugMesh::SphereMaxLod
|
||||
? uint8_t(DebugMesh::SphereMaxLod)
|
||||
: attrib.m_lod
|
||||
;
|
||||
draw(Mesh::Enum(Mesh::Sphere0 + lod), mtx, 1, attrib.m_wireframe);
|
||||
draw(DebugMesh::Enum(DebugMesh::Sphere0 + lod), mtx, 1, attrib.m_wireframe);
|
||||
}
|
||||
|
||||
void draw(const Triangle& _triangle)
|
||||
|
@ -1855,7 +1855,7 @@ struct DebugDrawEncoderImpl
|
|||
{
|
||||
float mtx[16];
|
||||
bx::mtxFromNormal(mtx, _normal, _size*0.5f, _center, attrib.m_spin);
|
||||
draw(Mesh::Quad, mtx, 1, false);
|
||||
draw(DebugMesh::Quad, mtx, 1, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1941,11 +1941,11 @@ struct DebugDrawEncoderImpl
|
|||
mtx[1][13] = _to.y;
|
||||
mtx[1][14] = _to.z;
|
||||
|
||||
uint8_t lod = attrib.m_lod > Mesh::ConeMaxLod
|
||||
? uint8_t(Mesh::ConeMaxLod)
|
||||
uint8_t lod = attrib.m_lod > DebugMesh::ConeMaxLod
|
||||
? uint8_t(DebugMesh::ConeMaxLod)
|
||||
: attrib.m_lod
|
||||
;
|
||||
draw(Mesh::Enum(Mesh::Cone0 + lod), mtx[0], 2, attrib.m_wireframe);
|
||||
draw(DebugMesh::Enum(DebugMesh::Cone0 + lod), mtx[0], 2, attrib.m_wireframe);
|
||||
}
|
||||
|
||||
void drawCylinder(const bx::Vec3& _from, const bx::Vec3& _to, float _radius, bool _capsule)
|
||||
|
@ -1963,11 +1963,11 @@ struct DebugDrawEncoderImpl
|
|||
|
||||
if (_capsule)
|
||||
{
|
||||
uint8_t lod = attrib.m_lod > Mesh::CapsuleMaxLod
|
||||
? uint8_t(Mesh::CapsuleMaxLod)
|
||||
uint8_t lod = attrib.m_lod > DebugMesh::CapsuleMaxLod
|
||||
? uint8_t(DebugMesh::CapsuleMaxLod)
|
||||
: attrib.m_lod
|
||||
;
|
||||
draw(Mesh::Enum(Mesh::Capsule0 + lod), mtx[0], 2, attrib.m_wireframe);
|
||||
draw(DebugMesh::Enum(DebugMesh::Capsule0 + lod), mtx[0], 2, attrib.m_wireframe);
|
||||
|
||||
Sphere sphere;
|
||||
sphere.center = _from;
|
||||
|
@ -1979,11 +1979,11 @@ struct DebugDrawEncoderImpl
|
|||
}
|
||||
else
|
||||
{
|
||||
uint8_t lod = attrib.m_lod > Mesh::CylinderMaxLod
|
||||
? uint8_t(Mesh::CylinderMaxLod)
|
||||
uint8_t lod = attrib.m_lod > DebugMesh::CylinderMaxLod
|
||||
? uint8_t(DebugMesh::CylinderMaxLod)
|
||||
: attrib.m_lod
|
||||
;
|
||||
draw(Mesh::Enum(Mesh::Cylinder0 + lod), mtx[0], 2, attrib.m_wireframe);
|
||||
draw(DebugMesh::Enum(DebugMesh::Cylinder0 + lod), mtx[0], 2, attrib.m_wireframe);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2125,11 +2125,11 @@ struct DebugDrawEncoderImpl
|
|||
pop();
|
||||
}
|
||||
|
||||
void draw(Mesh::Enum _mesh, const float* _mtx, uint16_t _num, bool _wireframe)
|
||||
void draw(DebugMesh::Enum _mesh, const float* _mtx, uint16_t _num, bool _wireframe)
|
||||
{
|
||||
pushTransform(_mtx, _num, false /* flush */);
|
||||
|
||||
const Mesh& mesh = s_dds.m_mesh[_mesh];
|
||||
const DebugMesh& mesh = s_dds.m_mesh[_mesh];
|
||||
|
||||
if (0 != mesh.m_numIndices[_wireframe])
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue