int _textureType;
protected static FBO_SUPPORT fboSupport = FBO_SUPPORT.USE_EXT_UNKNOWN;
public FBOParams(String fboName, int textureType, int internalFormat, int baseFormat, int bufferType, int fboWidth, int fboHeight ) throws Exception {
Minecraft mc = Minecraft.getMinecraft();
_textureType = textureType;
if (fboSupport == FBO_SUPPORT.USE_EXT_UNKNOWN)
{
// The framebuffer, which regroups 0, 1, or more textures, and 0 or 1 depth buffer.
try {
_frameBufferId = GL30.glGenFramebuffers();
fboSupport = FBO_SUPPORT.USE_GL30;
}
catch (IllegalStateException ex)
{
System.out.println("[Minecrift] FBO creation: GL30.glGenFramebuffers not supported. Attempting to use EXTFramebufferObject.glGenFramebuffersEXT");
fboSupport = FBO_SUPPORT.USE_EXT;
try {
_frameBufferId = EXTFramebufferObject.glGenFramebuffersEXT();
}
catch (IllegalStateException ex1)
{
System.out.println("[Minecrift] FBO creation: EXTFramebufferObject.glGenFramebuffersEXT not supported, FBO creation failed.");
throw ex1;
}
}
}
else if (fboSupport == FBO_SUPPORT.USE_GL30)
{
_frameBufferId = GL30.glGenFramebuffers();
}
else
{
_frameBufferId = EXTFramebufferObject.glGenFramebuffersEXT();
}
if (fboSupport == FBO_SUPPORT.USE_GL30)
{
_colorTextureId = GL11.glGenTextures();
_depthRenderBufferId = GL30.glGenRenderbuffers();
GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, _frameBufferId);
mc.checkGLError("FBO bind framebuffer");
GL11.glBindTexture(textureType, _colorTextureId);
mc.checkGLError("FBO bind texture");
GL11.glEnable(textureType);
GL11.glTexParameterf(textureType, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
GL11.glTexParameterf(textureType, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
GL11.glTexImage2D(textureType, 0, internalFormat, fboWidth, fboHeight, 0, baseFormat, bufferType, (java.nio.ByteBuffer) null);
System.out.println("[Minecrift] FBO '" + fboName + "': w: " + fboWidth + ", h: " + fboHeight);
GL30.glFramebufferTexture2D(GL30.GL_FRAMEBUFFER, GL30.GL_COLOR_ATTACHMENT0, textureType, _colorTextureId, 0);
mc.checkGLError("FBO bind texture framebuffer");
GL30.glBindRenderbuffer(GL30.GL_RENDERBUFFER, _depthRenderBufferId); // bind the depth renderbuffer
GL30.glRenderbufferStorage(GL30.GL_RENDERBUFFER, GL14.GL_DEPTH_COMPONENT24, fboWidth, fboHeight); // get the data space for it
GL30.glFramebufferRenderbuffer(GL30.GL_FRAMEBUFFER, GL30.GL_DEPTH_ATTACHMENT, GL30.GL_RENDERBUFFER, _depthRenderBufferId);
mc.checkGLError("FBO bind depth framebuffer");
}
else
{
_colorTextureId = GL11.glGenTextures();
_depthRenderBufferId = EXTFramebufferObject.glGenRenderbuffersEXT();
EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, _frameBufferId);
mc.checkGLError("FBO bind framebuffer");
GL11.glBindTexture(textureType, _colorTextureId);
mc.checkGLError("FBO bind texture");
GL11.glEnable(textureType);
GL11.glTexParameterf(textureType, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
GL11.glTexParameterf(textureType, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
GL11.glTexImage2D(textureType, 0, internalFormat, fboWidth, fboHeight, 0, baseFormat, bufferType, (java.nio.ByteBuffer) null);
System.out.println("[Minecrift] FBO '" + fboName + "': w: " + fboWidth + ", h: " + fboHeight);
EXTFramebufferObject.glFramebufferTexture2DEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, EXTFramebufferObject.GL_COLOR_ATTACHMENT0_EXT, textureType, _colorTextureId, 0);
mc.checkGLError("FBO bind texture framebuffer");
EXTFramebufferObject.glBindRenderbufferEXT(EXTFramebufferObject.GL_RENDERBUFFER_EXT, _depthRenderBufferId); // bind the depth renderbuffer
EXTFramebufferObject.glRenderbufferStorageEXT(EXTFramebufferObject.GL_RENDERBUFFER_EXT, GL14.GL_DEPTH_COMPONENT24, fboWidth, fboHeight); // get the data space for it
EXTFramebufferObject.glFramebufferRenderbufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, EXTFramebufferObject.GL_DEPTH_ATTACHMENT_EXT, EXTFramebufferObject.GL_RENDERBUFFER_EXT, _depthRenderBufferId);
mc.checkGLError("FBO bind depth framebuffer");
}
if (!checkFramebufferStatus())
{
// OK, if we have an error here - then throw an exception