How do you think it would be best to handle DepthStencilState / BlendState / RasterizerState ?
Associating each object in scene to its own states, like this:
class Object
{
// shaders and stuff
RasterizerState rs;
BlendState bs;
DepthStencilState pss;
};
void Render()
{
for( Object obj : ObjectList )
{
SetRasterizerState( obj.rs );
SetBlendState( obj. bs );
SetDepthStencilState( obh.pss );
Draw();
}
}
.
Or having a flag in each object indicating how is it going to be drawn, and setup states inside the rendering function:
class Object
{
// shaders and stuff
int flags; // uses transparency / casts shadows / etc
};
void Render()
{
// Draw Normal Objects
RasterizerState rs; // setup acordingly
SetRasterizerState( rs );
BlendState bs; // setup acordingly
SetBlendState( bs );
DepthStencilState pss; // setup acordingly
SetDepthStencilState( pss );
for( Object obj : NormalObjectList )
{
Draw();
}
// Draw Objects with transparency
RasterizerState rs; // setup acordingly
SetRasterizerState( rs );
BlendState bs; // setup acordingly
SetBlendState( bs );
DepthStencilState pss; // setup acordingly
SetDepthStencilState( pss );
for( Object obj : TransparentObjectList )
{
Draw();
}
// ETC....
}
.
So far I was using the first one, and it was working ok, but then I started to implement Mirrors wich require first to render the mirror to the Stencil buffer, then render the scene on the stenciled area, and then render the mirror's glass with some sort of transpareny over the reflected scene... which would be hard to do having each object associated with it's own DepthStencil / Blend / Rasterizer states...
However, sometimes you would like to render a specific object in wireframe mode, and sounds more natural to just modify that object's RasterizerState...
So.... how do you experienced people handle your states in your code?