Skip to content

Commit cfb963c

Browse files
authored
URenderPipeline: Fix rendering being affected by global glShadeModel state
The `glShadeModel` state is initially `GL_SMOOTH`, but other code may change it to `GL_FLAT` and if it doesn't change it back afterwards, users of `URenderPipeline` may not get the expected render result (e.g. trying to draw a gradient will result in a single flat color instead). The chance of some user of `URenderPipeline` intentionally relying on this global state leaking in feels sufficiently low, that I don't think any backwards compatibility needs to be maintained for it. I don't think it is even necessary to make this behavior configurable, since we don't allow a single vertex to be shared by multiple primitives, so anything which could be achieved by using GL_FLAT can also by achieved by simply using the same data for all vertices of each primitive. And modern OpenGL doesn't support it anyway. GitHub: #116
1 parent da7bf4a commit cfb963c

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/main/kotlin/gg/essential/universal/render/ManagedGlState.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ internal class ManagedGlState(
2323
var polygonOffset: Boolean,
2424
var polygonOffsetFactor: Float,
2525
var polygonOffsetUnits: Float,
26+
var shadeModel: Int,
2627
var alphaTest: Boolean,
2728
var alphaTestFunc: Int,
2829
var alphaTestRef: Float,
@@ -40,6 +41,7 @@ internal class ManagedGlState(
4041
polygonOffset = other.polygonOffset,
4142
polygonOffsetFactor = other.polygonOffsetFactor,
4243
polygonOffsetUnits = other.polygonOffsetUnits,
44+
shadeModel = other.shadeModel,
4345
alphaTest = other.alphaTest,
4446
alphaTestFunc = other.alphaTestFunc,
4547
alphaTestRef = other.alphaTestRef,
@@ -160,6 +162,10 @@ internal class ManagedGlState(
160162
//#if MC>=11700
161163
//$$ @Suppress("UNUSED_VARIABLE") val unused = org
162164
//#else
165+
if (curr.shadeModel != shadeModel) {
166+
curr.shadeModel = shadeModel
167+
GlStateManager.shadeModel(shadeModel)
168+
}
163169
if (curr.alphaTest != alphaTest) {
164170
curr.alphaTest = alphaTest
165171
//#if MC==11602
@@ -212,10 +218,12 @@ internal class ManagedGlState(
212218
polygonOffsetFactor = GL11.glGetFloat(GL11.GL_POLYGON_OFFSET_FACTOR),
213219
polygonOffsetUnits = GL11.glGetFloat(GL11.GL_POLYGON_OFFSET_UNITS),
214220
//#if MC>=11700
221+
//$$ shadeModel = 0,
215222
//$$ alphaTest = false,
216223
//$$ alphaTestFunc = 0,
217224
//$$ alphaTestRef = 0f,
218225
//#else
226+
shadeModel = GL11.glGetInteger(GL11.GL_SHADE_MODEL),
219227
alphaTest = GL11.glGetBoolean(GL11.GL_ALPHA_TEST),
220228
alphaTestFunc = GL11.glGetInteger(GL11.GL_ALPHA_TEST_FUNC),
221229
alphaTestRef = GL11.glGetFloat(GL11.GL_ALPHA_TEST_REF),

src/main/kotlin/gg/essential/universal/render/URenderPipeline.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,7 @@ class URenderPipeline private constructor(
465465
polygonOffset = polygonOffset.first != 0f || polygonOffset.second != 0f,
466466
polygonOffsetFactor = polygonOffset.first,
467467
polygonOffsetUnits = polygonOffset.second,
468+
shadeModel = GL11.GL_SMOOTH,
468469
alphaTest = true,
469470
alphaTestFunc = GL11.GL_ALWAYS,
470471
alphaTestRef = 0f,

0 commit comments

Comments
 (0)