copy depth buffer from MC for HUD caching

This commit is contained in:
Pistonight authored and Jason Mitchell committed 2024-01-26 10:34:46 -08:00
1 parent 3ee82e7157
commit 65d9bf8f2f
4 files changed
+51 -54

No files matched your search

@@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.List;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL30;
import com.gtnewhorizons.angelica.glsm.GLStateManager;
import com.gtnewhorizons.angelica.glsm.TessellatorManager;
@@ -34,10 +35,7 @@ public class HUDCaching {
public static Framebuffer framebuffer;
static {
framebuffer = new Framebuffer(0, 0, true);
framebuffer.framebufferColor[0] = 0.0F;
framebuffer.framebufferColor[1] = 0.0F;
framebuffer.framebufferColor[2] = 0.0F;
framebuffer.framebufferColor[3] = 0.0F;
framebuffer.setFramebufferColor(0, 0, 0, 0);
}
private static boolean dirty = true;
@@ -112,30 +110,23 @@ public class HUDCaching {
return;
}
GLStateManager.enableDepthTest();
ScaledResolution resolution = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);
int width = resolution.getScaledWidth();
int height = resolution.getScaledHeight();
renderer.setupOverlayRendering();
GLStateManager.enableBlend();
if (dirty) {
dirty = false;
checkFramebufferSizes(mc.displayWidth, mc.displayHeight);
framebuffer.framebufferClear();
resetFramebuffer(mc.displayWidth, mc.displayHeight);
framebuffer.bindFramebuffer(false);
GLStateManager.disableBlend();
GLStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA);
GLStateManager.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
GLStateManager.disableLighting();
GLStateManager.disableFog();
renderingCacheOverride = true;
ingame.renderGameOverlay(partialTicks, hasScreen, mouseX, mouseY);
renderingCacheOverride = false;
mc.getFramebuffer().bindFramebuffer(false);
GLStateManager.enableBlend();
} else {
renderer.setupOverlayRendering();
}
ScaledResolution resolution = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);
int width = resolution.getScaledWidth();
int height = resolution.getScaledHeight();
GLStateManager.enableBlend();
// reset the color that may be applied by some items
GLStateManager.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
@@ -148,8 +139,6 @@ public class HUDCaching {
GLStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0);
}
Tessellator tessellator = TessellatorManager.get();
if (ingame instanceof GuiIngameForge) {
GuiIngameForgeAccessor guiForge = ((GuiIngameForgeAccessor) ingame);
if (renderHelmetCaptured) {
@@ -168,36 +157,46 @@ public class HUDCaching {
}
if (renderPortalCapturedTicks > 0)
{
gui.callFunc_130015_b(renderPortalCapturedTicks, width, height);
}
if (renderCrosshairsCaptured) {
mc.getTextureManager().bindTexture(Gui.icons);
GLStateManager.enableBlend();
GLStateManager.tryBlendFuncSeparate(GL11.GL_ONE_MINUS_DST_COLOR, GL11.GL_ONE_MINUS_SRC_COLOR, GL11.GL_ONE, GL11.GL_ZERO);
GLStateManager.enableAlphaTest();
drawTexturedModalRect(tessellator, (width >> 1) - 7, (height >> 1) - 7);
GLStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ZERO);
gui.callRenderPortal(renderPortalCapturedTicks, width, height);
}
}
// render cached frame
Tessellator tessellator = TessellatorManager.get();
GLStateManager.enableBlend();
GLStateManager.tryBlendFuncSeparate(GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA);
GLStateManager.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
framebuffer.bindFramebufferTexture();
drawTexturedRect(tessellator, (float) resolution.getScaledWidth_double(), (float) resolution.getScaledHeight_double());
GLStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ZERO);
GLStateManager.enableDepthTest();
GLStateManager.tryBlendFuncSeparate(GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ZERO);
mc.getTextureManager().bindTexture(Gui.icons);
}
/**
* We are skipping certain render calls when rendering into cache,
* however, we cannot skip the GL state changes. This will fix
* the state before we start rendering
*/
public static void fixGLStateBeforeRenderingCache() {
GLStateManager.glDepthMask(true);
GLStateManager.enableDepthTest();
GLStateManager.enableAlphaTest();
GLStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ZERO);
GLStateManager.disableBlend();
}
private static void checkFramebufferSizes(int width, int height) {
private static void resetFramebuffer(int width, int height) {
if (framebuffer.framebufferWidth != width || framebuffer.framebufferHeight != height) {
framebuffer.createBindFramebuffer(width, height);
framebuffer.framebufferWidth = width;
framebuffer.framebufferHeight = height;
framebuffer.createBindFramebuffer(width, height);
framebuffer.setFramebufferFilter(GL11.GL_NEAREST);
} else {
framebuffer.framebufferClear();
}
// copy depth buffer from MC
OpenGlHelper.func_153171_g(GL30.GL_READ_FRAMEBUFFER, mc.getFramebuffer().framebufferObject);
OpenGlHelper.func_153171_g(GL30.GL_DRAW_FRAMEBUFFER, framebuffer.framebufferObject);
GL30.glBlitFramebuffer(0, 0, width, height, 0, 0, width, height, GL11.GL_DEPTH_BUFFER_BIT | GL11.GL_STENCIL_BUFFER_BIT, GL11.GL_NEAREST);
}
private static void drawTexturedRect(Tessellator tessellator, float width, float height) {
@@ -214,13 +213,4 @@ public class HUDCaching {
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
}
private static void drawTexturedModalRect(Tessellator tessellator, int x, int y) {
tessellator.startDrawingQuads();
tessellator.addVertexWithUV(x, y + 16, 100.0, 0.0, 0.0625);
tessellator.addVertexWithUV(x + 16, y + 16, 100.0, 0.0625, 0.0625);
tessellator.addVertexWithUV(x + 16, y, 100.0, 0.0625, 0.0);
tessellator.addVertexWithUV(x, y, 100.0, 0.0, 0.0);
tessellator.draw();
}
}
@@ -13,7 +13,6 @@ public interface GuiIngameAccessor {
@Invoker
void callRenderPumpkinBlur(int width, int height);
// render portal
@Invoker
void callFunc_130015_b(float partialTicks, int width, int height);
@Invoker("func_130015_b")
void callRenderPortal(float partialTicks, int width, int height);
}
@@ -1,13 +1,14 @@
package com.gtnewhorizons.angelica.mixins.early.angelica.hudcaching;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import com.gtnewhorizons.angelica.hudcaching.HUDCaching;
import net.minecraft.client.gui.Gui;
import net.minecraftforge.client.GuiIngameForge;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(GuiIngameForge.class)
public class MixinGuiIngameForge_HUDCaching {
@@ -25,6 +26,7 @@ public class MixinGuiIngameForge_HUDCaching {
private void angelica$captureRenderCrosshair(CallbackInfo ci) {
if (HUDCaching.renderingCacheOverride) {
HUDCaching.renderCrosshairsCaptured = true;
HUDCaching.fixGLStateBeforeRenderingCache();
ci.cancel();
}
}