PDA

View Full Version : Modern OpenGL (3+) and state sorting



Avithohol
09-28-2013, 07:01 AM
Dear All,


let me have a general question, and confirmation:


In my game engine, I have a state graph to minimize the state changes.
Each mesh knows what ShaderProgram, and what Texture it uses,
and based on this info all of them are inserted into a simple graph, like below:
(sorry for the ascii art)






....
/
ShaderProgram1
/ \
/ \
Texture1 Texture2
/ \ \
/ \ \
Mesh1 Mesh2 Mesh3











My questions is:
This is my simple (and maybe bad) solution for state sorting, but in general,
is the state sorting stuff is still relevant on today's GPU?

Should I still sort my meshes according to their Shader/Texture/Material whatever properties?

Or should I just simply draw the meshes, and let each mesh bind the ShaderProgram, and Texture it uses.
In that case a mesh would bind (glBindTexture) a texture which might be already bound,
or maybe it was already bound before by another similar mesh.





Thank You for sharing Your thoughts about this!
A

V-man
09-28-2013, 08:57 AM
Yes, state sorting boosts performance. You can sort by shader, then texture (for example texture0).

Avithohol
09-29-2013, 02:27 AM
Yes, state sorting boosts performance. You can sort by shader, then texture (for example texture0).

Thank You, V-man, yes I do that kind of sorting,
I just wondered if this complication still needed,
but it seems yes.

Cheers
A