From 71ceda155f340dcdd64aaa2b9607afcb40e4895f Mon Sep 17 00:00:00 2001 From: Victorious3 Date: Wed, 8 Apr 2015 00:22:42 +0200 Subject: [PATCH] Compatibility fix for the shaders mod, fixes #70 --- .../client/TileEntityAssemblerRenderer.java | 14 +++++++++++--- .../integratedcircuits/misc/RenderUtils.java | 18 ++++++++++++++++++ .../integratedcircuits/proxy/ClientProxy.java | 12 +++++++----- 3 files changed, 36 insertions(+), 8 deletions(-) diff --git a/src/main/java/vic/mod/integratedcircuits/client/TileEntityAssemblerRenderer.java b/src/main/java/vic/mod/integratedcircuits/client/TileEntityAssemblerRenderer.java index b1bdbf8..774da6c 100644 --- a/src/main/java/vic/mod/integratedcircuits/client/TileEntityAssemblerRenderer.java +++ b/src/main/java/vic/mod/integratedcircuits/client/TileEntityAssemblerRenderer.java @@ -4,7 +4,6 @@ import java.util.List; import java.util.Random; -import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.OpenGlHelper; import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.texture.TextureUtil; @@ -12,6 +11,7 @@ import net.minecraft.tileentity.TileEntity; import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL30; import vic.mod.integratedcircuits.DiskDrive; import vic.mod.integratedcircuits.DiskDrive.ModelFloppy; @@ -216,15 +216,18 @@ public void onRenderTick(TickEvent.RenderTickEvent event) { if(event.phase == Phase.START && schedule.size() > 0) { + int currentFBO = GL11.glGetInteger(GL30.GL_FRAMEBUFFER_BINDING); if(fbo == null) fbo = new Framebuffer(256, 256, false); - Minecraft.getMinecraft().getFramebuffer().unbindFramebuffer(); + fbo.unbindFramebuffer(); fbo.bindFramebuffer(false); GL11.glMatrixMode(GL11.GL_PROJECTION); + GL11.glPushMatrix(); GL11.glLoadIdentity(); GL11.glViewport(0, 0, 256, 256); GL11.glOrtho(0, 256, 256, 0, -1, 1); GL11.glMatrixMode(GL11.GL_MODELVIEW); + GL11.glPushMatrix(); GL11.glLoadIdentity(); GL11.glEnable(GL11.GL_BLEND); @@ -234,8 +237,13 @@ public void onRenderTick(TickEvent.RenderTickEvent event) updateFramebuffer(te); schedule.clear(); + GL11.glMatrixMode(GL11.GL_PROJECTION); + GL11.glPopMatrix(); + GL11.glMatrixMode(GL11.GL_MODELVIEW); + GL11.glPopMatrix(); + fbo.unbindFramebuffer(); - Minecraft.getMinecraft().getFramebuffer().bindFramebuffer(true); + OpenGlHelper.func_153171_g(OpenGlHelper.field_153198_e, currentFBO); } } diff --git a/src/main/java/vic/mod/integratedcircuits/misc/RenderUtils.java b/src/main/java/vic/mod/integratedcircuits/misc/RenderUtils.java index 133d039..d6e0dfb 100644 --- a/src/main/java/vic/mod/integratedcircuits/misc/RenderUtils.java +++ b/src/main/java/vic/mod/integratedcircuits/misc/RenderUtils.java @@ -6,9 +6,13 @@ import net.minecraft.client.renderer.OpenGlHelper; import net.minecraft.client.renderer.Tessellator; +import org.lwjgl.opengl.ARBFramebufferObject; +import org.lwjgl.opengl.EXTFramebufferObject; import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL30; import vic.mod.integratedcircuits.client.Resources; +import cpw.mods.fml.relauncher.ReflectionHelper; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -132,6 +136,20 @@ public static String cutStringToSize(FontRenderer fr, String str, int width) return str; } + public static int glGetFramebufferAttachmentParameteri(int target, int attachment, int pname) + { + if(OpenGlHelper.framebufferSupported) + { + int fboType = ReflectionHelper.getPrivateValue(OpenGlHelper.class, null, "field_153212_w"); + switch(fboType) { + case 0: return GL30.glGetFramebufferAttachmentParameteri(target, attachment, pname); + case 1: return ARBFramebufferObject.glGetFramebufferAttachmentParameteri(target, attachment, pname); + case 2: return EXTFramebufferObject.glGetFramebufferAttachmentParameteriEXT(target, attachment, pname); + } + } + return 0; + } + private static float lightX, lightY; public static void setBrightness(float lightX, float lightY) diff --git a/src/main/java/vic/mod/integratedcircuits/proxy/ClientProxy.java b/src/main/java/vic/mod/integratedcircuits/proxy/ClientProxy.java index aa1bbde..16ed6cf 100644 --- a/src/main/java/vic/mod/integratedcircuits/proxy/ClientProxy.java +++ b/src/main/java/vic/mod/integratedcircuits/proxy/ClientProxy.java @@ -44,6 +44,7 @@ import org.lwjgl.opengl.ARBShaderObjects; import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL30; import vic.mod.integratedcircuits.Constants; import vic.mod.integratedcircuits.DiskDrive; @@ -224,7 +225,8 @@ public void renderPlayer(float partial, RenderGlobal context) // Cirno try { Minecraft mc = Minecraft.getMinecraft(); - Framebuffer mcfbo = mc.getFramebuffer(); + int currentFBO = GL11.glGetInteger(GL30.GL_FRAMEBUFFER_BINDING); + int currentTexture = RenderUtils.glGetFramebufferAttachmentParameteri(GL30.GL_FRAMEBUFFER, GL30.GL_COLOR_ATTACHMENT0, GL30.GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME); if(OpenGlHelper.isFramebufferEnabled() && shaders && ShaderHelper.SHADER_BLUR != 0) { @@ -238,7 +240,7 @@ public void renderPlayer(float partial, RenderGlobal context) fbo2.setFramebufferColor(0, 0, 0, 1); fbo2.createBindFramebuffer(mc.displayWidth, mc.displayHeight); fbo2.unbindFramebuffer(); - mcfbo.bindFramebuffer(false); + OpenGlHelper.func_153171_g(OpenGlHelper.field_153198_e, currentFBO); } else if(mc.displayWidth != fbo.framebufferWidth || mc.displayHeight != fbo.framebufferHeight) { @@ -246,7 +248,7 @@ else if(mc.displayWidth != fbo.framebufferWidth || mc.displayHeight != fbo.frame fbo.unbindFramebuffer(); fbo2.createBindFramebuffer(mc.displayWidth, mc.displayHeight); fbo2.unbindFramebuffer(); - mcfbo.bindFramebuffer(false); + OpenGlHelper.func_153171_g(OpenGlHelper.field_153198_e, currentFBO); } OpenGlHelper.func_153188_a(OpenGlHelper.field_153198_e, OpenGlHelper.field_153200_g, 3553, fbo.framebufferTexture, 0); @@ -416,7 +418,7 @@ else if(enumaction == EnumAction.bow) GL11.glEnable(GL11.GL_TEXTURE_2D); - OpenGlHelper.func_153188_a(OpenGlHelper.field_153198_e, OpenGlHelper.field_153200_g, 3553, mcfbo.framebufferTexture, 0); + OpenGlHelper.func_153188_a(OpenGlHelper.field_153198_e, OpenGlHelper.field_153200_g, 3553, currentTexture, 0); if(OpenGlHelper.isFramebufferEnabled() && shaders && ShaderHelper.SHADER_BLUR != 0 && found) { @@ -450,7 +452,7 @@ else if(enumaction == EnumAction.bow) ShaderHelper.releaseShader(); fbo.framebufferClear(); - mcfbo.bindFramebuffer(false); + OpenGlHelper.func_153171_g(OpenGlHelper.field_153198_e, currentFBO); fbo2.bindFramebufferTexture(); GL11.glShadeModel(GL11.GL_SMOOTH);