Skip to content

Commit dad5dd1

Browse files
committed
Try making the unswizzle more reliable
1 parent 92dd96d commit dad5dd1

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

common/src/main/java/net/irisshaders/iris/gl/IrisRenderSystem.java

+15
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.mojang.blaze3d.vertex.VertexSorting;
77
import net.irisshaders.iris.Iris;
88
import net.irisshaders.iris.gl.sampler.SamplerLimits;
9+
import net.irisshaders.iris.gl.texture.TextureType;
910
import net.irisshaders.iris.mixin.GlStateManagerAccessor;
1011
import net.minecraft.client.Minecraft;
1112
import net.minecraft.client.gui.screens.Screen;
@@ -14,6 +15,7 @@
1415
import org.joml.Vector3i;
1516
import org.lwjgl.opengl.ARBDirectStateAccess;
1617
import org.lwjgl.opengl.ARBDrawBuffersBlend;
18+
import org.lwjgl.opengl.ARBTextureSwizzle;
1719
import org.lwjgl.opengl.EXTShaderImageLoadStore;
1820
import org.lwjgl.opengl.GL;
1921
import org.lwjgl.opengl.GL30C;
@@ -44,6 +46,7 @@ public class IrisRenderSystem {
4446
private static int polygonMode = GL43C.GL_FILL;
4547
private static int backupPolygonMode = GL43C.GL_FILL;
4648
private static int[] samplers;
49+
private static int textureToUnswizzle;
4750

4851
public static void initRenderer() {
4952
if (GL.getCapabilities().OpenGL45) {
@@ -486,6 +489,18 @@ public static void restoreCullingState() {
486489
cullingState = true;
487490
}
488491

492+
public static void onProgramUse() {
493+
if (textureToUnswizzle != 0) {
494+
IrisRenderSystem.texParameteriv(textureToUnswizzle, TextureType.TEXTURE_2D.getGlType(), ARBTextureSwizzle.GL_TEXTURE_SWIZZLE_RGBA,
495+
new int[]{GL30C.GL_RED, GL30C.GL_GREEN, GL30C.GL_BLUE, GL30C.GL_ALPHA});
496+
textureToUnswizzle = 0;
497+
}
498+
}
499+
500+
public static void setUnswizzle(int shaderTexture) {
501+
textureToUnswizzle = shaderTexture;
502+
}
503+
489504
public interface DSAAccess {
490505
void generateMipmaps(int texture, int target);
491506

common/src/main/java/net/irisshaders/iris/mixin/MixinGlStateManager_FramebufferBinding.java

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.mojang.blaze3d.platform.GlConst;
44
import com.mojang.blaze3d.platform.GlStateManager;
5+
import net.irisshaders.iris.gl.IrisRenderSystem;
56
import org.lwjgl.opengl.GL30C;
67
import org.spongepowered.asm.mixin.Mixin;
78
import org.spongepowered.asm.mixin.Unique;
@@ -54,6 +55,8 @@ public class MixinGlStateManager_FramebufferBinding {
5455
ci.cancel();
5556
}
5657

58+
IrisRenderSystem.onProgramUse();
59+
5760
iris$program = pInt0;
5861
}
5962

common/src/main/java/net/irisshaders/iris/pipeline/programs/ExtendedShader.java

+1-7
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,6 @@ public void clear() {
146146
BlendModeOverride.restore();
147147
}
148148

149-
if (intensitySwizzle && textureToUnswizzle != 0) {
150-
IrisRenderSystem.texParameteriv(textureToUnswizzle, TextureType.TEXTURE_2D.getGlType(), ARBTextureSwizzle.GL_TEXTURE_SWIZZLE_RGBA,
151-
new int[]{GL30C.GL_RED, GL30C.GL_GREEN, GL30C.GL_BLUE, GL30C.GL_ALPHA});
152-
textureToUnswizzle = 0;
153-
}
154-
155149
Minecraft.getInstance().getMainRenderTarget().bindWrite(false);
156150

157151
super.clear();
@@ -184,7 +178,7 @@ public void apply() {
184178
GlStateManager._activeTexture(i);
185179

186180
if (intensitySwizzle) {
187-
this.textureToUnswizzle = RenderSystem.getShaderTexture(0);
181+
IrisRenderSystem.setUnswizzle(RenderSystem.getShaderTexture(0));
188182
IrisRenderSystem.texParameteriv(RenderSystem.getShaderTexture(0), TextureType.TEXTURE_2D.getGlType(), ARBTextureSwizzle.GL_TEXTURE_SWIZZLE_RGBA,
189183
new int[]{GL30C.GL_RED, GL30C.GL_RED, GL30C.GL_RED, GL30C.GL_RED});
190184
}

0 commit comments

Comments
 (0)