-
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 (#2676)
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.
- Loading branch information
1 parent
1744347
commit cd18e7f
Showing
3 changed files
with
47 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
44 changes: 44 additions & 0 deletions
44
.../java/net/caffeinemc/mods/sodium/mixin/features/render/compositing/RenderTargetMixin.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,44 @@ | ||
package net.caffeinemc.mods.sodium.mixin.features.render.compositing; | ||
|
||
|
||
import com.mojang.blaze3d.pipeline.RenderTarget; | ||
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(RenderTarget.class) | ||
public class RenderTargetMixin { | ||
@Shadow | ||
public int frameBufferId; | ||
|
||
@Shadow | ||
public int width; | ||
|
||
@Shadow | ||
public int height; | ||
|
||
/** | ||
* @author JellySquid | ||
* @reason Use fixed function hardware for framebuffer blits | ||
*/ | ||
@Inject(method = "blitToScreen(IIZ)V", at = @At("HEAD"), cancellable = true) | ||
public void blitToScreen(int width, int height, boolean disableBlend, CallbackInfo ci) { | ||
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.frameBufferId); | ||
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