Slastraf Posted April 9, 2021 Share Posted April 9, 2021 void generateTest(){ //const siv::PerlinNoise perlin(seed); Surface* surface = NULL; Model* model = NULL; for(int i = 0; i<1000; i++) { model = Model::Create(); model->SetColor(1.0, 0.0, 1.0); surface = model->AddSurface(); surface->AddVertex(0.5, 0, 0.5, 0, 0, 1); surface->AddVertex(0.5, 0, -0.5, 0, 0, 1); surface->AddVertex(-0.5, 0, 0.5, 0, 0, 1); surface->AddVertex(-0.5, 0, -0.5, 0, 0, 1); surface->AddTriangle(0, 1, 2); surface->AddTriangle(1, 2, 3); surface->Update(); model->UpdateAABB(Entity::LocalAABB | Entity::GlobalAABB); } } Hello after I wanted to make a mesh generation algorithm I found out that I get a lot of lag when trying to have a small amount of vertex (<10k) in the scene If you run the test example above, it will make the game run at 2 fps or less. It does not max out my ram / gpu at all. I guess it has to do with memory leaks because I did not delete surface and model pointer. Then I tried to do the latter but it made different errors. 2021-04-09 18-23-58.mp4 Quote Link to comment Share on other sites More sharing options...
Josh Posted April 9, 2021 Share Posted April 9, 2021 Your code above is creating 1000 unique model entities. I would expect that to result in pretty slow rendering. The number of entities, and especially the number of unique meshes, if often more important than the vertex count. If you created one and then made 999 instances of it, it would run much faster. 1 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Solution Slastraf Posted April 9, 2021 Author Solution Share Posted April 9, 2021 2 minutes ago, Josh said: Your code above is creating 1000 new model entities. I would expect that to be a fairly slow process. That pointed me in the right direction. I made everything into one model, it still lagged, then I also made only one surface and then I got acceptable performance. Still it should not lag in the first place. The code looks like this and now I can proceed. void generateTest(){ // std::random_device rd; // std::uint32_t seed = rd(); //const siv::PerlinNoise perlin(seed); Surface* surface = NULL; Model* model = NULL; model = Model::Create(); model->SetColor(1.0, 0.0, 1.0); surface = model->AddSurface(); for(int i = 0; i<1000; i++) { surface->AddVertex(0.5, 0, 0.5, 0, 0, 1); surface->AddVertex(0.5, 0, -0.5, 0, 0, 1); surface->AddVertex(-0.5, 0, 0.5, 0, 0, 1); surface->AddVertex(-0.5, 0, -0.5, 0, 0, 1); surface->AddTriangle(0, 1, 2); surface->AddTriangle(1, 2, 3); surface->Update(); model->UpdateAABB(Entity::LocalAABB | Entity::GlobalAABB); } } Quote Link to comment Share on other sites More sharing options...
SpiderPig Posted April 9, 2021 Share Posted April 9, 2021 4 hours ago, Slastraf said: surface->Update(); model->UpdateAABB(Entity::LocalAABB | Entity::GlobalAABB); This should probably outside your loop as well. It won't effect render performance but it will generate the mesh faster as updateAABB() I think loops through all vertices in the model and finds the extents of the mesh for the AABB. 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.