Skip to content

Commit

Permalink
Try making the unswizzle more reliable
Browse files Browse the repository at this point in the history
  • Loading branch information
IMS212 committed Dec 10, 2024
1 parent 92dd96d commit dad5dd1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
15 changes: 15 additions & 0 deletions common/src/main/java/net/irisshaders/iris/gl/IrisRenderSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.mojang.blaze3d.vertex.VertexSorting;
import net.irisshaders.iris.Iris;
import net.irisshaders.iris.gl.sampler.SamplerLimits;
import net.irisshaders.iris.gl.texture.TextureType;
import net.irisshaders.iris.mixin.GlStateManagerAccessor;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screens.Screen;
Expand All @@ -14,6 +15,7 @@
import org.joml.Vector3i;
import org.lwjgl.opengl.ARBDirectStateAccess;
import org.lwjgl.opengl.ARBDrawBuffersBlend;
import org.lwjgl.opengl.ARBTextureSwizzle;
import org.lwjgl.opengl.EXTShaderImageLoadStore;
import org.lwjgl.opengl.GL;
import org.lwjgl.opengl.GL30C;
Expand Down Expand Up @@ -44,6 +46,7 @@ public class IrisRenderSystem {
private static int polygonMode = GL43C.GL_FILL;
private static int backupPolygonMode = GL43C.GL_FILL;
private static int[] samplers;
private static int textureToUnswizzle;

public static void initRenderer() {
if (GL.getCapabilities().OpenGL45) {
Expand Down Expand Up @@ -486,6 +489,18 @@ public static void restoreCullingState() {
cullingState = true;
}

public static void onProgramUse() {
if (textureToUnswizzle != 0) {
IrisRenderSystem.texParameteriv(textureToUnswizzle, TextureType.TEXTURE_2D.getGlType(), ARBTextureSwizzle.GL_TEXTURE_SWIZZLE_RGBA,
new int[]{GL30C.GL_RED, GL30C.GL_GREEN, GL30C.GL_BLUE, GL30C.GL_ALPHA});
textureToUnswizzle = 0;
}
}

public static void setUnswizzle(int shaderTexture) {
textureToUnswizzle = shaderTexture;
}

public interface DSAAccess {
void generateMipmaps(int texture, int target);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.mojang.blaze3d.platform.GlConst;
import com.mojang.blaze3d.platform.GlStateManager;
import net.irisshaders.iris.gl.IrisRenderSystem;
import org.lwjgl.opengl.GL30C;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
Expand Down Expand Up @@ -54,6 +55,8 @@ public class MixinGlStateManager_FramebufferBinding {
ci.cancel();
}

IrisRenderSystem.onProgramUse();

iris$program = pInt0;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,6 @@ public void clear() {
BlendModeOverride.restore();
}

if (intensitySwizzle && textureToUnswizzle != 0) {
IrisRenderSystem.texParameteriv(textureToUnswizzle, TextureType.TEXTURE_2D.getGlType(), ARBTextureSwizzle.GL_TEXTURE_SWIZZLE_RGBA,
new int[]{GL30C.GL_RED, GL30C.GL_GREEN, GL30C.GL_BLUE, GL30C.GL_ALPHA});
textureToUnswizzle = 0;
}

Minecraft.getInstance().getMainRenderTarget().bindWrite(false);

super.clear();
Expand Down Expand Up @@ -184,7 +178,7 @@ public void apply() {
GlStateManager._activeTexture(i);

if (intensitySwizzle) {
this.textureToUnswizzle = RenderSystem.getShaderTexture(0);
IrisRenderSystem.setUnswizzle(RenderSystem.getShaderTexture(0));
IrisRenderSystem.texParameteriv(RenderSystem.getShaderTexture(0), TextureType.TEXTURE_2D.getGlType(), ARBTextureSwizzle.GL_TEXTURE_SWIZZLE_RGBA,
new int[]{GL30C.GL_RED, GL30C.GL_RED, GL30C.GL_RED, GL30C.GL_RED});
}
Expand Down

0 comments on commit dad5dd1

Please sign in to comment.