mirror of
https://github.com/scratchfoundation/bgfx.git
synced 2024-12-01 03:47:07 -05:00
Fixed warnings.
This commit is contained in:
parent
1bc2ec8015
commit
c2eda31fca
3 changed files with 163 additions and 163 deletions
|
@ -99,7 +99,7 @@ namespace Forsyth
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const uint kMaxVertexCacheSize = 64;
|
const int kMaxVertexCacheSize = 64;
|
||||||
const uint kMaxPrecomputedVertexValenceScores = 64;
|
const uint kMaxPrecomputedVertexValenceScores = 64;
|
||||||
float s_vertexCacheScores[kMaxVertexCacheSize+1][kMaxVertexCacheSize];
|
float s_vertexCacheScores[kMaxVertexCacheSize+1][kMaxVertexCacheSize];
|
||||||
float s_vertexValenceScores[kMaxPrecomputedVertexValenceScores];
|
float s_vertexValenceScores[kMaxPrecomputedVertexValenceScores];
|
||||||
|
|
|
@ -117,7 +117,7 @@ Updating shader uniforms.
|
||||||
![example-03-raymarch](https://github.com/bkaradzic/bgfx/raw/master/examples/03-raymarch/screenshot.png)
|
![example-03-raymarch](https://github.com/bkaradzic/bgfx/raw/master/examples/03-raymarch/screenshot.png)
|
||||||
|
|
||||||
### 04-mesh
|
### 04-mesh
|
||||||
Loading OpenCTM meshes.
|
Loading meshes.
|
||||||
|
|
||||||
![example-04-mesh](https://github.com/bkaradzic/bgfx/raw/master/examples/04-mesh/screenshot.png)
|
![example-04-mesh](https://github.com/bkaradzic/bgfx/raw/master/examples/04-mesh/screenshot.png)
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,8 @@
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
void fatalCb(bgfx::Fatal::Enum _code, const char* _str)
|
void fatalCb(bgfx::Fatal::Enum _code, const char* _str)
|
||||||
|
@ -87,167 +89,165 @@ static bgfx::ProgramHandle loadProgram(const char* _vsName, const char* _fsName)
|
||||||
return program;
|
return program;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Aabb
|
struct Aabb
|
||||||
{
|
{
|
||||||
float m_min[3];
|
float m_min[3];
|
||||||
float m_max[3];
|
float m_max[3];
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Obb
|
struct Obb
|
||||||
{
|
{
|
||||||
float m_mtx[16];
|
float m_mtx[16];
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Sphere
|
struct Sphere
|
||||||
{
|
{
|
||||||
float m_center[3];
|
float m_center[3];
|
||||||
float m_radius;
|
float m_radius;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Primitive
|
struct Primitive
|
||||||
{
|
{
|
||||||
uint32_t m_startIndex;
|
uint32_t m_startIndex;
|
||||||
uint32_t m_numIndices;
|
uint32_t m_numIndices;
|
||||||
uint32_t m_startVertex;
|
uint32_t m_startVertex;
|
||||||
uint32_t m_numVertices;
|
uint32_t m_numVertices;
|
||||||
|
|
||||||
Sphere m_sphere;
|
Sphere m_sphere;
|
||||||
Aabb m_aabb;
|
Aabb m_aabb;
|
||||||
Obb m_obb;
|
Obb m_obb;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::vector<Primitive> PrimitiveArray;
|
typedef std::vector<Primitive> PrimitiveArray;
|
||||||
|
|
||||||
struct Group
|
struct Group
|
||||||
{
|
{
|
||||||
Group()
|
Group()
|
||||||
{
|
{
|
||||||
reset();
|
reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
void reset()
|
void reset()
|
||||||
{
|
{
|
||||||
m_vbh.idx = bgfx::invalidHandle;
|
m_vbh.idx = bgfx::invalidHandle;
|
||||||
m_ibh.idx = bgfx::invalidHandle;
|
m_ibh.idx = bgfx::invalidHandle;
|
||||||
m_prims.clear();
|
m_prims.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
bgfx::VertexBufferHandle m_vbh;
|
bgfx::VertexBufferHandle m_vbh;
|
||||||
bgfx::IndexBufferHandle m_ibh;
|
bgfx::IndexBufferHandle m_ibh;
|
||||||
Sphere m_sphere;
|
Sphere m_sphere;
|
||||||
Aabb m_aabb;
|
Aabb m_aabb;
|
||||||
Obb m_obb;
|
Obb m_obb;
|
||||||
PrimitiveArray m_prims;
|
PrimitiveArray m_prims;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Mesh
|
struct Mesh
|
||||||
{
|
{
|
||||||
void Mesh::load(const char* _filePath)
|
void load(const char* _filePath)
|
||||||
{
|
{
|
||||||
#define BGFX_CHUNK_MAGIC_VB BX_MAKEFOURCC('V', 'B', ' ', 0x0)
|
#define BGFX_CHUNK_MAGIC_VB BX_MAKEFOURCC('V', 'B', ' ', 0x0)
|
||||||
#define BGFX_CHUNK_MAGIC_IB BX_MAKEFOURCC('I', 'B', ' ', 0x0)
|
#define BGFX_CHUNK_MAGIC_IB BX_MAKEFOURCC('I', 'B', ' ', 0x0)
|
||||||
#define BGFX_CHUNK_MAGIC_PRI BX_MAKEFOURCC('P', 'R', 'I', 0x0)
|
#define BGFX_CHUNK_MAGIC_PRI BX_MAKEFOURCC('P', 'R', 'I', 0x0)
|
||||||
|
|
||||||
bx::CrtFileReader reader;
|
bx::CrtFileReader reader;
|
||||||
reader.open(_filePath);
|
reader.open(_filePath);
|
||||||
|
|
||||||
Group group;
|
Group group;
|
||||||
|
|
||||||
uint32_t chunk;
|
uint32_t chunk;
|
||||||
while (4 == bx::read(&reader, chunk) )
|
while (4 == bx::read(&reader, chunk) )
|
||||||
{
|
{
|
||||||
switch (chunk)
|
switch (chunk)
|
||||||
{
|
{
|
||||||
case BGFX_CHUNK_MAGIC_VB:
|
case BGFX_CHUNK_MAGIC_VB:
|
||||||
{
|
{
|
||||||
bx::read(&reader, group.m_sphere);
|
bx::read(&reader, group.m_sphere);
|
||||||
bx::read(&reader, group.m_aabb);
|
bx::read(&reader, group.m_aabb);
|
||||||
bx::read(&reader, group.m_obb);
|
bx::read(&reader, group.m_obb);
|
||||||
|
|
||||||
bx::read(&reader, m_decl);
|
bx::read(&reader, m_decl);
|
||||||
uint16_t stride = m_decl.getStride();
|
uint16_t stride = m_decl.getStride();
|
||||||
|
|
||||||
uint16_t numVertices;
|
uint16_t numVertices;
|
||||||
bx::read(&reader, numVertices);
|
bx::read(&reader, numVertices);
|
||||||
const bgfx::Memory* mem = bgfx::alloc(numVertices*stride);
|
const bgfx::Memory* mem = bgfx::alloc(numVertices*stride);
|
||||||
bx::read(&reader, mem->data, mem->size);
|
bx::read(&reader, mem->data, mem->size);
|
||||||
|
|
||||||
group.m_vbh = bgfx::createVertexBuffer(mem, m_decl);
|
group.m_vbh = bgfx::createVertexBuffer(mem, m_decl);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BGFX_CHUNK_MAGIC_IB:
|
case BGFX_CHUNK_MAGIC_IB:
|
||||||
{
|
{
|
||||||
uint32_t numIndices;
|
uint32_t numIndices;
|
||||||
bx::read(&reader, numIndices);
|
bx::read(&reader, numIndices);
|
||||||
const bgfx::Memory* mem = bgfx::alloc(numIndices*2);
|
const bgfx::Memory* mem = bgfx::alloc(numIndices*2);
|
||||||
bx::read(&reader, mem->data, mem->size);
|
bx::read(&reader, mem->data, mem->size);
|
||||||
group.m_ibh = bgfx::createIndexBuffer(mem);
|
group.m_ibh = bgfx::createIndexBuffer(mem);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BGFX_CHUNK_MAGIC_PRI:
|
case BGFX_CHUNK_MAGIC_PRI:
|
||||||
{
|
{
|
||||||
uint16_t len;
|
uint16_t len;
|
||||||
bx::read(&reader, len);
|
bx::read(&reader, len);
|
||||||
|
|
||||||
std::string material;
|
std::string material;
|
||||||
material.resize(len);
|
material.resize(len);
|
||||||
bx::read(&reader, const_cast<char*>(material.c_str() ), len);
|
bx::read(&reader, const_cast<char*>(material.c_str() ), len);
|
||||||
|
|
||||||
uint32_t type = m_decl.has(bgfx::Attrib::TexCoord0) ? 0 : 1;
|
uint16_t num;
|
||||||
|
bx::read(&reader, num);
|
||||||
uint16_t num;
|
|
||||||
bx::read(&reader, num);
|
for (uint32_t ii = 0; ii < num; ++ii)
|
||||||
|
{
|
||||||
for (uint32_t ii = 0; ii < num; ++ii)
|
bx::read(&reader, len);
|
||||||
{
|
|
||||||
bx::read(&reader, len);
|
std::string name;
|
||||||
|
name.resize(len);
|
||||||
std::string name;
|
bx::read(&reader, const_cast<char*>(name.c_str() ), len);
|
||||||
name.resize(len);
|
|
||||||
bx::read(&reader, const_cast<char*>(name.c_str() ), len);
|
Primitive prim;
|
||||||
|
bx::read(&reader, prim.m_startIndex);
|
||||||
Primitive prim;
|
bx::read(&reader, prim.m_numIndices);
|
||||||
bx::read(&reader, prim.m_startIndex);
|
bx::read(&reader, prim.m_startVertex);
|
||||||
bx::read(&reader, prim.m_numIndices);
|
bx::read(&reader, prim.m_numVertices);
|
||||||
bx::read(&reader, prim.m_startVertex);
|
bx::read(&reader, prim.m_sphere);
|
||||||
bx::read(&reader, prim.m_numVertices);
|
bx::read(&reader, prim.m_aabb);
|
||||||
bx::read(&reader, prim.m_sphere);
|
bx::read(&reader, prim.m_obb);
|
||||||
bx::read(&reader, prim.m_aabb);
|
|
||||||
bx::read(&reader, prim.m_obb);
|
group.m_prims.push_back(prim);
|
||||||
|
}
|
||||||
group.m_prims.push_back(prim);
|
|
||||||
}
|
m_groups.push_back(group);
|
||||||
|
group.reset();
|
||||||
m_groups.push_back(group);
|
}
|
||||||
group.reset();
|
break;
|
||||||
}
|
|
||||||
break;
|
default:
|
||||||
|
DBG("%08x at %d", chunk, reader.seek() );
|
||||||
default:
|
break;
|
||||||
DBG("%08x at %d", chunk, reader.seek() );
|
}
|
||||||
break;
|
}
|
||||||
}
|
|
||||||
}
|
reader.close();
|
||||||
|
}
|
||||||
reader.close();
|
|
||||||
}
|
void unload()
|
||||||
|
{
|
||||||
void Mesh::unload()
|
for (GroupArray::const_iterator it = m_groups.begin(), itEnd = m_groups.end(); it != itEnd; ++it)
|
||||||
{
|
{
|
||||||
for (GroupArray::const_iterator it = m_groups.begin(), itEnd = m_groups.end(); it != itEnd; ++it)
|
const Group& group = *it;
|
||||||
{
|
bgfx::destroyVertexBuffer(group.m_vbh);
|
||||||
const Group& group = *it;
|
|
||||||
bgfx::destroyVertexBuffer(group.m_vbh);
|
if (bgfx::invalidHandle != group.m_ibh.idx)
|
||||||
|
{
|
||||||
if (bgfx::invalidHandle != group.m_ibh.idx)
|
bgfx::destroyIndexBuffer(group.m_ibh);
|
||||||
{
|
}
|
||||||
bgfx::destroyIndexBuffer(group.m_ibh);
|
}
|
||||||
}
|
m_groups.clear();
|
||||||
}
|
}
|
||||||
m_groups.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
void submit(bgfx::ProgramHandle _program, float* _mtx)
|
void submit(bgfx::ProgramHandle _program, float* _mtx)
|
||||||
{
|
{
|
||||||
|
@ -272,9 +272,9 @@ struct Mesh
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bgfx::VertexDecl m_decl;
|
bgfx::VertexDecl m_decl;
|
||||||
typedef std::vector<Group> GroupArray;
|
typedef std::vector<Group> GroupArray;
|
||||||
GroupArray m_groups;
|
GroupArray m_groups;
|
||||||
};
|
};
|
||||||
|
|
||||||
int _main_(int _argc, char** _argv)
|
int _main_(int _argc, char** _argv)
|
||||||
|
|
Loading…
Reference in a new issue