Scenegraph state changes, my strange way of dealing with them

Started by
2 comments, last by Niwak 17 years, 10 months ago
Most people believe I'm weird. Moreso the teacher when I handed in my assignment and told him that I'm managing matrix state changes without saving the state of the matrix in question (IE: no push/pop). Instead I use loadMatrix/multMatrix for all animation and it works perfectly, even under complex scenes. My question is whether it's common to forego the push/pop matrix stacks in favour of loading/multiplying? Some of the techniques I use within my scenegraph are unorthodox. This isn't the first nor last I created my own method which is considered strange by everyone except myself but it is a method in which I'm confused as to whether it's done commonly or is it just me behaving badly. Thanks.
Advertisement
the methods loadMatrix and multMatrix are in my point of view not so performant like just push/pop the matrix but if you havnt problems with the speed at all, there should be no problem using this instead...
If I understand this correctly, you do:

loadMatrix(car)
draw car body
multMatrix(wheel1)
draw wheel
loadMatrix(car)
multMatrix(wheel2)
draw wheel
...etc

instead of the typical:

loadMatrix(car)
draw car body
pushMatrix
multMatrix(wheel1)
draw wheel
popMatrix
pushMatrix
multMatrix(wheel2)
draw wheel
popMatrix
...etc

If we cancel out the common parts, the net effect is you are substituting the push/pop combo for a loadMatrix. Push/pop have no data parameters to pass to the video card, so they are faster. If you have a race game with five cars with 4 wheels each, you would be sending 15 unnecessary matrices for every frame. That is why your method is not done commonly.
The way you handle the matrices depends on the way you traverse the scenegraph.
If you just traverse it from top to bottom, push/pop can save you a bit of processing (very little), if you sort your render commands by shader / texture / back to front for blended one, etc.. push/pop are not that usefull.

Anyway, if you manage cleanly your matrice stack on the CPU, I don't think that you will get any performance boost with push/pop.

This topic is closed to new replies.

Advertisement