0
votes

As the title says, do the drivers optimize in some way idempotent operations on the opengl state machine?

For example, what if i rebind the same buffer to the same target two times?

glBindBuffer(GL_ARRAY_BUFFER, buf_id)
...
...
//No previous binding operation on the target, this should be idempotent 
//and ideally with no cost.
glBindBuffer(GL_ARRAY_BUFFER, buf_id)  

The same questions goes with Vertex Array Objects (glBindVertexArray), shaders (glUseProgram) framebuffers etc..

2
This will depend on the specific API implementation. And even for a specific one it will be hard to know unless it is open source. - BDL

2 Answers

0
votes

Profile your app. That's always the best way to test your assumptions. Use RenderDoc or any other GPU profiling tool. Those usually show redundant API calls,which hit performance. But it is also a good practice to have a mechanism of caching the state. Here is, how John Carmack did it in Quake Arena.

0
votes

They can but the spec doesn't guarantee it. If you want it done you have to do it yourself.