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