diff --git a/src/main/java/com/gtnewhorizons/angelica/hudcaching/HUDCaching.java b/src/main/java/com/gtnewhorizons/angelica/hudcaching/HUDCaching.java index 42061749e..23463c839 100644 --- a/src/main/java/com/gtnewhorizons/angelica/hudcaching/HUDCaching.java +++ b/src/main/java/com/gtnewhorizons/angelica/hudcaching/HUDCaching.java @@ -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(); - } - } diff --git a/src/main/java/com/gtnewhorizons/angelica/mixins/early/angelica/hudcaching/GuiIngameAccessor.java b/src/main/java/com/gtnewhorizons/angelica/mixins/early/angelica/hudcaching/GuiIngameAccessor.java index 4240d8b53..959e9b132 100644 --- a/src/main/java/com/gtnewhorizons/angelica/mixins/early/angelica/hudcaching/GuiIngameAccessor.java +++ b/src/main/java/com/gtnewhorizons/angelica/mixins/early/angelica/hudcaching/GuiIngameAccessor.java @@ -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); } diff --git a/src/main/java/com/gtnewhorizons/angelica/mixins/early/angelica/hudcaching/MixinGuiIngameForge_HUDCaching.java b/src/main/java/com/gtnewhorizons/angelica/mixins/early/angelica/hudcaching/MixinGuiIngameForge_HUDCaching.java index 7298024b1..8180b8f28 100644 --- a/src/main/java/com/gtnewhorizons/angelica/mixins/early/angelica/hudcaching/MixinGuiIngameForge_HUDCaching.java +++ b/src/main/java/com/gtnewhorizons/angelica/mixins/early/angelica/hudcaching/MixinGuiIngameForge_HUDCaching.java @@ -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(); } } diff --git a/src/main/java/net/coderbot/iris/pipeline/HandRenderer.java b/src/main/java/net/coderbot/iris/pipeline/HandRenderer.java index 28b100b7c..22a320545 100644 --- a/src/main/java/net/coderbot/iris/pipeline/HandRenderer.java +++ b/src/main/java/net/coderbot/iris/pipeline/HandRenderer.java @@ -10,6 +10,8 @@ import net.minecraft.entity.EntityLiving; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemBlock; +import net.minecraft.item.ItemStack; + import org.joml.Matrix4f; public class HandRenderer { @@ -58,7 +60,11 @@ public class HandRenderer { public boolean isHandTranslucent(InteractionHand hand) { // TODO: Offhand // Item item = Minecraft.getMinecraft().thePlayer.getItemBySlot(hand == InteractionHand.OFF_HAND ? EquipmentSlot.OFFHAND : EquipmentSlot.MAINHAND).getItem(); - Item item = Minecraft.getMinecraft().thePlayer.getHeldItem().getItem(); + ItemStack heldItem = Minecraft.getMinecraft().thePlayer.getHeldItem(); + if (heldItem == null) { + return false; + } + Item item = heldItem.getItem(); if (item instanceof ItemBlock itemBlock) { // TODO: RenderType