Skip to main content
gamedev.net
🔒 Locked

Managing Renderstates

Started by NogginBoink Dec 30, 2003 at 12:22 AM 2 replies 300+ views
Original Post
NogginBoink
NogginBoink
Okay, I''m new to this whole Direct3D thing, but I have a question that I think is important before doing any architecting. Conceptually, just about any game written for D3D is going to be object oriented, and I assume that each object is going to draw itself. My question is: how do you manage render states? Do all of your onscreen objects use the exact same render states? If not, how does each class object know which render states to change when before drawing itself? It seems that it would be a waste for each class object to set each of the bajillion render states before drawing itself. But that''s going to be the only way, ultimately, that the class object is going to "know" that the device is in the correct render state. Currently, the only idea I have is this: when I create an instance of my class object, I would pass it a complete "default" render state. My game code would guarantee that the device will always be in this state when I call the class'' Render() method. The class, then, would only call SetRenderState() for the attributes that are different between the default render state and the render state it needs. (It would then, of course, set the render state back to the default before exiting Render()). I''m just curious to know how others handle this.
circlesoft
circlesoft
The LPDIRECT3DSTATEBLOCK9 is very useful for blocking renderstate''s together. I use that whenever I need to change renderstates a lot, but generally, that''s just going between 3d and text rendering.
NogginBoink
NogginBoink
quote:
Original post by circlesoft
The LPDIRECT3DSTATEBLOCK9 is very useful for blocking renderstate''s together. I use that whenever I need to change renderstates a lot, but generally, that''s just going between 3d and text rendering.


Yes!

That was the missing link!

Thank you!
Fidelio66
Fidelio66
Stateblocks are very useful. Especially if you draw a lot of separate objects and do a list of setrenderstates. I assume a setrenderstate probably doesn''t do much more than setting some bits in a register on the card through the driver. If every call has to get the state, do an & or | on the flags and set it back, then just setting the while 32-bit value in one call is more efficient, especially since setrenderstate calls will stall the pipeline.

Topic Locked

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

Sign in to reply to this topic.