View Full Version : Shaders and Texture func call overhead?

07-30-2013, 05:32 AM
I'm trying to well merge all separated parts I've developed and tested one by one separately.
I'm in trouble during Rendering() pass. Deeply I need to "re-order" some functions call to avoid overhead of useless functions.

My rendering function calls are:

[shader] glLinkProgram(...);
[shader] glUseProgram(...);
[shader] set Uniform Buffer Object with some data
for each Mesh do...

[texture] glActiveTexture(...);
[texture] glBindTexture(...);
[texture] glUniform1i(...);
[texture] glBindSampler(...);
[vbo] glBindBuffer(GL_ARRAY_BUFFER...);
[vbo] glEnableVertexAttribArray(...);
[vbo] glVertexAttribPointer(...);
[vbo] glDrawInstanced(...);


I was wondering if I could remove latest 2 [texture] calls.
I think it's useless to bind together Samplers and Textures each loop cycle.
This binding is static and it doesn't change.

Is it possibile to do something to avoid few function calls?
Thanks for your help!

07-30-2013, 07:09 AM
This binding is static and it doesn't change.

If it doesn't change, why do you call the functions?

Is it possibile to do something to avoid few function calls?

The simple rule is: if you don't need to modify GL state, just don't.

07-30-2013, 07:27 AM
The binding is static/fixed but I need to call it at least one time to create their "relationship"....but when I should call it?
Online I've found I need to bind Samples-to-Textures when I change ShaderProgram....in another website I've found the opposite...so I'm a bit confused.

Logically it became useless to bind same things at every frame/loop. VBOs needs to be binded at every frame because I need to "select" what "model" to render, but this special Sampler-Texture binding is something like to a Parameter: fixed until I want to change it.

So, where I should need to call this fixed binding?