Archived

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

HexDump

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

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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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.

Share this post


Link to post
Share on other sites