fix mesh index overflows

This commit is contained in:
darkrose 2015-01-16 20:06:50 +10:00
parent 5a6fa7a4c2
commit 7bf5f4f4a0
2 changed files with 14 additions and 31 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 913 B

After

Width:  |  Height:  |  Size: 905 B

View File

@ -56,18 +56,18 @@ public:
) )
{ {
PreMeshBuffer *p = NULL; PreMeshBuffer *p = NULL;
for(u32 i=0; i<m_prebuffers.size(); i++) for (u32 i=0; i<m_prebuffers.size(); i++) {
{
PreMeshBuffer &pp = m_prebuffers[i]; PreMeshBuffer &pp = m_prebuffers[i];
if(pp.material != material) if (pp.material != material)
continue;
if (pp.vertices.size() + numVertices > 65535)
continue; continue;
p = &pp; p = &pp;
break; break;
} }
if(p == NULL) if (p == NULL) {
{
PreMeshBuffer pp; PreMeshBuffer pp;
pp.material = material; pp.material = material;
m_prebuffers.push_back(pp); m_prebuffers.push_back(pp);
@ -75,18 +75,11 @@ public:
} }
u32 vertex_count = p->vertices.size(); u32 vertex_count = p->vertices.size();
for(u32 i=0; i<numIndices; i++) for(u32 i=0; i<numIndices; i++) {
{
u32 j = indices[i] + vertex_count; u32 j = indices[i] + vertex_count;
if(j > 65535)
{
dstream<<"FIXME: Meshbuffer ran out of indices"<<std::endl;
// NOTE: Fix is to just add an another MeshBuffer
}
p->indices.push_back(j); p->indices.push_back(j);
} }
for(u32 i=0; i<numVertices; i++) for(u32 i=0; i<numVertices; i++) {
{
p->vertices.push_back(vertices[i]); p->vertices.push_back(vertices[i]);
} }
} }
@ -98,28 +91,18 @@ public:
for(u32 i=0; i<m_prebuffers.size(); i++) for(u32 i=0; i<m_prebuffers.size(); i++)
{ {
PreMeshBuffer &p = m_prebuffers[i]; PreMeshBuffer &p = m_prebuffers[i];
/*dstream<<"p.vertices.size()="<<p.vertices.size()
<<", p.indices.size()="<<p.indices.size()
<<std::endl;*/
// Create meshbuffer // Create meshbuffer
// This is a "Standard MeshBuffer", // This is a "Standard MeshBuffer",
// it's a typedeffed CMeshBuffer<video::S3DVertex> // it's a typedeffed CMeshBuffer<video::S3DVertex>
scene::SMeshBuffer *buf = new scene::SMeshBuffer(); scene::SMeshBuffer *buf = new scene::SMeshBuffer();
// Set material // Set material
buf->Material = p.material; buf->Material = p.material;
//((scene::SMeshBuffer*)buf)->Material = p.material;
// Use VBO
//buf->setHardwareMappingHint(scene::EHM_STATIC);
// Add to mesh // Add to mesh
mesh->addMeshBuffer(buf); mesh->addMeshBuffer(buf);
// Mesh grabbed it // Mesh grabbed it
buf->drop(); buf->drop();
buf->append(p.vertices.pointer(), p.vertices.size(), buf->append(p.vertices.pointer(), p.vertices.size(), p.indices.pointer(), p.indices.size());
p.indices.pointer(), p.indices.size());
} }
} }