Skip to content

Commit

Permalink
Apply clear if needed
Browse files Browse the repository at this point in the history
Add missing apply clear before binding the attachment as texture
  • Loading branch information
xCollateral committed Sep 29, 2024
1 parent 2ea032d commit 6358de8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/main/java/net/vulkanmod/gl/GlFramebuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static void resetBoundFramebuffer() {
boundId = 0;
}

static void beginRendering(GlFramebuffer glFramebuffer) {
public static void beginRendering(GlFramebuffer glFramebuffer) {
Renderer.getInstance().beginRendering(glFramebuffer.renderPass, glFramebuffer.framebuffer);

Framebuffer framebuffer = glFramebuffer.framebuffer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.mojang.blaze3d.pipeline.RenderTarget;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.platform.TextureUtil;
import com.mojang.blaze3d.systems.RenderSystem;
import net.vulkanmod.gl.GlFramebuffer;
import net.vulkanmod.gl.GlTexture;
Expand All @@ -14,13 +13,11 @@
import net.vulkanmod.vulkan.util.DrawUtil;
import org.lwjgl.opengl.GL30;
import org.lwjgl.system.MemoryStack;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.*;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(RenderTarget.class)
public abstract class RenderTargetMixin implements ExtendedRenderTarget {
Expand Down Expand Up @@ -74,6 +71,9 @@ public void clear(boolean getError) {
@Overwrite
public void bindRead() {
RenderSystem.assertOnRenderThread();

applyClear();

GlTexture.bindTexture(this.colorTextureId);

try (MemoryStack stack = MemoryStack.stackPush()) {
Expand Down Expand Up @@ -137,6 +137,11 @@ private void _blitToScreen(int width, int height, boolean disableBlend, Callback
ci.cancel();
}

@Inject(method = "getColorTextureId", at = @At("HEAD"))
private void injClear(CallbackInfoReturnable<Integer> cir) {
applyClear();
}

@Override
public boolean isBound() {
return bound;
Expand All @@ -146,4 +151,17 @@ public boolean isBound() {
public RenderPass getRenderPass() {
return GlFramebuffer.getFramebuffer(this.frameBufferId).getRenderPass();
}

@Unique
private void applyClear() {
if (this.needClear) {
GlFramebuffer currentFramebuffer = GlFramebuffer.getBoundFramebuffer();

this._bindWrite(false);

if (currentFramebuffer != null) {
GlFramebuffer.beginRendering(currentFramebuffer);
}
}
}
}

0 comments on commit 6358de8

Please sign in to comment.