Can I just add…it really depends upon the uniforms and vertex attributes you are throwing at those shaders.
I would have to agree with what’s already been said…the tetxure binding operation is a lot simpler for GL than switching shaders and therefore faster.
Perhaps, if the textures are all the same size, you could organise the 100 textures into a 2D Array texture. That way you wont be switching anything and just selecting the slice via a uniform change.
So You think the first approach is the fastest one ?
Each shader will have different complexity.
From a basic multi-texturing up to a per-pixel lighted bumpmapping.
To be more exact on my case:
within one frame, i will have about 10 different shader program change and each one of them is used to draw primitives with different-different 2D textures applied.
Regarding the uniform and vertex attributes:
Actually a lot of such values are passed to the shaders:
Per Vertex: TBN values, Heightmap coverage values, etc…
Uniform: Current time, FPS interval, etc …
So in one word: a lot of data passed to the shaders.
Good idea the texture size trick unfortunately the texture sizes are so different.
Correct, yes. A shader change is actually one of the slowest operations you can do, but to be honest arranging your data sensibly and batching stuff which has common states together properly is far more important than either.
Correct, yes. A shader change is actually one of the slowest operations you can do, but to be honest arranging your data sensibly and batching stuff which has common states together properly is far more important than either. [/QUOTE]
Thank You, its a shame :o but may I expand the question a bit more with the same pattern:
Within one frame:
Calling glBindTexture(GL_TEXTURE_2D,…) only once
then calling 100 glTranslatef(…)
– OR –
Within one frame:
Calling glTranslatef(…) only once
then calling 100 glBindTexture(GL_TEXTURE_2D,…)
I have already read the FAQ of OpenGL about “overusing” glTranslatef …
Consider using a texture atlas to handle this. See this gamedev.net post for lots of resources. You may be able to bind just one shader and one texture.
For the relative cost of various state changes, see Tom Forsyth’s Renderstate change costs:
I’d like to piggyback on this thread and ask: What is faster:
100 glUseProgramObjectARB()
or just
1 glUseProgramObjectARB() and
100 glUniform*()
I’ve read a paper encouraging shader writers to implement more than 1 materials in 1 shader. This, however, means conditionals, which are a no-no in a shader.