Skip to content

Commit

Permalink
Compatibility fix for the shaders mod, fixes #70
Browse files Browse the repository at this point in the history
  • Loading branch information
Victorious3 committed Apr 7, 2015
1 parent 97fabf1 commit 71ceda1
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
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;
import net.minecraft.client.shader.Framebuffer;
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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}
}

Expand Down
18 changes: 18 additions & 0 deletions src/main/java/vic/mod/integratedcircuits/misc/RenderUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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)
Expand Down
12 changes: 7 additions & 5 deletions src/main/java/vic/mod/integratedcircuits/proxy/ClientProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{
Expand All @@ -238,15 +240,15 @@ 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)
{
fbo.createBindFramebuffer(mc.displayWidth, mc.displayHeight);
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);
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 71ceda1

Please sign in to comment.