diff --git a/core/src/main/java/com/seibel/distanthorizons/core/render/glObject/GLState.java b/core/src/main/java/com/seibel/distanthorizons/core/render/glObject/GLState.java index f863e8e09..08b569f57 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/render/glObject/GLState.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/render/glObject/GLState.java @@ -36,10 +36,13 @@ public class GLState public int activeTextureNumber; public int texture0; public int texture1; + public int texture2; + public int texture3; public int frameBufferTexture0; public int frameBufferTexture1; public int frameBufferDepthTexture; public boolean blend; + public boolean scissor; public int blendEqRGB; public int blendEqAlpha; public int blendSrcColor; @@ -83,6 +86,12 @@ public class GLState GL32.glActiveTexture(GL32.GL_TEXTURE1); this.texture1 = GL32.glGetInteger(GL32.GL_TEXTURE_BINDING_2D); + GL32.glActiveTexture(GL32.GL_TEXTURE2); + this.texture2 = GL32.glGetInteger(GL32.GL_TEXTURE_BINDING_2D); + + GL32.glActiveTexture(GL32.GL_TEXTURE3); + this.texture3= GL32.glGetInteger(GL32.GL_TEXTURE_BINDING_2D); + GL32.glActiveTexture(this.activeTextureNumber); this.frameBufferTexture0 = GL32.glGetFramebufferAttachmentParameteri(GL32.GL_FRAMEBUFFER, GL32.GL_COLOR_ATTACHMENT0, GL32.GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME); @@ -90,6 +99,7 @@ public class GLState this.frameBufferDepthTexture = GL32.glGetFramebufferAttachmentParameteri(GL32.GL_FRAMEBUFFER, GL32.GL_DEPTH_ATTACHMENT, GL32.GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME); this.blend = GL32.glIsEnabled(GL32.GL_BLEND); + this.scissor = GL32.glIsEnabled(GL32.GL_SCISSOR_TEST); this.blendEqRGB = GL32.glGetInteger(GL32.GL_BLEND_EQUATION_RGB); this.blendEqAlpha = GL32.glGetInteger(GL32.GL_BLEND_EQUATION_ALPHA); this.blendSrcColor = GL32.glGetInteger(GL32.GL_BLEND_SRC_RGB); @@ -119,7 +129,7 @@ public class GLState ", FB text0=" + this.frameBufferTexture0 + ", FB text1=" + this.frameBufferTexture1 + ", FB depth=" + this.frameBufferDepthTexture + - ", blend=" + this.blend + ", blendMode=" + GLEnums.getString(this.blendSrcColor) + "," + GLEnums.getString(this.blendDstColor) + + ", blend=" + this.blend + ", scissor=" + this.scissor + ", blendMode=" + GLEnums.getString(this.blendSrcColor) + "," + GLEnums.getString(this.blendDstColor) + ", depth=" + this.depth + ", depthFunc=" + GLEnums.getString(this.depthFunc) + ", stencil=" + this.stencil + ", stencilFunc=" + GLEnums.getString(this.stencilFunc) + ", stencilRef=" + this.stencilRef + ", stencilMask=" + this.stencilMask + @@ -156,12 +166,27 @@ public class GLState GL32.glDisable(GL32.GL_BLEND); } + if (this.scissor) + { + GL32.glEnable(GL32.GL_SCISSOR_TEST); + } + else + { + GL32.glDisable(GL32.GL_SCISSOR_TEST); + } + GL32.glActiveTexture(GL32.GL_TEXTURE0); GL32.glBindTexture(GL32.GL_TEXTURE_2D, GL32.glIsTexture(this.texture0) ? this.texture0 : 0); GL32.glActiveTexture(GL32.GL_TEXTURE1); GL32.glBindTexture(GL32.GL_TEXTURE_2D, GL32.glIsTexture(this.texture1) ? this.texture1 : 0); + GL32.glActiveTexture(GL32.GL_TEXTURE2); + GL32.glBindTexture(GL32.GL_TEXTURE_2D, GL32.glIsTexture(this.texture2) ? this.texture2 : 0); + + GL32.glActiveTexture(GL32.GL_TEXTURE3); + GL32.glBindTexture(GL32.GL_TEXTURE_2D, GL32.glIsTexture(this.texture3) ? this.texture3 : 0); + GL32.glActiveTexture(this.activeTextureNumber); GL32.glBindTexture(GL32.GL_TEXTURE_2D, GL32.glIsTexture(this.texture2D) ? this.texture2D : 0); diff --git a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/FadeRenderer.java b/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/FadeRenderer.java index a236f3488..599d5b053 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/FadeRenderer.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/FadeRenderer.java @@ -116,7 +116,6 @@ public class FadeRenderer GLState mcState = new GLState(); - GLState state = new GLState(); try { @@ -148,9 +147,6 @@ public class FadeRenderer FadeApplyShader.INSTANCE.fadeTexture = this.fadeTexture; FadeApplyShader.INSTANCE.render(partialTicks); - // restored to remove FadeApplyShader GL state changes - mcState.restore(); - profiler.pop(); } catch (Exception e) @@ -159,7 +155,8 @@ public class FadeRenderer } finally { - state.restore(); + // make sure we always revert to MC's state to prevent GL state corruption + mcState.restore(); } } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/shaders/FadeShader.java b/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/shaders/FadeShader.java index 65170c412..9da231567 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/shaders/FadeShader.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/shaders/FadeShader.java @@ -176,10 +176,6 @@ public class FadeShader extends AbstractShaderRenderer GL32.glBindTexture(GL32.GL_TEXTURE_2D, LodRenderer.getActiveColorTextureId()); GL32.glUniform1i(this.uDhColorTexture, 3); - // this is necessary for MC 1.16 (IE Legacy OpenGL) - // otherwise the framebuffer isn't cleared correctly and the fade smears across the screen - GL32.glClear(GL32.GL_COLOR_BUFFER_BIT | GL32.GL_DEPTH_BUFFER_BIT); - ScreenQuad.INSTANCE.render();