0
$\begingroup$

I wonder what happens when functions that change OpenGL states, ex glBindVertexArray or glBindTexture are called with the same parameter multiple times in a row like below?

 //like this
 glBindVertexArray(vao);
 glBindVertexArray(vao);
 glBindTexture(GL_TEXTURE_2D, tbo);
 glBindTexture(GL_TEXTURE_2D, tbo);

 //or like this
 glBindVertexArray(vao);
 glBindTexture(GL_TEXTURE_2D, tbo);
 glBindVertexArray(vao);
 glBindTexture(GL_TEXTURE_2D, tbo);
 

We know that state changes are costly. But if the new state is the same as the old one is performance overhead the same as if the two states where different? Or does OpenGL perform conditional check and ignore the second state change command?

$\endgroup$
0
$\begingroup$

There are no performance guarantees in OpenGL. Many implementations will filter out some kinds of redundant state, but nothing guarantees that.

The best you can do is this: if you change state, you should do so with the expectation that you will pay the cost of that state change.

It should also be noted that the cost of a state change is paid at the next render call, not when the change is made. So if you bind 20 different VAOs, but only render with the last one, it's probably going to be just as expensive as binding the last one.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.