
JEI scene renderer should not use GLSM push/popAttrib()
jchung01 opened this issue · 3 comments
Using GLStateManager#push/popAttrib()
is discouraged, as it can desync the state between what OpenGL reports and what GLSM's copy of the state reports because of resetting GL modifiers directly. This may cause weird visual issues in other mods' renders down the line. If you put a breakpoint here while viewing a multiblock renderer recipe in JEI and compare the values of some states before and after calling popAttrib()
, you can see that the states are desynced.
Before call to popAttrib()
:
GlStateManager.blendState.blend.currentState = true
GL11.glIsEnabled(GL11.GL_BLEND) = true // GL equivalent of blendState
GlStateManager.lightingState.currentState = true
GL11.glIsEnabled(GL11.GL_LIGHTING) = true // GL equivalent of lightingState
After:
GlStateManager.blendState.blend.currentState = true
GL11.glIsEnabled(GL11.GL_BLEND) = false // Desynced
GlStateManager.lightingState.currentState = true
GL11.glIsEnabled(GL11.GL_LIGHTING) = false // Desynced
Instead of push/popAttrib()
, the only choice is to ensure you reset any modifiers you set yourself. Looks like it's also used in ConstellationRenderer.
See the Forge issue mentioned in the javadocs for GLStateManager#push/popAttrib()
and this gist for general details.
Would it be possible to submit a PR if possible? can't figure out what pushAttrib vs popAttrib does for now.
From my limited understanding of GLStateManager
(GLSM) and associated rendering code, GLSM wraps most calls to OpenGL functions in order to track its own copies of internal states for several flags/attributes. pushAttrib
pushes all current OpenGL states of the attributes onto a stack, and popAttrib
pops those attributes, restoring that snapshot of the attribute states. However, these two functions in GLSM just directly call OpenGL's functions without any verification with GLSM's own internal state copies, so when the attributes are popped, OpenGL's states and GLSM's copy of the states become desynced. This is not a problem if everything in between those two methods use raw GL, but could be a problem if any GLSM methods are used while the attributes are still on the stack. Even then, it may not be a problem because the attributes changed are set internally from other code anyways, but it's best not to rely on push/popAttrib
if using GLSM.