Slow when drawing a lot of models on screen


I’m trying to draw a 32 x 32 map with textured “cube” models (they are a bit more detailed than a normal cube).
But when doing that i get very slow fps (around 15 fps)…
I build up a vector in the setup method, gameObject being a class i made to hold information on an object like position, rotation, scale, id, modelType etc… I preloaded some models in the setup method and then in the draw method i loop through the vector and depending on the modelType i position the corresponding model and draw it.

I made a preview mode where i only draw ofBoxPrimitive and i get full 60 fps. I made the preview by adding a ofBoxPrimitive in the gameObject with all the correct position/rotation/scale and i just draw them in a for loop. But trying that with the models the program freeze since i’m doing a lot of loadModel call…

i’m using AssimpModelLoader for the models.

So i’m wondering if there is a better way to do that and get better performance ?

Hi @dayus !

Could you share an image of what the cube model looks like?

Are all the models the same, or is each one unique?

If they are the same mesh and texture ( or even same mesh / different texture )then there could be a bunch of ways to speed things up. ( Grabbing the mesh once and/or doing instanced vbo rendering ).

One other thing you could look at is the loader parameters.

You could try ofxAssimpModelLoader::OPTIMIZE_HIGH as the second parameter in the load function. ( You will need a nightly build of OF - found at the bottom of the download page for that ).

bool ofxAssimpModelLoader::load(std::string modelName, int assimpOptimizeFlags=OPTIMIZE_DEFAULT);

Thanks you for your quick response!

here is the cube in wireframe

i have a bout 4 differents cube (pretty similar) and they all share the same texture.

I would like to try the nightly build if there’s an easy way to upgrade my actual project?

In the meantime, i’ll take a look at vbo rendering you are referencing.

are you using debug or release? it changes performance a lot for assimp model loader
edit: release is fast

@dimitre you are right release mode does run way faster, i get a 50-60 fps

but still, it might be a good idea to upgrade to the nightly build

Nice that it is running faster! Debug on Windows is quite slow!
( note: we should make Release the default build )

Just fyi:
Instanced rendering is great when you are trying to draw one mesh many times.
In your case having 4 different types makes it maybe not worth the implementation time.

Also if you model is simply textured and you don’t want shininess etc you could try:

Ok and is upgrading to the nightly build is an easy task? do i just overwrite the openframeworks folder with the new one?

you can have both OFs dont need to replace the folder with the new one just put another name on the new one and copy your project to that one

1 Like