jME: Improved State Tracking
Back in July I talked about issues in jMonkeyEngine with tracking states across multiple OpenGL contexts. This has changed drastically with the latest changes checked into CVS last night. Now we have the concept of RenderContext and StateRecord. Basically, for each OpenGL context created in jMonkeyEngine, a RenderContext (RC) is also created. Each RC contains a number of StateRecords, each of which keep track of changes for a particular RenderState that have occurred in that given RC. This allows the individual RenderStates the ability to check if a state or value is already set in the current RC before making the expensive OpenGL call.
All of this eliminated the need for several hacks in our code:
- We were previously checking at the RenderState level if a state was already applied (using ==) This sped us up, but introduced artifacts because changes internally to the state could not be detected.
- Because of the problem with the hack discussed in point 1, we cleared the list of "currently applied states" at the end of every frame, meaning we had to reapply every state type every frame. Many states never get used in an app or game, and re-disabling them every frame was a big waste of time. Well, now we can track the state of OpenGL from frame to frame, so this is no longer an issue.
- Context changed required reapplying all of the default states every time just to make sure we knew what the current state of things were. Again, no longer needed.
That said, I imagine there are still many bugs in this new code. Still, so far it has held up nicely in the tests and our game code. Give it a whirl today!
Labels: jMonkeyEngine

