Uniform arrays?

Started by
4 comments, last by Kaptein 10 years, 2 months ago

I have been thinking about how I need to send uniform values for every draw call.

I have several VBOs (they are pretty large) which contain subsets of meshes. As you can imagine each mesh is most likely rendered at a unique location for each and every draw call.

Is it possible with modern OpenGL (4.x) to (assuming same shader) provide an array of uniform values which are unique to the current frame rendered, so as to reduce the number of GL calls needed during rendering?

Advertisement

It sounds like you're looking for Uniform Buffer Objects.

Maybe, but it doesn't seem like it will provide a unique uniform value for each successive render call (if that makes sense, I guess it doesn't).

So maybe I'm just stuck with vertex attributes for unique positions per call.

Sounds like you're maybe talking about Instancing?

glDrawElementsInstanced() will draw the same model several times. In order to position things differently you need to do one of a two things.

A) Pass each transform and model specific data in via a Uniform Buffer Object

B) Pass each transform and model specific data in via a VBO with a vertex attribute divisor

You can draw many models (All the same) with a single draw call at different transformations and such.


So maybe I'm just stuck with vertex attributes for unique positions per call.

But vertex attributes are meant to change per vertex. Using an attribute as constant is possible but seems me wasteful and an update time consuming, especially because you mentioned that the VBOs are big.

It seems me from the OP that there are several sub-meshes (presumably not instances of the same mesh), and for each one a draw call is made. Similar to setting the different VBO for each call, also the different set of uniforms has to be set. In such case using UBOs would be the correct way. It would not reduce the amount of draw calls, because the amount of sub-meshes does not change. But it would reduce the amount of calls for setting uniforms, because a single call would be sufficient to set all uniforms at once for a particular draw call.


So maybe I'm just stuck with vertex attributes for unique positions per call.

But vertex attributes are meant to change per vertex. Using an attribute as constant is possible but seems me wasteful and an update time consuming, especially because you mentioned that the VBOs are big.

It seems me from the OP that there are several sub-meshes (presumably not instances of the same mesh), and for each one a draw call is made. Similar to setting the different VBO for each call, also the different set of uniforms has to be set. In such case using UBOs would be the correct way. It would not reduce the amount of draw calls, because the amount of sub-meshes does not change. But it would reduce the amount of calls for setting uniforms, because a single call would be sufficient to set all uniforms at once for a particular draw call.

Indeed, that is actually what i'm going to do. It doesn't solve my actual problem in reducing the amount of transformed matrix transfers to the shader for each object, but I'm going to look into what Togg* mentioned.

This topic is closed to new replies.

Advertisement