<p>There are no performance guarantees in OpenGL. Many implementations will filter out some kinds of redundant state, but nothing guarantees that.</p>
<p>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.</p>
<p>It should also be noted that the cost of a state change is paid at the next <em>render</em> 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.</p>

CC BY-SA 4.0
2021-10-05T14:05:34.347Z
2021-10-05T14:05:34.347Z
Nicol Bolas
<p>I wonder what happens when functions that change OpenGL states, ex <code>glBindVertexArray</code> or <code>glBindTexture</code> are called with the same parameter multiple times in a row like below?</p>
<pre><code> //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);
 
</code></pre>
<p>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?</p>

<opengl>
How OpenGL handles assigning the same state multiple times in a row
Lenny White
# How OpenGL handles assigning the same state multiple times in a row

(Asked by: username_0 on 2021-10-05)

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?

**Tags:** opengl


---

## 1 answers

### Answer by username_1 on 2021-10-05. Score: 0 | Accepted answer

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.


---

