More than 1000 geometries

From JReality Wiki
Jump to: navigation, search

- see also Many small objects optimisation


OpenGL 3 has some shortcomings when it comes to drawing a large number of small objects with all different shader, different textures and different uniform variables. The problem is, that when changing any of the before mentioned, you need to issue a glDrawArrays command, which is very expensive (I think this is because for the glBind... calls, the pointers to GPU memory have to be fetched from main memory). There are the openGL bindless extensions, but we did not want to expect from users GPUs to support these. Therefore drawing many small objects can be a problem in the jogl3 backend.


However there is some optimization in certain cases: When the many objects all have the same texture, same reflection map and the same shader, no transparency and neither point nor edge drawing, then the performance is optimized, but still behind the jogl2 backend for the same case. You can turn off the performance optimization in the jogl3 backend with:

 
JRViewer jrv;
 
Scene scene = jrv.getPlugin(Scene.class);
 
scene.getRootAppearance().setAttribute(CommonAttributes.SMALL_OBJ_OPTIMIZATION, false);

An example application with 10000 cubes runs with:

- 16 FPS in the jogl2 backend

- 12 FPS in the jogl3 backend (without optimization 3.9 FPS)


A solution might be to flatten the geometries, i.e. make one IndexedFaceSet out of the 1000. This is a good idea, if you know, that they wont move relative to each other and you will not need to remove single geometries from the collection. With flattened 10000 cubes you get the following performance:

- 20 FPS with a stutter every 10 frames in the jogl2 backend

- 60 FPS in the jogl3 backend


The same with 30000 cubes:

- 6 FPS with jogl2

- 25 FPS with jogl3