Skip to content

Commit

Permalink
Clear render targets upon creation to avoid having them contain undef…
Browse files Browse the repository at this point in the history
…ined data

We interpreted the buffer clear directives a bit too literally. It's always necessary to clear color buffers before rendering to them.
  • Loading branch information
coderbot16 committed Jun 27, 2021
1 parent 07f3d12 commit 224cb5e
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/main/java/net/coderbot/iris/rendertarget/RenderTargets.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
/**
Expand Down Expand Up @@ -49,6 +52,21 @@ public RenderTargets(int width, int height, Map<Integer, PackRenderTargetDirecti
this.cachedHeight = height;

this.ownedFramebuffers = new ArrayList<>();

// 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() {
Expand Down

0 comments on commit 224cb5e

Please sign in to comment.