List of usage examples for org.lwjgl.opengl EXTFramebufferObject glFramebufferTexture2DEXT
public static native void glFramebufferTexture2DEXT(@NativeType("GLenum") int target, @NativeType("GLenum") int attachment, @NativeType("GLenum") int textarget, @NativeType("GLuint") int texture, @NativeType("GLint") int level);
From source file:a1.gui.GUI_Map.java
License:Open Source License
public void CreateLightMap() { //Coord screen_size = new Coord(Config.getScreenWidth(), Config.getScreenHeight()); //Coord screen_coord = new Coord(GUI.map.mc).sub(screen_size.div(2)); List<Coord> lst = new ArrayList<Coord>(); for (RenderPart p : render_parts) { Drawable d = p.owner.getattr(Drawable.class); if (d != null) { if (d.name.contains("fir")) { lst.add(p.dc);//w w w .ja v a2 s. co m } if (d.name.contains("player")) { lst.add(p.dc); } } } // for (Obj o : ObjCache.objs.values()) { // Drawable d = o.getattr(Drawable.class); // if (d != null) { // if (d.name.contains("tree")) { // if (o.getpos().in_rect(screen_coord, screen_size)) // lst.add(o.getpos()); // } // } // } if (first) { first = false; boolean FBOEnabled = GLContext.getCapabilities().GL_EXT_framebuffer_object; if (!FBOEnabled) Log.info("No FBO"); myFBOId = EXTFramebufferObject.glGenFramebuffersEXT(); //LightMap = GL11.glGenTextures(); EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, myFBOId); EXTFramebufferObject.glFramebufferTexture2DEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, EXTFramebufferObject.GL_COLOR_ATTACHMENT0_EXT, GL11.GL_TEXTURE_2D, LightMap, 0); EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, 0); } //ByteBuffer bb = ByteBuffer.allocate(1024 * 1024 * 4); //GL11.glReadPixels(0, 0, 1024, 768, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, bb); // ? FBO ? ? EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, myFBOId); // GL11.glPushAttrib(GL11.GL_VIEWPORT_BIT); // ? // GL11.glViewport( 0, 0, 1024, 1024 ); // // ? // ? GL11.glEnable(GL11.GL_TEXTURE_2D); GL11.glClearColor(0.3f, 0.3f, 0.4f, 1.0f); GL11.glClear(GL_COLOR_BUFFER_BIT); GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE); // ? ? ? for (Coord c : lst) DrawLight(c, 100, 100); /*GL11.glTranslatef(0, 0, -6f); GL11.glBegin(GL11.GL_QUADS); GL11.glVertex3f(0, 0, 0); GL11.glVertex3f(200, 0, 0); GL11.glVertex3f(200, 200, 0); GL11.glVertex3f(0, 200, 0); GL11.glEnd();*/ // GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, 0); // GL11.glPopAttrib(); // GL11.glClear(GL11.GL_COLOR_BUFFER_BIT); // // //GL11.glBindTexture(GL11.GL_TEXTURE_2D, LightMap); //Render2D.CheckError(); // ? - ? //GL11.glCopyTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA8, 0, 0, 1024, 1024, 0); //GL11.glCopyTexSubImage2D(GL11.GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1024, 1024); //Render2D.CheckError(); GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); }
From source file:com.ardor3d.renderer.lwjgl.LwjglTextureRenderer.java
License:Open Source License
private void render(final List<? extends Spatial> toDrawA, final Spatial toDrawB, final Scene toDrawC, final List<Texture> texs, final int clear) { final int maxDrawBuffers = ContextManager.getCurrentContext().getCapabilities().getMaxFBOColorAttachments(); // if we only support 1 draw buffer at a time anyway, we'll have to render to each texture individually... if (maxDrawBuffers == 1 || texs.size() == 1) { try {/*from w w w . j a v a 2 s.co m*/ ContextManager.getCurrentContext().pushFBOTextureRenderer(this); for (int i = 0; i < texs.size(); i++) { final Texture tex = texs.get(i); setupForSingleTexDraw(tex); if (_samples > 0 && _supportsMultisample) { setMSFBO(); } switchCameraIn(clear); if (toDrawA != null) { doDraw(toDrawA); } else if (toDrawB != null) { doDraw(toDrawB); } else { doDraw(toDrawC); } switchCameraOut(); if (_samples > 0 && _supportsMultisample) { blitMSFBO(); } takedownForSingleTexDraw(tex); } } finally { ContextManager.getCurrentContext().popFBOTextureRenderer(); } return; } try { ContextManager.getCurrentContext().pushFBOTextureRenderer(this); // Otherwise, we can streamline this by rendering to multiple textures at once. // first determine how many groups we need final LinkedList<Texture> depths = new LinkedList<Texture>(); final LinkedList<Texture> colors = new LinkedList<Texture>(); for (int i = 0; i < texs.size(); i++) { final Texture tex = texs.get(i); if (tex.getTextureStoreFormat().isDepthFormat()) { depths.add(tex); } else { colors.add(tex); } } // we can only render to 1 depth texture at a time, so # groups is at minimum == numDepth final int groups = Math.max(depths.size(), (int) Math.ceil(colors.size() / (float) maxDrawBuffers)); final RenderContext context = ContextManager.getCurrentContext(); for (int i = 0; i < groups; i++) { // First handle colors int colorsAdded = 0; while (colorsAdded < maxDrawBuffers && !colors.isEmpty()) { final Texture tex = colors.removeFirst(); if (tex.getType() == Type.TwoDimensional) { EXTFramebufferObject.glFramebufferTexture2DEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, EXTFramebufferObject.GL_COLOR_ATTACHMENT0_EXT + colorsAdded, GL11.GL_TEXTURE_2D, tex.getTextureIdForContext(context.getGlContextRep()), 0); } else if (tex.getType() == Type.CubeMap) { EXTFramebufferObject.glFramebufferTexture2DEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, EXTFramebufferObject.GL_COLOR_ATTACHMENT0_EXT + colorsAdded, LwjglTextureStateUtil.getGLCubeMapFace(((TextureCubeMap) tex).getCurrentRTTFace()), tex.getTextureIdForContext(context.getGlContextRep()), 0); } else { throw new IllegalArgumentException("Invalid texture type: " + tex.getType()); } colorsAdded++; } // Now take care of depth. if (!depths.isEmpty()) { final Texture tex = depths.removeFirst(); // Set up our depth texture if (tex.getType() == Type.TwoDimensional) { EXTFramebufferObject.glFramebufferTexture2DEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, EXTFramebufferObject.GL_DEPTH_ATTACHMENT_EXT, GL11.GL_TEXTURE_2D, tex.getTextureIdForContext(context.getGlContextRep()), 0); } else if (tex.getType() == Type.CubeMap) { EXTFramebufferObject.glFramebufferTexture2DEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, EXTFramebufferObject.GL_DEPTH_ATTACHMENT_EXT, LwjglTextureStateUtil.getGLCubeMapFace(((TextureCubeMap) tex).getCurrentRTTFace()), tex.getTextureIdForContext(context.getGlContextRep()), 0); } else { throw new IllegalArgumentException("Invalid texture type: " + tex.getType()); } _usingDepthRB = false; } else if (!_usingDepthRB) { // setup our default depth render buffer if not already set EXTFramebufferObject.glFramebufferRenderbufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, EXTFramebufferObject.GL_DEPTH_ATTACHMENT_EXT, EXTFramebufferObject.GL_RENDERBUFFER_EXT, _depthRBID); _usingDepthRB = true; } setDrawBuffers(colorsAdded); setReadBuffer(colorsAdded != 0 ? EXTFramebufferObject.GL_COLOR_ATTACHMENT0_EXT : GL11.GL_NONE); // Check FBO complete checkFBOComplete(_fboID); switchCameraIn(clear); if (toDrawA != null) { doDraw(toDrawA); } else { doDraw(toDrawB); } switchCameraOut(); } // automatically generate mipmaps for our textures. for (int x = 0, max = texs.size(); x < max; x++) { if (texs.get(x).getMinificationFilter().usesMipMapLevels()) { final Texture tex = texs.get(x); if (tex.getMinificationFilter().usesMipMapLevels()) { LwjglTextureStateUtil.doTextureBind(texs.get(x), 0, true); EXTFramebufferObject.glGenerateMipmapEXT(LwjglTextureStateUtil.getGLType(tex.getType())); } } } } finally { ContextManager.getCurrentContext().popFBOTextureRenderer(); } }
From source file:com.ardor3d.renderer.lwjgl.LwjglTextureRenderer.java
License:Open Source License
@Override protected void setupForSingleTexDraw(final Texture tex) { final RenderContext context = ContextManager.getCurrentContext(); final int textureId = tex.getTextureIdForContext(context.getGlContextRep()); if (tex.getTextureStoreFormat().isDepthFormat()) { // No color buffer EXTFramebufferObject.glFramebufferRenderbufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, EXTFramebufferObject.GL_COLOR_ATTACHMENT0_EXT, EXTFramebufferObject.GL_RENDERBUFFER_EXT, 0); // Setup depth texture into FBO if (tex.getType() == Type.TwoDimensional) { EXTFramebufferObject.glFramebufferTexture2DEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, EXTFramebufferObject.GL_DEPTH_ATTACHMENT_EXT, GL11.GL_TEXTURE_2D, textureId, 0); } else if (tex.getType() == Type.CubeMap) { EXTFramebufferObject.glFramebufferTexture2DEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, EXTFramebufferObject.GL_DEPTH_ATTACHMENT_EXT, LwjglTextureStateUtil.getGLCubeMapFace(((TextureCubeMap) tex).getCurrentRTTFace()), textureId, 0);/*from w ww.ja v a2 s . c o m*/ } else { throw new IllegalArgumentException("Can not render to texture of type: " + tex.getType()); } setDrawBuffer(GL11.GL_NONE); setReadBuffer(GL11.GL_NONE); } else { // Set color texture into FBO if (tex.getType() == Type.TwoDimensional) { EXTFramebufferObject.glFramebufferTexture2DEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, EXTFramebufferObject.GL_COLOR_ATTACHMENT0_EXT, GL11.GL_TEXTURE_2D, textureId, 0); } else if (tex.getType() == Type.CubeMap) { EXTFramebufferObject.glFramebufferTexture2DEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, EXTFramebufferObject.GL_COLOR_ATTACHMENT0_EXT, LwjglTextureStateUtil.getGLCubeMapFace(((TextureCubeMap) tex).getCurrentRTTFace()), textureId, 0); } else { throw new IllegalArgumentException("Can not render to texture of type: " + tex.getType()); } // setup depth RB EXTFramebufferObject.glFramebufferRenderbufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, EXTFramebufferObject.GL_DEPTH_ATTACHMENT_EXT, EXTFramebufferObject.GL_RENDERBUFFER_EXT, _depthRBID); setDrawBuffer(EXTFramebufferObject.GL_COLOR_ATTACHMENT0_EXT); setReadBuffer(EXTFramebufferObject.GL_COLOR_ATTACHMENT0_EXT); } // Check FBO complete checkFBOComplete(_fboID); }
From source file:com.badlogic.gdx.backends.jglfw.JglfwGL20.java
License:Apache License
public void glFramebufferTexture2D(int target, int attachment, int textarget, int texture, int level) { EXTFramebufferObject.glFramebufferTexture2DEXT(target, attachment, textarget, texture, level); }
From source file:com.flowpowered.caustic.lwjgl.gl20.GL20FrameBuffer.java
License:MIT License
@Override public void attach(AttachmentPoint point, Texture texture) { checkCreated();//from w ww . jav a2s. co m texture.checkCreated(); CausticUtil.checkVersion(this, texture); // Bind the frame buffer EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, id); // Attach the texture EXTFramebufferObject.glFramebufferTexture2DEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, point.getGLConstant(), GL11.GL_TEXTURE_2D, texture.getID(), 0); // Add it to the color outputs if it's a color type if (point.isColor()) { outputBuffers.add(point.getGLConstant()); } // Update the list of output buffers updateOutputBuffers(); // Unbind the frame buffer EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, 0); // Check for errors LWJGLUtil.checkForGLError(); }
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;/*w w w. ja v a2 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); 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.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;//w w w. j a 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); 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:flash.display.BitmapData.java
License:Open Source License
public void applyFilter(final BitmapData sourceBitmapData, final Rectangle sourceRect, final Point destPoint, final BitmapFilter filter) { final int textureId = JITB$textureId(); ////from w w w.j av a 2 s. c om // If this == sourceBitmapData we have to create a temporary buffer // as an input since we directly render to this BitmapData. // // Another case is when the filter is a ShaderFilter and it expects // an input which is also set to this. // final int bufferTextureId; //TODO this can be done in VRAM only bufferTextureId = glGenTextures(); final ByteBuffer buffer = BufferUtils.createByteBuffer(width() * height() * 4); buffer.limit(buffer.capacity()); glBindTexture(TextureUtil.mode(), bufferTextureId); glTexParameteri(TextureUtil.mode(), GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(TextureUtil.mode(), GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexImage2D(TextureUtil.mode(), 0, GL_RGBA, width(), height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer); // // Create and bind FBO // final int fboId = EXTFramebufferObject.glGenFramebuffersEXT(); EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, fboId); // // Attach the current BitmapData as a texture to render to. EXTFramebufferObject.glFramebufferTexture2DEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, EXTFramebufferObject.GL_COLOR_ATTACHMENT0_EXT, TextureUtil.mode(), -1 == bufferTextureId ? textureId : bufferTextureId, 0); // // Check the health of our FBO // final int status = EXTFramebufferObject .glCheckFramebufferStatusEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT); if (status != EXTFramebufferObject.GL_FRAMEBUFFER_COMPLETE_EXT) { throw new RuntimeException("Could not setup FBO."); } // // Start using FBO // EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, fboId); glPushAttrib(GL_VIEWPORT_BIT); glViewport(0, 0, width(), height()); // // Bind the source BitmapData as an input for the filter. // if (!rect().equals(sourceBitmapData.rect()) || !ORIGIN.equals(destPoint)) { glBindTexture(TextureUtil.mode(), JITB$textureId()); rect().JITB$render(false); } glPushMatrix(); glTranslated(destPoint.x, destPoint.y, 0.0); glBindTexture(TextureUtil.mode(), sourceBitmapData.JITB$textureId()); // // Now run the filter with the given texture. // if (filter instanceof ShaderFilter) { ShaderFilter shaderFilter = ((ShaderFilter) filter); if (null != shaderFilter.shader()) { final ShaderInput[] inputs = shaderFilter.shader().data().JITB$inputs(); if (inputs.length > 0) { inputs[0].input(this); } shaderFilter.shader().JITB$bind(0.0, 0.0, width(), height(), false); } sourceRect.JITB$render(false); if (null != shaderFilter.shader()) { shaderFilter.shader().JITB$unbind(); } } glPopMatrix(); // // Note: We can defer this step to the next _buffer access. // _buffer.clear(); glReadPixels(0, 0, width(), height(), GL_RGBA, GL_UNSIGNED_BYTE, _buffer); _invalidated = -1 != bufferTextureId; // // Cleanup // glBindTexture(TextureUtil.mode(), 0); glPopAttrib(); EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, 0); EXTFramebufferObject.glDeleteFramebuffersEXT(fboId); if (-1 != bufferTextureId) { // // Exchange old texture for buffer. // glDeleteTextures(_textureId); _textureId = bufferTextureId; } }
From source file:io.root.gfx.glutils.GL.java
License:Apache License
public static void glFramebufferTexture2D(int target, int attachment, int textarget, int texture, int level) { EXTFramebufferObject.glFramebufferTexture2DEXT(target, attachment, textarget, texture, level); }
From source file:itdelatrisu.opsu.render.Rendertarget.java
License:Open Source License
/** * Creates a Rendertarget with a Texture that it renders the color buffer in * and a renderbuffer that it renders the depth to. * @param width the width/*from ww w . ja v a 2 s . c om*/ * @param height the height */ public static Rendertarget createRTTFramebuffer(int width, int height) { int old_framebuffer = GL11.glGetInteger(EXTFramebufferObject.GL_FRAMEBUFFER_BINDING_EXT); int old_texture = GL11.glGetInteger(GL11.GL_TEXTURE_BINDING_2D); Rendertarget buffer = new Rendertarget(width, height); buffer.bind(); int fboTexture = buffer.textureID; GL11.glBindTexture(GL11.GL_TEXTURE_2D, fboTexture); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, 4, width, height, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_INT, (ByteBuffer) null); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); EXTFramebufferObject.glBindRenderbufferEXT(EXTFramebufferObject.GL_RENDERBUFFER_EXT, buffer.depthBufferID); EXTFramebufferObject.glRenderbufferStorageEXT(EXTFramebufferObject.GL_RENDERBUFFER_EXT, GL11.GL_DEPTH_COMPONENT, width, height); EXTFramebufferObject.glFramebufferRenderbufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, EXTFramebufferObject.GL_DEPTH_ATTACHMENT_EXT, EXTFramebufferObject.GL_RENDERBUFFER_EXT, buffer.depthBufferID); EXTFramebufferObject.glFramebufferTexture2DEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, EXTFramebufferObject.GL_COLOR_ATTACHMENT0_EXT, GL11.GL_TEXTURE_2D, fboTexture, 0); GL11.glBindTexture(GL11.GL_TEXTURE_2D, old_texture); EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, old_framebuffer); return buffer; }