-
Notifications
You must be signed in to change notification settings - Fork 832
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use hardware copy for render target blits where possible
Minecraft performs a blit using a fragment shader, which is unnecessary when blending is not used. Using the fixed function hardware to perform the blit is much faster and doesn't utilize the rasterization engine. This is a cherry-pick of cd18e7f, 1ac46d0, and e1bae36.
- Loading branch information
1 parent
3c95e1d
commit e68abfb
Showing
3 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
...in/java/me/jellysquid/mods/sodium/mixin/features/render/compositing/FramebufferMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package me.jellysquid.mods.sodium.mixin.features.render.compositing; | ||
|
||
|
||
import net.caffeinemc.mods.sodium.client.compatibility.workarounds.Workarounds; | ||
import net.minecraft.client.gl.Framebuffer; | ||
import org.lwjgl.opengl.GL32C; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
@Mixin(Framebuffer.class) | ||
public class FramebufferMixin { | ||
@Shadow | ||
public int fbo; | ||
|
||
@Shadow | ||
public int textureWidth; | ||
|
||
@Shadow | ||
public int textureHeight; | ||
|
||
/** | ||
* @author JellySquid | ||
* @reason Use fixed function hardware for framebuffer blits | ||
*/ | ||
@Inject(method = "drawInternal", at = @At("HEAD"), cancellable = true) | ||
public void blitToScreen(int width, int height, boolean disableBlend, CallbackInfo ci) { | ||
if (Workarounds.isWorkaroundEnabled(Workarounds.Reference.INTEL_FRAMEBUFFER_BLIT_CRASH_WHEN_UNFOCUSED)) { | ||
return; | ||
} | ||
|
||
if (disableBlend) { | ||
ci.cancel(); | ||
|
||
// When blending is not used, we can directly copy the contents of one | ||
// framebuffer to another using the blitting engine. This can save a lot of time | ||
// when compared to going through the rasterization pipeline. | ||
GL32C.glBindFramebuffer(GL32C.GL_READ_FRAMEBUFFER, this.fbo); | ||
GL32C.glBlitFramebuffer( | ||
0, 0, width, height, | ||
0, 0, width, height, | ||
GL32C.GL_COLOR_BUFFER_BIT, GL32C.GL_LINEAR); | ||
GL32C.glBindFramebuffer(GL32C.GL_READ_FRAMEBUFFER, 0); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters