From 224cb5eb19dd253b58d74dc2ae386e36c39db596 Mon Sep 17 00:00:00 2001 From: coderbot Date: Sat, 26 Jun 2021 23:20:38 -0400 Subject: [PATCH] Clear render targets upon creation to avoid having them contain undefined data We interpreted the buffer clear directives a bit too literally. It's always necessary to clear color buffers before rendering to them. --- .../iris/rendertarget/RenderTargets.java | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/coderbot/iris/rendertarget/RenderTargets.java b/src/main/java/net/coderbot/iris/rendertarget/RenderTargets.java index 47375eb5a7..5dbbe7bf3a 100644 --- a/src/main/java/net/coderbot/iris/rendertarget/RenderTargets.java +++ b/src/main/java/net/coderbot/iris/rendertarget/RenderTargets.java @@ -6,13 +6,16 @@ import java.util.Map; import com.google.common.collect.ImmutableSet; +import com.mojang.blaze3d.platform.GlStateManager; +import com.mojang.blaze3d.systems.RenderSystem; import net.coderbot.iris.Iris; import net.coderbot.iris.gl.framebuffer.GlFramebuffer; -import net.coderbot.iris.gl.texture.InternalTextureFormat; -import net.coderbot.iris.shaderpack.PackDirectives; import net.coderbot.iris.shaderpack.PackRenderTargetDirectives; +import net.minecraft.client.MinecraftClient; import net.minecraft.client.gl.Framebuffer; +import org.lwjgl.opengl.GL20C; +import org.lwjgl.opengl.GL30C; public class RenderTargets { /** @@ -49,6 +52,21 @@ public RenderTargets(int width, int height, Map(); + + // NB: Make sure all buffers are cleared so that they don't contain undefined + // data. Otherwise very weird things can happen. + // + // TODO: Make this respect the clear color of each buffer, destroy these framebuffers afterwards. + RenderSystem.clearColor(0.0f, 0.0f, 0.0f, 0.0f); + + createFramebufferWritingToMain(new int[] {0,1,2,3,4,5,6,7}).bind(); + RenderSystem.clear(GL20C.GL_COLOR_BUFFER_BIT, false); + + createFramebufferWritingToAlt(new int[] {0,1,2,3,4,5,6,7}).bind(); + RenderSystem.clear(GL20C.GL_COLOR_BUFFER_BIT, false); + + // Make sure to rebind the vanilla framebuffer. + MinecraftClient.getInstance().getFramebuffer().beginWrite(false); } public void destroy() {