Direct3D state stack

Started by
8 comments, last by DEVOXE 18 years, 8 months ago
Hi; I am trying to adopt from OpenGL to DirectX api and wondering if there is a stack mechanism in directx as well to push and pop back the states. To put it an other way, are there any glPush(), glPop() similiar functions? For instance, to render an object with blending support, should we set the proper states and take them back not to effect the next rendering object? Or any other ways to handle these kind of state changes? Thanks a lot for any ideas.
Advertisement
You can save/capture and restore state blocks, but that's it.
There is no stack in D3D for render states.
You could always implement a state stack yourself, which is what I did for a good while.
Quote:Original post by sordid
You could always implement a state stack yourself, which is what I did for a good while.

Thanks for the information. BTW, do you think it is essential to code such a stack or just a design issue, trying to emulate the accustomed API? If you think it eases the life quite a bit, can you suggest some design tips to start with?

Actually there IS a matrix stack in DirectX. Look up ID3DXMatrixStack in the docs.
I think he means a stack for state changes.

Never having used OpenGL, I've never even heard of a state stack before, but I can't really think of why I'd need one. You just set the render states that you need and draw; I'm not sure what advantages a stack would give me, as it's not like states are applied in a hierarchy.
_______________________________________________________________________Hoo-rah.
There is no state stack in OGL, only a Transform ( Matrix Stack ) and the ID3DXMatrixStack is similar to the one in OGL...
Then what on earth is the OP asking for?
_______________________________________________________________________Hoo-rah.
For D3D state changes, I recommend that you use some sort of tree, instead of the traditional stack. Kind of like this:
                     Shader1                            Shader2               |--------|--------|                 |--------|--------|           TextureSet1      TextureSet2       TextureSet3        TextureSet4       |--------|--------|      ...               ...               ...   ConstantSet1      ConstantSet2       |                 |     Entity1          Entity5     Entity2          Entity6     Entity3     Entity4

This tree will let you efficiently managed and change all states - shaders, textures, constants, stream sources, and render states.
Dustin Franklin ( circlesoft :: KBase :: Mystic GD :: ApolloNL )
Quote:Original post by JoCCo
There is no state stack in OGL, only a Transform ( Matrix Stack )


There is a kind of mechanism to push and pop the current attributes with

glPushAttrib(BITFLAG) and glPopAttrib(). With this functionality you dont have to recode the states especially if that state needs a more than one function call.

Quote:Original post by circlesoft
For D3D state changes, I recommend that you use some sort of tree, instead of the traditional stack.


Thank you very much for the idea. I will give a try for the implementation.

This topic is closed to new replies.

Advertisement