Archived

This topic is now archived and is closed to further replies.

How to manage Render States in games (optimizing and more....)

This topic is 5930 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hello, I´m writing this days a little renderer to use in my engine and I would like to know how ppl manage Render States (for a list of objects with different ones), and how they handle them for every object, what I mean is: 1- Object1 needs to be rendered with alpha blending, no lights, and wireframe. 2 - Object2 needs to be rendered with alpha, lights and solid. How do you guys first create a list of Render States for each object (I think you do not hardcode them for each object (slow, etc...), and how do you then group Objects in order to minimize render state changes, etc... I export models from max, is there any way to get from max the render states every object needs to be rendered well? Thnx in advance. HexDump.

Share on other sites
This is my idea that I have not tried yet.

Since you usually only have a few render states, or should, then setup a delta pattern between each one. Pre-calcualte what states you have to change for each active state and when you get a state change request from an object you can just look up which state fields need to be changed and change just them. I can''t realy see having more than ten states for most renderes, so you just have to store ten state changes.

Share on other sites
A more general form of a delta pattern would be a histogram, probably not as fast as a delta pattern since you still have to evaluate it, but can be used for a few other things as well...

------------
- outRider -

Share on other sites
delta pattern? histogram patter? ... pls I do not understand :/, coudl you post an example pls?.

Share on other sites
Group them together like this.

Render2D()
{
Disable ZBuffer

Draw objects...
Draw more
Draw
Draw

Enable ZBuffer

}

The Render2D function would disable the ZBuffer to draw 2D objects.. then enable it again when it returns.

Share on other sites
Check out ID3DXEffect class. This is very useful. You put your render states in data files instead of hard coding it. For hand setting them, a simple optimization is to filter SetRenderState calls. Wrap SetRenderState() and cache them. Only call Direct3d''s SetRenderState() if the it really changes.

Jack

Share on other sites
YES YES, do this, just like in the water example!

Share on other sites
I do crap like

#define RALPHA 1#define RGRAYSCALE 2#define RUPSIDEDOWN 3#define RZBUFFER 4...void RenderMode(flags){  switch(flags){  case RALPHA: glEnable(GL_ALPHA_TEST); break;... etc

I find it pretty easy to flag a bunch of values and just switch() them later in a function.

~ Jesse

The gl2D Project

Share on other sites
quote:
Original post by HexDump
...and how do you then group Objects in order to minimize render state changes, etc...

One technique I''ve heard of is a ''shader tree,'' basically a tree whose nodes are renderer state changes with more expensive changes near the root and less expensive ones near the leaves. Here''s a quick link.

Josh

1. 1
Rutin
46
2. 2
3. 3
4. 4
5. 5
JoeJ
19

• 13
• 10
• 12
• 10
• 13
• Forum Statistics

• Total Topics
632998
• Total Posts
3009808
• Who's Online (See full list)

There are no registered users currently online

×