Skip to main content
GameDev.net gamedev.net
🔒 Locked

Render States

Started by Simplicity Oct 28, 2005 at 6:29 PM 3 replies 800+ views
Original Post
Simplicity
Simplicity
It might be a good idea to minimize render state changes, but there are a few dilemma I would like to discuss. If certain objects share the same render states, one may want to group them. But then, when you apply the state change, you don't really change all the posible states. You would most likely assume certain states are at their default values and set the ones necessary. In that case, to make sure other sets of objects are given the same "fairness", would you change the states that you want and then put it back the way it was after you render? This would require addition steps such as saving the previous state and change of states twice. Does anyone have suggestions? Thanks.
RenderTarget
RenderTarget
State management is hard. Sometimes the management scheme is complex enough that just setting redundant state isn't as harmful to perf. But, if you were to try, one idea might be to track all the states that any object can ever set, and set all those states (that matter, and which differ from the current state) when you render an object. Then sort rendering of objects by minimal state changes. That's a lot of state to track though.
[sub]My spoon is too big.[/sub]
circlesoft
circlesoft
Good question. What I do is check to see if the constant has a default value at start up. For example, this has a default value:

float4 myConstant : MYSEMANTIC { 0.0, 1.0, 0.754, 0.322 };

This doesn't:

float4 myConstant2: MYSEMANTIC2;

If the constant has a default value, it isn't added to the group of constants that a material has. Therefore, it is not updated at all upon rendering. This effectively sidesteps the "saving state" issue.
Simplicity
Simplicity
I don't understand what circlesoft is trying to say. That looks like something from the shader?
Armadon
Armadon
I totally understand what you are saying and it would be in your best interest to make sure what the default states are of the render states you are setting so that you can take advantage of not setting render states each and every single time and switching them back.

Usually I look them up to make sure and if they do apply to what I want to do then I do don't set them at all...(which is pretty obvious I guess).

So for your question group your entities together that need to be rendered using the same render states and lookup the render state and if needed reset the renderstate to what it was before.

i.e.
RenderStateManager.CullMode
Remarks
The default value is Cull.CounterClockwise.

I hope this helps.
Take care.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.