Jump to content
  • Advertisement
Sign in to follow this  
jusa

Consecutive calls to glUseProgram

This topic is 1146 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 a noob question about how glUseProgram works.
 
Suppose I did something like this:
// A and B are shader programs.

void render() {
   glUseProgram(A);
   glUseProgram(B);

   glDrawArrays(...);
}

Is program A ever used for drawing here, or is it pointless to do this?

 

Share this post


Link to post
Share on other sites
Advertisement

The second one replaces the first one, so no point unless there's another glDrawArrays (or something else that uses the shader) in between the glUsePrograms.

Share this post


Link to post
Share on other sites
Only one program can be installed at a time, so glUseProgram(B) will override the call to glUseProgram(A) and glDrawArrays will only use program B for rendering.

What effect are you trying to achieve?

Edit: ninja'd Edited by Simmie

Share this post


Link to post
Share on other sites

Ok, thanks for the answers!

 

I just wanted a confirmation that previous calls are replaced if there's no drawing in between. I wasn't sure when I read the description in the OpenGL docs.

Share this post


Link to post
Share on other sites
It isn’t pointless in terms of performance.
Binding shaders is one of the slowest things you can do. Never bind a shader unless you intend to draw with it. ::glUseProgram( A ) here won’t cause any draw calls, but it will heavily impact your FPS.


L. Spiro

Share this post


Link to post
Share on other sites

I just wanted a confirmation that previous calls are replaced if there's no drawing in between.

 

Previous calls are replaced, regardless of whether there's anything in-between.

glUseProgram(A);    //Sets the program to be used by later function calls.
glDrawArrays(...);  //Uses the program that was *most recently* set (in this case, program 'A')
glUseProgram(B);    //Sets the program to be used by later function calls.
glDrawArrays(...);  //Uses the program that was *most recently* set (in this case, program 'B')

And because it's having the videocard driver do the actual setting, which might be sending it to the videocard (or waiting until later to send it), it can be a slow function call, so if you aren't actually going to use it (either by drawing with it, or setting uniforms, or whatever else you intend to use if for), don't set it.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!