forked from oerkki/voxelands
fix mesh index overflows
This commit is contained in:
parent
5a6fa7a4c2
commit
7bf5f4f4a0
Binary file not shown.
Before Width: | Height: | Size: 913 B After Width: | Height: | Size: 905 B |
|
@ -48,26 +48,26 @@ class MeshCollector
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void append(
|
void append(
|
||||||
video::SMaterial material,
|
video::SMaterial material,
|
||||||
const video::S3DVertex* const vertices,
|
const video::S3DVertex* const vertices,
|
||||||
u32 numVertices,
|
u32 numVertices,
|
||||||
const u16* const indices,
|
const u16* const indices,
|
||||||
u32 numIndices
|
u32 numIndices
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
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());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue