eggboy
eggboy

Reputation: 33

Opengl reduce usage of uniforms

I have near 10000 vertex buffers (different sizes) and corresponding integer data for each buffer. So when i render i do something like this:

Bind shader
For each vertex buffer:
    Set uniform
    Bind vertex buffer
    Draw call

This many uniform changes really slow down the program.

So i was thinking of using a uniform buffer object or a ssbo and send an array of integers to the shader, then somehow index into the array with each draw call. Is there a way to somehow know which draw call is being processed in the shader?

Upvotes: 2

Views: 1267

Answers (1)

Rabbid76
Rabbid76

Reputation: 210890

In general, OpenGL does not count the draw calls. You would have to manage a uniform counter yourself or you can generate an SSBO for each mesh and bind the SSBO belonging to the mesh before the draw call.

A possibility I can see is using Multi-Draw (see glMultiDrawArrays ). But then you have to store the data for all the meshes in the same buffer objects and the vertex attribute specification has to be the same for all meshes, stored in one Vertex Array Object.
The index of the drawing command is stored in the built-in vertex shader input variable gl_DrawID (Requires GLSL 4.60 or ARB_shader_draw_parameters).


Another way to improve performance is to sort the meshs so that fewer changes to the uniforms are required. If there are mehes that have the same uniform settings, then render them in succession, without setting the uniforms in between.


The best performance improvement can be achieved by not rendering. Do not render all meshes, render only the geometry that is "visible" in the viewport.
You can implement some simple culling test like View Frustum Culling. Skip a mesh if the bounding box or the bounding sphere of the mesh is not in place and does not intersect the Viewing frustum.

Upvotes: 1

Related Questions