There seems to be very little info beyond the basic advice about minimising state changes. Is this an area where developers like to protect their secrets? Anyway, I would appreciate any and all comments on the strategy I am planning to implement in my (relatively simple) scenegraph (sg)…
My plan is a stack based state machine. Each node (in reality a selected few) in my sg “pushes” it’s desired states onto the stack. In doing so the current “locked” states will override new ones and “dirty” flags will be set for those states that have actually changed. Only dirty states will actually trigger the relevent OpenGL call. Apart from special conditions, such as at the start of rendering a frame, I have three situations during sg processing where states may be pushed/ popped: Parent-to-Child (PC), Child-to-Child (CC) and Child-to-Parent (CP).
The CC step is more correctly a CPC assuming parent states always override a previous child states (I don’t know if this would be considered “correct” in general sg theory). This I think needs special attention otherwise redundant state changes are possible if a parent sets, say, lighting on as a default for it’s children but C1 sets lighting off and then C2 also sets lighting off.
I’m also hoping that this stack based approach will lend itself to future optimisations, at least identifying candicate states for on-the-fly display list creation (maybe by caching the stack from the previously rendered frame).
Does this strategy sound over-compilicated, over-simplified, flimsy? Am I simply deluding myself and it’s just a short term hack that would have to be scrapped in the near future? I’m not asking anyone to give up hard earned secrets but I would appreciate a nudge in the right direction. Thanks in advance for any advice offered.