Skip to content
Snippets Groups Projects
Commit 3ad212c9 authored by Perttu Ahola's avatar Perttu Ahola
Browse files

meshbuffer cache test. No much speed improvement.

parent c18af6e7
No related branches found
No related tags found
No related merge requests found
...@@ -297,6 +297,8 @@ void MapBlock::updateMesh() ...@@ -297,6 +297,8 @@ void MapBlock::updateMesh()
core::list<FastFace*> *fastfaces_new = new core::list<FastFace*>; core::list<FastFace*> *fastfaces_new = new core::list<FastFace*>;
//TimeTaker timer1("updateMesh1", g_device);
/* /*
We are including the faces of the trailing edges of the block. We are including the faces of the trailing edges of the block.
This means that when something changes, the caller must This means that when something changes, the caller must
...@@ -340,12 +342,26 @@ void MapBlock::updateMesh() ...@@ -340,12 +342,26 @@ void MapBlock::updateMesh()
} }
} }
//timer1.stop();
//TimeTaker timer2("updateMesh2", g_device);
scene::SMesh *mesh_new = NULL; scene::SMesh *mesh_new = NULL;
//s32 appendtime = 0;
if(fastfaces_new->getSize() > 0) if(fastfaces_new->getSize() > 0)
{ {
mesh_new = new scene::SMesh(); mesh_new = new scene::SMesh();
scene::IMeshBuffer *buf = NULL; scene::IMeshBuffer *buf = NULL;
/*
Buffer for lesser calls to
mesh_new->getMeshBuffer(g_materials[f->material]),
which is slow.
key = material id, value = meshbuffer of that material
*/
core::map<u8, scene::IMeshBuffer*> bufs;
core::list<FastFace*>::Iterator i = fastfaces_new->begin(); core::list<FastFace*>::Iterator i = fastfaces_new->begin();
...@@ -359,27 +375,43 @@ void MapBlock::updateMesh() ...@@ -359,27 +375,43 @@ void MapBlock::updateMesh()
if(f->material != material_in_use || buf == NULL) if(f->material != material_in_use || buf == NULL)
{ {
// Try to get a meshbuffer associated with the material // Try to get a meshbuffer associated with the material
buf = mesh_new->getMeshBuffer(g_materials[f->material]); core::map<u8, scene::IMeshBuffer*>::Node*
// If not found, create one n = bufs.find(f->material);
if(buf == NULL)
if(n != NULL)
{ {
// This is a "Standard MeshBuffer", buf = n->getValue();
// it's a typedeffed CMeshBuffer<video::S3DVertex> }
buf = new scene::SMeshBuffer(); else
// Set material {
((scene::SMeshBuffer*)buf)->Material = g_materials[f->material]; buf = mesh_new->getMeshBuffer(g_materials[f->material]);
// Use VBO // If not found, create one
//buf->setHardwareMappingHint(scene::EHM_STATIC); if(buf == NULL)
// Add to mesh {
mesh_new->addMeshBuffer(buf); // This is a "Standard MeshBuffer",
// Mesh grabbed it // it's a typedeffed CMeshBuffer<video::S3DVertex>
buf->drop(); buf = new scene::SMeshBuffer();
bufs[f->material] = buf;
// Set material
((scene::SMeshBuffer*)buf)->Material = g_materials[f->material];
// Use VBO
//buf->setHardwareMappingHint(scene::EHM_STATIC);
// Add to mesh
mesh_new->addMeshBuffer(buf);
// Mesh grabbed it
buf->drop();
}
} }
material_in_use = f->material; material_in_use = f->material;
} }
u16 indices[] = {0,1,2,2,3,0}; u16 indices[] = {0,1,2,2,3,0};
//TimeTaker timer("", g_device);
buf->append(f->vertices, 4, indices, 6); buf->append(f->vertices, 4, indices, 6);
//appendtime += timer.stop(true);
} }
// Use VBO for mesh (this just would set this for ever buffer) // Use VBO for mesh (this just would set this for ever buffer)
...@@ -390,6 +422,8 @@ void MapBlock::updateMesh() ...@@ -390,6 +422,8 @@ void MapBlock::updateMesh()
<<" materials"<<std::endl;*/ <<" materials"<<std::endl;*/
} }
//dstream<<"appendtime="<<appendtime<<std::endl;
// TODO: Get rid of the FastFace stage // TODO: Get rid of the FastFace stage
core::list<FastFace*>::Iterator i; core::list<FastFace*>::Iterator i;
i = fastfaces_new->begin(); i = fastfaces_new->begin();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment