PDA

View Full Version : State hierarchy



EmJayJay
02-28-2015, 06:36 AM
Not sure if state hierarchy is the right description but I'll go with that.

After preparing everything related to OpenGL and resources used by it you then apply state changes and draw commands but I was thinking what is the most efficient way to do it.

Would this be good hierarchy?

-Enable/Disable calls
-Editing Enabled values
--Program swap
---Uniform updates
---Buffer updates
---VAO swaps
----Draw

Or is it a good idea to Enable/Disable between program swaps. Where would glPolygonMode fit in this design?

Alfonse Reinheart
02-28-2015, 08:43 AM
Generally speaking, you don't mechanically put enables or disables in one location relative to other state changes. You change the things that need to be changed to draw the next object (preferably after sorting objects so that they require a minimum of state changes between them).

glPolygonMode is generally not something you change very much. Assuming the defaults are not reasonable for you, you would set it once for a particular sequence of rendering.

mhagain
02-28-2015, 12:29 PM
After preparing everything related to OpenGL and resources used by it you then apply state changes and draw commands but I was thinking what is the most efficient way to do it.
The order you change state in generally doesn't matter (I say "generally" because non-DSA OpenGL will have interactions between bind-to-modify and bind-to-use) - instead what most drivers/hardware will do is what's called lazy state changes; i.e the driver will just record that a state change was requested, but not actually apply it until such a time as it is needed (typically a draw call). If there is an order which is more optimal for some drivers, it can be safely assumed that those drivers will apply the changes in their own driver-optimal order (which may be different to that for other drivers).

If it pleases you to always change state in a certain order in your own code, then by all means do so. But you don't have to.

EmJayJay
02-28-2015, 05:52 PM
glPolygonMode is generally not something you change very much. Assuming the defaults are not reasonable for you, you would set it once for a particular sequence of rendering.
This is what I meant. Having a default render state set and changing it when the state changes from the default to new one. Basically creating different stage profiles and trying to use them efficiently and in all cases which use the currently bound profile before applying new profile which either enables new state or mode like the glPolygonMode. After the rendering has been completed the programs switches back to the default profile values. Using the same approach as you would use with shader program swapping and VAO bindings, eliminate frequent swapping.