Jump to content
  • Advertisement
Sign in to follow this  
Kaptein

OpenGL Uniform arrays?

This topic is 2091 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

 

Share this post


Link to post
Share on other sites
Advertisement

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites


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.

Share this post


Link to post
Share on other sites

 


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.

Edited by Kaptein

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!