List of usage examples for org.lwjgl.opengl GL30 glBindFramebuffer
public static void glBindFramebuffer(@NativeType("GLenum") int target, @NativeType("GLuint") int framebuffer)
From source file:com.microsoft.Malmo.MissionHandlers.VideoProducerImplementation.java
License:Open Source License
@Override public void getFrame(MissionInit missionInit, ByteBuffer buffer) { if (!this.videoParams.isWantDepth()) { getRGBFrame(buffer); // Just return the simple RGB, 3bpp image. return;//from w w w.ja va 2 s.co m } // Otherwise, do the work of extracting the depth map: final int width = this.videoParams.getWidth(); final int height = this.videoParams.getHeight(); GL30.glBindFramebuffer(GL30.GL_READ_FRAMEBUFFER, Minecraft.getMinecraft().getFramebuffer().framebufferObject); GL30.glBindFramebuffer(GL30.GL_DRAW_FRAMEBUFFER, this.fbo.framebufferObject); GL30.glBlitFramebuffer(0, 0, Minecraft.getMinecraft().getFramebuffer().framebufferWidth, Minecraft.getMinecraft().getFramebuffer().framebufferHeight, 0, 0, width, height, GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT, GL11.GL_NEAREST); this.fbo.bindFramebuffer(true); glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, buffer); glReadPixels(0, 0, width, height, GL_DEPTH_COMPONENT, GL_FLOAT, this.depthBuffer); this.fbo.unbindFramebuffer(); // Now convert the depth buffer into values from 0-255 and copy it over the alpha channel. // We either use the min and max values supplied in order to scale it, or we scale it according // to the dynamic content: float minval, maxval; // The scaling section is optional (since the depthmap is optional) - so if there is no depthScaling object, // go with the default of autoscale. if (this.videoParams.getDepthScaling() == null || this.videoParams.getDepthScaling().isAutoscale()) { minval = 1; maxval = 0; for (int i = 0; i < width * height; i++) { float f = this.depthBuffer.get(i); if (f < minval) minval = f; if (f > maxval) maxval = f; } } else { minval = this.videoParams.getDepthScaling().getMin().floatValue(); maxval = this.videoParams.getDepthScaling().getMax().floatValue(); if (minval > maxval) { // You can't trust users. float t = minval; minval = maxval; maxval = t; } } float range = maxval - minval; if (range < 0.000001) range = 0.000001f; // To avoid divide by zero errors in cases where there is no depth variance float scale = 255 / range; for (int i = 0; i < width * height; i++) { float f = this.depthBuffer.get(i); f = (f < minval ? minval : (f > maxval ? maxval : f)); f -= minval; f *= scale; buffer.put(i * 4 + 3, (byte) f); } // Reset depth buffer ready for next read: this.depthBuffer.clear(); }
From source file:com.mtbs3d.minecrift.FBOParams.java
License:LGPL
public FBOParams(String fboName, int textureType, int internalFormat, int baseFormat, int bufferType, int fboWidth, int fboHeight) throws Exception { Minecraft mc = Minecraft.getMinecraft(); _textureType = textureType;//from ww w . ja va 2s . c o m 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); checkGLError("FBO bind framebuffer"); GL11.glBindTexture(textureType, _colorTextureId); 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); 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); checkGLError("FBO bind depth framebuffer"); } else { _colorTextureId = GL11.glGenTextures(); _depthRenderBufferId = EXTFramebufferObject.glGenRenderbuffersEXT(); EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, _frameBufferId); checkGLError("FBO bind framebuffer"); GL11.glBindTexture(textureType, _colorTextureId); 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); 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); checkGLError("FBO bind depth framebuffer"); } if (!checkFramebufferStatus()) { // OK, if we have an error here - then throw an exception System.out.println("[Minecrift] FAILED to create framebuffer!!"); throw new Exception("Failed to create framebuffer"); } }
From source file:com.mtbs3d.minecrift.FBOParams.java
License:LGPL
public void bindRenderTarget() { if (fboSupport == FBO_SUPPORT.USE_GL30) GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, _frameBufferId); else/*from www . j ava 2 s . co m*/ EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, _frameBufferId); }
From source file:com.mtbs3d.minecrift.render.FBOParams.java
License:LGPL
public FBOParams(String fboName, int textureType, int internalFormat, int baseFormat, int bufferType, int fboWidth, int fboHeight) throws Exception { Minecraft mc = Minecraft.getMinecraft(); _textureType = textureType;/*from w w w . j av a 2 s. c o m*/ 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 System.out.println("[Minecrift] FAILED to create framebuffer!!"); throw new Exception("Failed to create framebuffer"); } }
From source file:com.mtbs3d.minecrift.VRRenderer.java
License:LGPL
private void unbindFBORenderTarget() { try {//from w w w . j a va 2s . c om GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, 0); } catch (IllegalStateException ex) { EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, 0); } }
From source file:com.opengrave.og.light.Depth2DFramebuffer.java
License:Open Source License
public Depth2DFramebuffer(int size) { framebufferSize = size;/*from ww w . ja va 2s .co m*/ framebuffer = GL30.glGenFramebuffers(); GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, framebuffer); shadowMap = new Texture2DShadowMap(framebufferSize); shadowMap.bindToFrameBuffer(); // GL11.glDrawBuffer(GL30.GL_COLOR_ATTACHMENT0); GL11.glDrawBuffer(GL11.GL_NONE); Util.checkErr(); GL11.glReadBuffer(GL11.GL_NONE); int i = GL30.glCheckFramebufferStatus(GL30.GL_FRAMEBUFFER); if (i != GL30.GL_FRAMEBUFFER_COMPLETE) { throw new RuntimeException("Framebuffer creation failed with code: " + i); } GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, 0); // TESTING STUFF count = 2; FloatBuffer pos = BufferUtils.createFloatBuffer(3 * 3 * count); FloatBuffer tex = BufferUtils.createFloatBuffer(2 * 3 * count); pos.put(0.75f).put(0.75f).put(0f); pos.put(0.75f).put(0.25f).put(0f); pos.put(0.25f).put(0.75f).put(0f); pos.put(0.25f).put(0.25f).put(0f); pos.put(0.75f).put(0.25f).put(0f); pos.put(0.25f).put(0.75f).put(0f); pos.flip(); tex.put(1f).put(1f); tex.put(1f).put(0f); tex.put(0f).put(1f); tex.put(0f).put(0f); tex.put(1f).put(0f); tex.put(0f).put(1f); tex.flip(); vao_ID = GL30.glGenVertexArrays(); GL30.glBindVertexArray(vao_ID); int vbo_pos_ID = GL15.glGenBuffers(); int vbo_tex_ID = GL15.glGenBuffers(); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo_pos_ID); GL15.glBufferData(GL15.GL_ARRAY_BUFFER, pos, GL15.GL_STATIC_DRAW); GL20.glVertexAttribPointer(0, 3, GL11.GL_FLOAT, false, 0, 0); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo_tex_ID); GL15.glBufferData(GL15.GL_ARRAY_BUFFER, tex, GL15.GL_STATIC_DRAW); GL20.glVertexAttribPointer(1, 2, GL11.GL_FLOAT, false, 0, 0); }
From source file:com.opengrave.og.light.Depth2DFramebuffer.java
License:Open Source License
@Override public void bindDraw() { Util.checkErr();//from w w w . j a va2 s . c o m for (int i = GL13.GL_TEXTURE0; i < GL13.GL_TEXTURE31; i++) { GL13.glActiveTexture(i); GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0); GL11.glBindTexture(GL30.GL_TEXTURE_2D_ARRAY, 0); GL11.glBindTexture(GL13.GL_TEXTURE_CUBE_MAP, 0); } Util.checkErr(); GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, framebuffer); Util.checkErr(); GL11.glDisable(GL11.GL_BLEND); Util.checkErr(); GL11.glEnable(GL11.GL_DEPTH_TEST); GL11.glDepthFunc(GL11.GL_LESS); GL11.glDepthMask(true); Util.checkErr(); GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT); Util.checkErr(); GL11.glViewport(0, 0, framebufferSize, framebufferSize); }
From source file:com.opengrave.og.light.Depth2DFramebuffer.java
License:Open Source License
@Override public void unbindDraw() { GL11.glFlush(); GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, 0); }
From source file:com.opengrave.og.light.DepthCubeFramebuffer.java
License:Open Source License
public DepthCubeFramebuffer(int size) { framebufferSize = size;/*from w w w . ja va 2 s.com*/ framebuffer = GL30.glGenFramebuffers(); // System.out.println("Creating Pointlight Framebuffer : " + // framebuffer); GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, framebuffer); shadowMap = new TextureCubeShadowMap(framebufferSize); // shadowMap.bindToFrameBuffer(); shadowMap.bindToFrameBuffer(0); // GL11.glDrawBuffer(GL30.GL_COLOR_ATTACHMENT0); GL11.glDrawBuffer(GL11.GL_NONE); Util.checkErr(); GL11.glReadBuffer(GL11.GL_NONE); int i = GL30.glCheckFramebufferStatus(GL30.GL_FRAMEBUFFER); if (i != GL30.GL_FRAMEBUFFER_COMPLETE) { throw new RuntimeException("Framebuffer creation failed with code: " + i); } GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, 0); Util.checkErr(); }
From source file:com.opengrave.og.light.DepthCubeFramebuffer.java
License:Open Source License
public void bindDraw(int direction) { Util.checkErr();//from w ww.j a va2s .co m GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, framebuffer); shadowMap.bindToFrameBuffer(direction); Util.checkErr(); Util.checkErr(); GL11.glDisable(GL11.GL_BLEND); Util.checkErr(); GL11.glEnable(GL11.GL_DEPTH_TEST); GL11.glDepthFunc(GL11.GL_LESS); GL11.glDepthMask(true); Util.checkErr(); GL11.glClear(GL11.GL_DEPTH_BUFFER_BIT); Util.checkErr(); GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT); GL11.glViewport(0, 0, framebufferSize, framebufferSize); }