Skip to content

Commit 6358de8

Browse files
committed
Apply clear if needed
Add missing apply clear before binding the attachment as texture
1 parent 2ea032d commit 6358de8

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

src/main/java/net/vulkanmod/gl/GlFramebuffer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public static void resetBoundFramebuffer() {
2525
boundId = 0;
2626
}
2727

28-
static void beginRendering(GlFramebuffer glFramebuffer) {
28+
public static void beginRendering(GlFramebuffer glFramebuffer) {
2929
Renderer.getInstance().beginRendering(glFramebuffer.renderPass, glFramebuffer.framebuffer);
3030

3131
Framebuffer framebuffer = glFramebuffer.framebuffer;

src/main/java/net/vulkanmod/mixin/render/target/RenderTargetMixin.java

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import com.mojang.blaze3d.pipeline.RenderTarget;
44
import com.mojang.blaze3d.platform.GlStateManager;
5-
import com.mojang.blaze3d.platform.TextureUtil;
65
import com.mojang.blaze3d.systems.RenderSystem;
76
import net.vulkanmod.gl.GlFramebuffer;
87
import net.vulkanmod.gl.GlTexture;
@@ -14,13 +13,11 @@
1413
import net.vulkanmod.vulkan.util.DrawUtil;
1514
import org.lwjgl.opengl.GL30;
1615
import org.lwjgl.system.MemoryStack;
17-
import org.spongepowered.asm.mixin.Final;
18-
import org.spongepowered.asm.mixin.Mixin;
19-
import org.spongepowered.asm.mixin.Overwrite;
20-
import org.spongepowered.asm.mixin.Shadow;
16+
import org.spongepowered.asm.mixin.*;
2117
import org.spongepowered.asm.mixin.injection.At;
2218
import org.spongepowered.asm.mixin.injection.Inject;
2319
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
20+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
2421

2522
@Mixin(RenderTarget.class)
2623
public abstract class RenderTargetMixin implements ExtendedRenderTarget {
@@ -74,6 +71,9 @@ public void clear(boolean getError) {
7471
@Overwrite
7572
public void bindRead() {
7673
RenderSystem.assertOnRenderThread();
74+
75+
applyClear();
76+
7777
GlTexture.bindTexture(this.colorTextureId);
7878

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

140+
@Inject(method = "getColorTextureId", at = @At("HEAD"))
141+
private void injClear(CallbackInfoReturnable<Integer> cir) {
142+
applyClear();
143+
}
144+
140145
@Override
141146
public boolean isBound() {
142147
return bound;
@@ -146,4 +151,17 @@ public boolean isBound() {
146151
public RenderPass getRenderPass() {
147152
return GlFramebuffer.getFramebuffer(this.frameBufferId).getRenderPass();
148153
}
154+
155+
@Unique
156+
private void applyClear() {
157+
if (this.needClear) {
158+
GlFramebuffer currentFramebuffer = GlFramebuffer.getBoundFramebuffer();
159+
160+
this._bindWrite(false);
161+
162+
if (currentFramebuffer != null) {
163+
GlFramebuffer.beginRendering(currentFramebuffer);
164+
}
165+
}
166+
}
149167
}

0 commit comments

Comments
 (0)