diff --git a/common/src/main/java/net/irisshaders/iris/Iris.java b/common/src/main/java/net/irisshaders/iris/Iris.java index 6066bab350..d16b55c7bb 100644 --- a/common/src/main/java/net/irisshaders/iris/Iris.java +++ b/common/src/main/java/net/irisshaders/iris/Iris.java @@ -355,7 +355,7 @@ private static boolean loadExternalShaderpack(String name) { } private static void handleException(Exception e) { - if (lastDimension != null && irisConfig.areDebugOptionsEnabled()) { + if (irisConfig.areDebugOptionsEnabled()) { Minecraft.getInstance().setScreen(new DebugLoadFailedGridScreen(Minecraft.getInstance().screen, Component.literal(e instanceof ShaderCompileException ? "Failed to compile shaders" : "Exception"), e)); } else { if (Minecraft.getInstance().player != null) { diff --git a/common/src/main/java/net/irisshaders/iris/compat/dh/LodRendererEvents.java b/common/src/main/java/net/irisshaders/iris/compat/dh/LodRendererEvents.java index 541262e153..a6df78d0b3 100644 --- a/common/src/main/java/net/irisshaders/iris/compat/dh/LodRendererEvents.java +++ b/common/src/main/java/net/irisshaders/iris/compat/dh/LodRendererEvents.java @@ -1,5 +1,6 @@ package net.irisshaders.iris.compat.dh; +import com.mojang.blaze3d.systems.RenderSystem; import com.seibel.distanthorizons.api.DhApi; import com.seibel.distanthorizons.api.enums.rendering.EDhApiFogDrawMode; import com.seibel.distanthorizons.api.enums.rendering.EDhApiRenderPass; @@ -197,7 +198,7 @@ public void beforeClear(DhApiCancelableEventParam event) { if (ShadowRenderingState.areShadowsCurrentlyBeingRendered()) { event.cancelEvent(); } else if (getInstance().shouldOverride) { - GL43C.glClear(GL43C.GL_DEPTH_BUFFER_BIT); + RenderSystem.clear(GL43C.GL_DEPTH_BUFFER_BIT); event.cancelEvent(); } } diff --git a/common/src/main/java/net/irisshaders/iris/gl/IrisRenderSystem.java b/common/src/main/java/net/irisshaders/iris/gl/IrisRenderSystem.java index 1d692a94fc..9a09e408c8 100644 --- a/common/src/main/java/net/irisshaders/iris/gl/IrisRenderSystem.java +++ b/common/src/main/java/net/irisshaders/iris/gl/IrisRenderSystem.java @@ -104,6 +104,11 @@ public static void uniformMatrix4fv(int location, boolean transpose, FloatBuffer GL32C.glUniformMatrix4fv(location, transpose, matrix); } + public static void uniformMatrix4fv(int location, boolean transpose, float[] matrix) { + RenderSystem.assertOnRenderThreadOrInit(); + GL32C.glUniformMatrix4fv(location, transpose, matrix); + } + public static void copyTexImage2D(int target, int level, int internalFormat, int x, int y, int width, int height, int border) { RenderSystem.assertOnRenderThreadOrInit(); GL32C.glCopyTexImage2D(target, level, internalFormat, x, y, width, height, border); @@ -454,6 +459,14 @@ public static int createBuffers() { return dsaState.createBuffers(); } + public static String getStringi(int glEnum, int index) { + return GL46C.glGetStringi(glEnum, index); + } + + public static void copyImageSubData(int sourceTexture, int target, int mip, int srcX, int srcY, int srcZ, int destTexture, int dstTarget, int dstMip, int dstX, int dstY, int dstZ, int width, int height, int depth) { + GL46C.glCopyImageSubData(sourceTexture, target, mip, srcX, srcY, srcZ, destTexture, dstTarget, dstMip, dstX, dstY, dstZ, width, height, depth); + } + public interface DSAAccess { void generateMipmaps(int texture, int target); diff --git a/common/src/main/java/net/irisshaders/iris/gl/buffer/ShaderStorageBuffer.java b/common/src/main/java/net/irisshaders/iris/gl/buffer/ShaderStorageBuffer.java index f26c8b68ca..9e332fe05d 100644 --- a/common/src/main/java/net/irisshaders/iris/gl/buffer/ShaderStorageBuffer.java +++ b/common/src/main/java/net/irisshaders/iris/gl/buffer/ShaderStorageBuffer.java @@ -74,7 +74,7 @@ public void createStatic() { GlStateManager._glBindBuffer(GL43C.GL_SHADER_STORAGE_BUFFER, getId()); IrisRenderSystem.bufferStorage(GL43C.GL_SHADER_STORAGE_BUFFER, info.size(), content == null ? 0 : GL46C.GL_DYNAMIC_STORAGE_BIT); if (content != null) { - GL46C.glBufferSubData(GL43C.GL_SHADER_STORAGE_BUFFER, 0, content); + GlStateManager._glBufferSubData(GL43C.GL_SHADER_STORAGE_BUFFER, 0, content); } else { IrisRenderSystem.clearBufferSubData(GL43C.GL_SHADER_STORAGE_BUFFER, GL43C.GL_R8, 0, info.size(), GL43C.GL_RED, GL43C.GL_BYTE, new int[]{0}); } diff --git a/common/src/main/java/net/irisshaders/iris/gl/shader/StandardMacros.java b/common/src/main/java/net/irisshaders/iris/gl/shader/StandardMacros.java index fa374a2222..d832f69740 100644 --- a/common/src/main/java/net/irisshaders/iris/gl/shader/StandardMacros.java +++ b/common/src/main/java/net/irisshaders/iris/gl/shader/StandardMacros.java @@ -5,6 +5,7 @@ import com.mojang.blaze3d.platform.GlUtil; import net.irisshaders.iris.Iris; import net.irisshaders.iris.compat.dh.DHCompat; +import net.irisshaders.iris.gl.IrisRenderSystem; import net.irisshaders.iris.helpers.StringPair; import net.irisshaders.iris.pathways.HandRenderer; import net.irisshaders.iris.pbr.format.TextureFormat; @@ -317,12 +318,12 @@ public static String getRenderer() { */ public static Set getGlExtensions() { // In OpenGL Core, we must use a new way of retrieving extensions. - int numExtensions = GL30C.glGetInteger(GL30C.GL_NUM_EXTENSIONS); + int numExtensions = GlStateManager._getInteger(GL30C.GL_NUM_EXTENSIONS); String[] extensions = new String[numExtensions]; for (int i = 0; i < numExtensions; i++) { - extensions[i] = GL30C.glGetStringi(GL30C.GL_EXTENSIONS, i); + extensions[i] = IrisRenderSystem.getStringi(GL30C.GL_EXTENSIONS, i); } // TODO note that we do not add extensions based on if the shader uses them and if they are supported diff --git a/common/src/main/java/net/irisshaders/iris/gl/texture/DepthCopyStrategy.java b/common/src/main/java/net/irisshaders/iris/gl/texture/DepthCopyStrategy.java index 2c12bfb3b0..2ba34a6f47 100644 --- a/common/src/main/java/net/irisshaders/iris/gl/texture/DepthCopyStrategy.java +++ b/common/src/main/java/net/irisshaders/iris/gl/texture/DepthCopyStrategy.java @@ -111,7 +111,7 @@ public boolean needsDestFramebuffer() { @Override public void copy(GlFramebuffer sourceFb, int sourceTexture, GlFramebuffer destFb, int destTexture, int width, int height) { - GL43C.glCopyImageSubData( + IrisRenderSystem.copyImageSubData( sourceTexture, GL43C.GL_TEXTURE_2D, 0, diff --git a/common/src/main/java/net/irisshaders/iris/pipeline/programs/ExtendedShader.java b/common/src/main/java/net/irisshaders/iris/pipeline/programs/ExtendedShader.java index d299eb359f..8c7668a70f 100644 --- a/common/src/main/java/net/irisshaders/iris/pipeline/programs/ExtendedShader.java +++ b/common/src/main/java/net/irisshaders/iris/pipeline/programs/ExtendedShader.java @@ -1,6 +1,7 @@ package net.irisshaders.iris.pipeline.programs; import com.mojang.blaze3d.platform.GlStateManager; +import com.mojang.blaze3d.platform.Window; import com.mojang.blaze3d.preprocessor.GlslPreprocessor; import com.mojang.blaze3d.shaders.CompiledShader; import com.mojang.blaze3d.shaders.Uniform; @@ -144,9 +145,30 @@ public void clear() { BlendModeOverride.restore(); } + if (intensitySwizzle) { + IrisRenderSystem.texParameteriv(RenderSystem.getShaderTexture(0), TextureType.TEXTURE_2D.getGlType(), ARBTextureSwizzle.GL_TEXTURE_SWIZZLE_RGBA, + new int[]{GL30C.GL_RED, GL30C.GL_GREEN, GL30C.GL_BLUE, GL30C.GL_ALPHA}); + } + Minecraft.getInstance().getMainRenderTarget().bindWrite(false); } + @Override + public void setDefaultUniforms(VertexFormat.Mode mode, Matrix4f modelView, Matrix4f projection, Window window) { + super.setDefaultUniforms(mode, modelView, projection, window); + if (modelViewInverse != null) { + modelViewInverse.set(modelView.invert(tempMatrix4f)); + } + + if (normalMatrix != null) { + normalMatrix.set(modelView.invert(tempMatrix4f).transpose3x3(tempMatrix3f)); + } + + if (projectionInverse != null) { + projectionInverse.set(projection.invert(tempMatrix4f)); + } + } + @Override public void apply() { CapturedRenderingState.INSTANCE.setCurrentAlphaTest(alphaTest); @@ -168,26 +190,6 @@ public void apply() { ImmediateState.usingTessellation = usesTessellation; - if (PROJECTION_MATRIX != null) { - if (projectionInverse != null) { - projectionInverse.set(tempMatrix4f.set(PROJECTION_MATRIX.getFloatBuffer()).invert().get(tempFloats)); - } - } else { - if (projectionInverse != null) { - projectionInverse.set(identity); - } - } - - if (MODEL_VIEW_MATRIX != null) { - if (modelViewInverse != null) { - modelViewInverse.set(tempMatrix4f.set(MODEL_VIEW_MATRIX.getFloatBuffer()).invert().get(tempFloats)); - } - - if (normalMatrix != null) { - normalMatrix.set(tempMatrix3f.set(tempMatrix4f.set(MODEL_VIEW_MATRIX.getFloatBuffer())).invert().transpose().get(tempFloats2)); - } - } - uploadIfNotNull(projectionInverse); uploadIfNotNull(modelViewInverse); uploadIfNotNull(normalMatrix); @@ -204,7 +206,7 @@ public void apply() { images.update(); - GL46C.glUniform1i(GlStateManager._glGetUniformLocation(getProgramId(), "iris_overlay"), 1); + //GL46C.glUniform1i(GlStateManager._glGetUniformLocation(getProgramId(), "iris_overlay"), 1); if (this.blendModeOverride != null) { this.blendModeOverride.apply(); diff --git a/common/src/main/java/net/irisshaders/iris/pipeline/programs/GlUniformMatrix3f.java b/common/src/main/java/net/irisshaders/iris/pipeline/programs/GlUniformMatrix3f.java index e20ce9372e..41c8cf58bd 100644 --- a/common/src/main/java/net/irisshaders/iris/pipeline/programs/GlUniformMatrix3f.java +++ b/common/src/main/java/net/irisshaders/iris/pipeline/programs/GlUniformMatrix3f.java @@ -1,5 +1,6 @@ package net.irisshaders.iris.pipeline.programs; +import com.mojang.blaze3d.platform.GlStateManager; import net.caffeinemc.mods.sodium.client.gl.shader.uniform.GlUniform; import org.joml.Matrix3fc; import org.lwjgl.opengl.GL30C; @@ -16,7 +17,7 @@ public void set(Matrix3fc value) { try (MemoryStack stack = MemoryStack.stackPush()) { FloatBuffer buf = stack.callocFloat(9); value.get(buf); - GL30C.glUniformMatrix3fv(this.index, false, buf); + GlStateManager._glUniformMatrix3(this.index, false, buf); } } } diff --git a/common/src/main/java/net/irisshaders/iris/pipeline/programs/SodiumPrograms.java b/common/src/main/java/net/irisshaders/iris/pipeline/programs/SodiumPrograms.java index b4bcba383d..1a92538044 100644 --- a/common/src/main/java/net/irisshaders/iris/pipeline/programs/SodiumPrograms.java +++ b/common/src/main/java/net/irisshaders/iris/pipeline/programs/SodiumPrograms.java @@ -2,6 +2,7 @@ import com.google.common.collect.ImmutableSet; import com.google.common.primitives.Ints; +import com.mojang.blaze3d.platform.GlStateManager; import net.caffeinemc.mods.sodium.client.gl.GlObject; import net.caffeinemc.mods.sodium.client.gl.shader.GlProgram; import net.caffeinemc.mods.sodium.client.gl.shader.GlShader; @@ -168,10 +169,10 @@ private GlProgram buildProgram(GlProgram.Builder builder, int handle = ((GlObject) shader).handle(); GLDebug.nameObject(GL43C.GL_PROGRAM, handle, "sodium-terrain-" + pass.toString().toLowerCase(Locale.ROOT)); - if (!hasNormal) hasNormal = GL43C.glGetAttribLocation(handle, "iris_Normal") != -1; - if (!hasMidBlock) hasMidBlock = GL43C.glGetAttribLocation(handle, "at_midBlock") != -1; - if (!hasBlockId) hasBlockId = GL43C.glGetAttribLocation(handle, "mc_Entity") != -1; - if (!hasMidUv) hasMidUv = GL43C.glGetAttribLocation(handle, "mc_midTexCoord") != -1; + if (!hasNormal) hasNormal = GlStateManager._glGetAttribLocation(handle, "iris_Normal") != -1; + if (!hasMidBlock) hasMidBlock = GlStateManager._glGetAttribLocation(handle, "at_midBlock") != -1; + if (!hasBlockId) hasBlockId = GlStateManager._glGetAttribLocation(handle, "mc_Entity") != -1; + if (!hasMidUv) hasMidUv = GlStateManager._glGetAttribLocation(handle, "mc_midTexCoord") != -1; return new SodiumShader(pipeline, pass, shader, handle, source.getDirectives().getBlendModeOverride().orElse(null), createBufferBlendOverrides(source), customUniforms, flipState, diff --git a/common/src/main/java/net/irisshaders/iris/uniforms/custom/cached/BooleanCachedUniform.java b/common/src/main/java/net/irisshaders/iris/uniforms/custom/cached/BooleanCachedUniform.java index bbd037c39b..bba9f23474 100644 --- a/common/src/main/java/net/irisshaders/iris/uniforms/custom/cached/BooleanCachedUniform.java +++ b/common/src/main/java/net/irisshaders/iris/uniforms/custom/cached/BooleanCachedUniform.java @@ -1,5 +1,6 @@ package net.irisshaders.iris.uniforms.custom.cached; +import com.mojang.blaze3d.systems.RenderSystem; import kroppeb.stareval.function.FunctionReturn; import kroppeb.stareval.function.Type; import net.irisshaders.iris.gl.uniform.UniformUpdateFrequency; @@ -26,7 +27,7 @@ protected boolean doUpdate() { @Override public void push(int location) { - GL21.glUniform1i(location, this.cached ? 1 : 0); + RenderSystem.glUniform1i(location, this.cached ? 1 : 0); } @Override diff --git a/common/src/main/java/net/irisshaders/iris/uniforms/custom/cached/Float2VectorCachedUniform.java b/common/src/main/java/net/irisshaders/iris/uniforms/custom/cached/Float2VectorCachedUniform.java index d891647983..3f20508a0a 100644 --- a/common/src/main/java/net/irisshaders/iris/uniforms/custom/cached/Float2VectorCachedUniform.java +++ b/common/src/main/java/net/irisshaders/iris/uniforms/custom/cached/Float2VectorCachedUniform.java @@ -1,5 +1,6 @@ package net.irisshaders.iris.uniforms.custom.cached; +import net.irisshaders.iris.gl.IrisRenderSystem; import net.irisshaders.iris.gl.uniform.UniformUpdateFrequency; import net.irisshaders.iris.parsing.VectorType; import org.joml.Vector2f; @@ -20,7 +21,7 @@ protected void setFrom(Vector2f other) { @Override public void push(int location) { - GL21.glUniform2f(location, this.cached.x, this.cached.y); + IrisRenderSystem.uniform2f(location, this.cached.x, this.cached.y); } @Override diff --git a/common/src/main/java/net/irisshaders/iris/uniforms/custom/cached/Float3VectorCachedUniform.java b/common/src/main/java/net/irisshaders/iris/uniforms/custom/cached/Float3VectorCachedUniform.java index 269a8c11e8..f97ce79655 100644 --- a/common/src/main/java/net/irisshaders/iris/uniforms/custom/cached/Float3VectorCachedUniform.java +++ b/common/src/main/java/net/irisshaders/iris/uniforms/custom/cached/Float3VectorCachedUniform.java @@ -1,5 +1,6 @@ package net.irisshaders.iris.uniforms.custom.cached; +import net.irisshaders.iris.gl.IrisRenderSystem; import net.irisshaders.iris.gl.uniform.UniformUpdateFrequency; import net.irisshaders.iris.parsing.VectorType; import org.joml.Vector3f; @@ -20,7 +21,7 @@ protected void setFrom(Vector3f other) { @Override public void push(int location) { - GL21.glUniform3f(location, this.cached.x, this.cached.y, this.cached.z); + IrisRenderSystem.uniform3f(location, this.cached.x, this.cached.y, this.cached.z); } @Override diff --git a/common/src/main/java/net/irisshaders/iris/uniforms/custom/cached/Float4MatrixCachedUniform.java b/common/src/main/java/net/irisshaders/iris/uniforms/custom/cached/Float4MatrixCachedUniform.java index 209f2050ca..b706e69683 100644 --- a/common/src/main/java/net/irisshaders/iris/uniforms/custom/cached/Float4MatrixCachedUniform.java +++ b/common/src/main/java/net/irisshaders/iris/uniforms/custom/cached/Float4MatrixCachedUniform.java @@ -1,5 +1,7 @@ package net.irisshaders.iris.uniforms.custom.cached; +import com.mojang.blaze3d.systems.RenderSystem; +import net.irisshaders.iris.gl.IrisRenderSystem; import net.irisshaders.iris.gl.uniform.UniformUpdateFrequency; import net.irisshaders.iris.parsing.MatrixType; import org.joml.Matrix4f; @@ -24,7 +26,7 @@ protected void setFrom(Matrix4fc other) { public void push(int location) { // `gets` the values from the matrix and put's them into a buffer this.cached.get(buffer); - GL21.glUniformMatrix4fv(location, false, buffer); + IrisRenderSystem.uniformMatrix4fv(location, false, buffer); } @Override diff --git a/common/src/main/java/net/irisshaders/iris/uniforms/custom/cached/Float4VectorCachedUniform.java b/common/src/main/java/net/irisshaders/iris/uniforms/custom/cached/Float4VectorCachedUniform.java index fc2fed99cd..7cb4f0b0d8 100644 --- a/common/src/main/java/net/irisshaders/iris/uniforms/custom/cached/Float4VectorCachedUniform.java +++ b/common/src/main/java/net/irisshaders/iris/uniforms/custom/cached/Float4VectorCachedUniform.java @@ -1,5 +1,6 @@ package net.irisshaders.iris.uniforms.custom.cached; +import net.irisshaders.iris.gl.IrisRenderSystem; import net.irisshaders.iris.gl.uniform.UniformUpdateFrequency; import net.irisshaders.iris.parsing.VectorType; import org.joml.Vector4f; @@ -20,7 +21,7 @@ protected void setFrom(Vector4f other) { @Override public void push(int location) { - GL21.glUniform4f(location, this.cached.x, this.cached.y, this.cached.z, this.cached.w); + IrisRenderSystem.uniform4f(location, this.cached.x, this.cached.y, this.cached.z, this.cached.w); } @Override diff --git a/common/src/main/java/net/irisshaders/iris/uniforms/custom/cached/FloatCachedUniform.java b/common/src/main/java/net/irisshaders/iris/uniforms/custom/cached/FloatCachedUniform.java index 59e76d0211..e898bd3433 100644 --- a/common/src/main/java/net/irisshaders/iris/uniforms/custom/cached/FloatCachedUniform.java +++ b/common/src/main/java/net/irisshaders/iris/uniforms/custom/cached/FloatCachedUniform.java @@ -2,6 +2,7 @@ import kroppeb.stareval.function.FunctionReturn; import kroppeb.stareval.function.Type; +import net.irisshaders.iris.gl.IrisRenderSystem; import net.irisshaders.iris.gl.uniform.FloatSupplier; import net.irisshaders.iris.gl.uniform.UniformUpdateFrequency; import org.lwjgl.opengl.GL21; @@ -25,7 +26,7 @@ protected boolean doUpdate() { @Override public void push(int location) { - GL21.glUniform1f(location, this.cached); + IrisRenderSystem.uniform1f(location, this.cached); } @Override diff --git a/common/src/main/java/net/irisshaders/iris/uniforms/custom/cached/Int2VectorCachedUniform.java b/common/src/main/java/net/irisshaders/iris/uniforms/custom/cached/Int2VectorCachedUniform.java index 9b568b8469..8703081376 100644 --- a/common/src/main/java/net/irisshaders/iris/uniforms/custom/cached/Int2VectorCachedUniform.java +++ b/common/src/main/java/net/irisshaders/iris/uniforms/custom/cached/Int2VectorCachedUniform.java @@ -1,6 +1,7 @@ package net.irisshaders.iris.uniforms.custom.cached; import kroppeb.stareval.function.FunctionReturn; +import net.irisshaders.iris.gl.IrisRenderSystem; import net.irisshaders.iris.gl.uniform.UniformUpdateFrequency; import net.irisshaders.iris.parsing.VectorType; import org.joml.Vector2i; @@ -21,7 +22,7 @@ protected void setFrom(Vector2i other) { @Override public void push(int location) { - GL21.glUniform2i(location, this.cached.x, this.cached.y); + IrisRenderSystem.uniform2i(location, this.cached.x, this.cached.y); } @Override diff --git a/common/src/main/java/net/irisshaders/iris/uniforms/custom/cached/Int3VectorCachedUniform.java b/common/src/main/java/net/irisshaders/iris/uniforms/custom/cached/Int3VectorCachedUniform.java index b974ebbaef..6f3dd187ed 100644 --- a/common/src/main/java/net/irisshaders/iris/uniforms/custom/cached/Int3VectorCachedUniform.java +++ b/common/src/main/java/net/irisshaders/iris/uniforms/custom/cached/Int3VectorCachedUniform.java @@ -1,5 +1,6 @@ package net.irisshaders.iris.uniforms.custom.cached; +import net.irisshaders.iris.gl.IrisRenderSystem; import net.irisshaders.iris.gl.uniform.UniformUpdateFrequency; import net.irisshaders.iris.parsing.VectorType; import org.joml.Vector3i; @@ -20,7 +21,7 @@ protected void setFrom(Vector3i other) { @Override public void push(int location) { - GL21.glUniform3i(location, this.cached.x, this.cached.y, this.cached.z); + IrisRenderSystem.uniform3i(location, this.cached.x, this.cached.y, this.cached.z); } @Override diff --git a/common/src/main/java/net/irisshaders/iris/uniforms/custom/cached/IntCachedUniform.java b/common/src/main/java/net/irisshaders/iris/uniforms/custom/cached/IntCachedUniform.java index a9182b6605..140f4e5b18 100644 --- a/common/src/main/java/net/irisshaders/iris/uniforms/custom/cached/IntCachedUniform.java +++ b/common/src/main/java/net/irisshaders/iris/uniforms/custom/cached/IntCachedUniform.java @@ -1,5 +1,6 @@ package net.irisshaders.iris.uniforms.custom.cached; +import com.mojang.blaze3d.systems.RenderSystem; import kroppeb.stareval.function.FunctionReturn; import kroppeb.stareval.function.Type; import net.irisshaders.iris.gl.uniform.UniformUpdateFrequency; @@ -26,7 +27,7 @@ protected boolean doUpdate() { @Override public void push(int location) { - GL21.glUniform1i(location, this.cached); + RenderSystem.glUniform1i(location, this.cached); } @Override