List of usage examples for org.lwjgl.opengl GL11 glBindTexture
public static void glBindTexture(@NativeType("GLenum") int target, @NativeType("GLuint") int texture)
From source file:org.terasology.rendering.opengl.FBO.java
License:Apache License
/** * Binds the color attachment to the currently active texture unit. * Once a texture is bound it can be sampled by shaders. *//*from ww w . j a va 2 s . c o m*/ public void bindTexture() { GL11.glBindTexture(GL11.GL_TEXTURE_2D, colorBufferTextureId); }
From source file:org.terasology.rendering.opengl.FBO.java
License:Apache License
/** * Binds the depth attachment to the currently active texture unit. * Once a texture is bound it can be sampled by shaders. *//*from ww w . ja v a 2s. co m*/ public void bindDepthTexture() { GL11.glBindTexture(GL11.GL_TEXTURE_2D, depthStencilTextureId); }
From source file:org.terasology.rendering.opengl.FBO.java
License:Apache License
/** * Binds the normals attachment to the currently active texture unit. * Once a texture is bound it can be sampled by shaders. *///from www. j a v a2 s.c om public void bindNormalsTexture() { GL11.glBindTexture(GL11.GL_TEXTURE_2D, normalsBufferTextureId); }
From source file:org.terasology.rendering.opengl.FBO.java
License:Apache License
/** * Binds the light buffer attachment to the currently active texture unit. * Once a texture is bound it can be sampled by shaders. */// w ww . j a v a 2 s .co m public void bindLightBufferTexture() { GL11.glBindTexture(GL11.GL_TEXTURE_2D, lightBufferTextureId); }
From source file:org.terasology.rendering.opengl.FBO.java
License:Apache License
/** * Unbinds the texture attached to the currently active texture unit. * Quirk: this also works if the texture to be unbound is -not- an attachment * of the calling instance's FrameBuffer. */// w w w.j a v a2 s . c o m public static void unbindTexture() { GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0); }
From source file:org.terasology.rendering.opengl.FBO.java
License:Apache License
/** * Creates an FBO, allocating the underlying FrameBuffer and the desired attachments on the GPU. * * Also checks the resulting FBO for completeness and logs errors and their error codes as necessary. * Callers must check the returned FBO's status (see getStatus()). Only FBO with a Status.COMPLETE should be used. * * In what follows, the GL constants between parenthesis represent the (internal format, data type, filtering type) of a buffer. * * An FBO of Type.DEFAULT will have a 32 bit color buffer attached to it. (GL_RGBA, GL11.GL_UNSIGNED_BYTE, GL_LINEAR) * An FBO of Type.HDR will have a 64 bit color buffer attached to it. (GL_RGBA, GL_HALF_FLOAT_ARB, GL_LINEAR) * An FBO of Type.NO_COLOR will have -no- color buffer attached to it. * * If the creation process is successful (Status.COMPLETE) GPU memory has been allocated for the FrameBuffer and * its attachments. However, the content of the attachments is undefined. * * @param urn An identification string. It is currently used only to log creation errors and is not stored in the FBO. * @param dimensions A Dimensions object wrapping width and height of the FBO. * @param type Can be Type.DEFAULT, Type.HDR or Type.NO_COLOR * @param useDepthBuffer If true the FBO will have a 24 bit depth buffer attached to it. (GL_DEPTH_COMPONENT24, GL_UNSIGNED_INT, GL_NEAREST) * @param useNormalBuffer If true the FBO will have a 32 bit normals buffer attached to it. (GL_RGBA, GL_UNSIGNED_BYTE, GL_LINEAR) * @param useLightBuffer If true the FBO will have 32/64 bit light buffer attached to it, depending if Type is DEFAULT/HDR. * (GL_RGBA/GL_RGBA16F_ARB, GL_UNSIGNED_BYTE/GL_HALF_FLOAT_ARB, GL_LINEAR) * @param useStencilBuffer If true the depth buffer will also have an 8 bit Stencil buffer associated with it. * (GL_DEPTH24_STENCIL8_EXT, GL_UNSIGNED_INT_24_8_EXT, GL_NEAREST) * @return The resuting FBO object wrapping a FrameBuffer and its attachments. Use getStatus() before use to verify completeness. *//*from w w w. j ava 2 s . co m*/ public static FBO create(ResourceUrn urn, Dimensions dimensions, Type type, boolean useDepthBuffer, boolean useNormalBuffer, boolean useLightBuffer, boolean useStencilBuffer) { FBO fbo = new FBO(dimensions.width, dimensions.height); // Create the FBO on the GPU fbo.fboId = glGenFramebuffersEXT(); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo.fboId); if (type != Type.NO_COLOR) { createColorBuffer(fbo, dimensions, type); } if (useNormalBuffer) { createNormalsBuffer(fbo, dimensions); } if (useLightBuffer) { createLightBuffer(fbo, dimensions, type); } if (useDepthBuffer) { createDepthBuffer(fbo, dimensions, useStencilBuffer); } GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0); IntBuffer bufferIds = BufferUtils.createIntBuffer(3); if (type != Type.NO_COLOR) { bufferIds.put(GL_COLOR_ATTACHMENT0_EXT); } if (useNormalBuffer) { bufferIds.put(GL_COLOR_ATTACHMENT1_EXT); } if (useLightBuffer) { bufferIds.put(GL_COLOR_ATTACHMENT2_EXT); } bufferIds.flip(); if (bufferIds.limit() == 0) { GL11.glReadBuffer(GL11.GL_NONE); GL20.glDrawBuffers(GL11.GL_NONE); } else { GL20.glDrawBuffers(bufferIds); } verifyCompleteness(urn, type, fbo); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); return fbo; }
From source file:org.terasology.rendering.opengl.FBO.java
License:Apache License
private static void createColorBuffer(FBO fbo, Dimensions dimensions, Type type) { fbo.colorBufferTextureId = glGenTextures(); GL11.glBindTexture(GL11.GL_TEXTURE_2D, fbo.colorBufferTextureId); setTextureParameters(GL11.GL_LINEAR); if (type == Type.HDR) { allocateTexture(dimensions, GL11.GL_RGBA, GL11.GL_RGBA, ARBHalfFloatPixel.GL_HALF_FLOAT_ARB); } else {//from www . j a v a 2 s .c om allocateTexture(dimensions, GL11.GL_RGBA, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE); } glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL11.GL_TEXTURE_2D, fbo.colorBufferTextureId, 0); }
From source file:org.terasology.rendering.opengl.FBO.java
License:Apache License
private static void createNormalsBuffer(FBO fbo, Dimensions dimensions) { fbo.normalsBufferTextureId = glGenTextures(); GL11.glBindTexture(GL11.GL_TEXTURE_2D, fbo.normalsBufferTextureId); setTextureParameters(GL11.GL_LINEAR); allocateTexture(dimensions, GL11.GL_RGBA, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE); glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT1_EXT, GL11.GL_TEXTURE_2D, fbo.normalsBufferTextureId, 0); }
From source file:org.terasology.rendering.opengl.FBO.java
License:Apache License
private static void createLightBuffer(FBO fbo, Dimensions dimensions, Type type) { fbo.lightBufferTextureId = glGenTextures(); GL11.glBindTexture(GL11.GL_TEXTURE_2D, fbo.lightBufferTextureId); setTextureParameters(GL11.GL_LINEAR); if (type == Type.HDR) { allocateTexture(dimensions, ARBTextureFloat.GL_RGBA16F_ARB, GL11.GL_RGBA, ARBHalfFloatPixel.GL_HALF_FLOAT_ARB); } else {/* w ww .j a v a2s . c o m*/ allocateTexture(dimensions, GL11.GL_RGBA, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE); } glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT2_EXT, GL11.GL_TEXTURE_2D, fbo.lightBufferTextureId, 0); }
From source file:org.terasology.rendering.opengl.FBO.java
License:Apache License
private static void createDepthBuffer(FBO fbo, Dimensions dimensions, boolean useStencilBuffer) { fbo.depthStencilTextureId = glGenTextures(); GL11.glBindTexture(GL11.GL_TEXTURE_2D, fbo.depthStencilTextureId); setTextureParameters(GL11.GL_NEAREST); if (!useStencilBuffer) { allocateTexture(dimensions, GL14.GL_DEPTH_COMPONENT24, GL11.GL_DEPTH_COMPONENT, GL11.GL_UNSIGNED_INT); } else {//w ww . j a va2s. c o m allocateTexture(dimensions, EXTPackedDepthStencil.GL_DEPTH24_STENCIL8_EXT, EXTPackedDepthStencil.GL_DEPTH_STENCIL_EXT, EXTPackedDepthStencil.GL_UNSIGNED_INT_24_8_EXT); } fbo.depthStencilRboId = glGenRenderbuffersEXT(); glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, fbo.depthStencilRboId); if (!useStencilBuffer) { glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL14.GL_DEPTH_COMPONENT24, fbo.dimensions.width, fbo.dimensions.height); } else { glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, EXTPackedDepthStencil.GL_DEPTH24_STENCIL8_EXT, fbo.dimensions.width, fbo.dimensions.height); } glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0); glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, fbo.depthStencilRboId); glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL11.GL_TEXTURE_2D, fbo.depthStencilTextureId, 0); if (useStencilBuffer) { glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT, GL11.GL_TEXTURE_2D, fbo.depthStencilTextureId, 0); } }