Java Code Examples for org.lwjgl.opengl.GL30#glBindFramebuffer()

The following examples show how to use org.lwjgl.opengl.GL30#glBindFramebuffer() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BlurPane.java    From LWJGUI with MIT License 6 votes vote down vote up
private void blit(Context context) {
	// Source
	float ratio = window.getPixelRatio();
	int srcfbo = GL11.glGetInteger(GL30.GL_FRAMEBUFFER_BINDING);
	GL30.glBindFramebuffer(GL30.GL_READ_FRAMEBUFFER, srcfbo);
	
	// Destination
	GL30.glBindFramebuffer(GL30.GL_DRAW_FRAMEBUFFER, bufferTemp.getFboId());
	int destwid = bufferTemp.getWidth();
	int desthei = bufferTemp.getHeight();
	
	int sx1 = (int)(getX()*ratio);
	int sy1 = (int)(getY()*ratio);
	int sx2 = sx1 + (int) (destwid*ratio);
	int sy2 = sy1 + (int) (desthei*ratio);
	
	// Blit
	GL30.glBlitFramebuffer( sx1,sy1,sx2,sy2,
			                0,0, destwid,desthei,
			                GL11.GL_COLOR_BUFFER_BIT,
			                GL11.GL_NEAREST);
	
	// Rebind source
	GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER,srcfbo);
}
 
Example 2
Source File: Fbo.java    From LowPolyWater with The Unlicense 5 votes vote down vote up
/**
 * Copy the contents of a colour attachment of this FBO to the screen.
 * 
 * @param colourIndex
 *            - The index of the colour buffer that should be blitted.
 */
public void blitToScreen(int colourIndex) {
	GL30.glBindFramebuffer(GL30.GL_DRAW_FRAMEBUFFER, 0);
	GL11.glDrawBuffer(GL11.GL_BACK);
	GL30.glBindFramebuffer(GL30.GL_READ_FRAMEBUFFER, fboId);
	GL11.glReadBuffer(GL30.GL_COLOR_ATTACHMENT0 + colourIndex);
	GL30.glBlitFramebuffer(0, 0, width, height, 0, 0, Display.getWidth(), Display.getHeight(),
			GL11.GL_COLOR_BUFFER_BIT, GL11.GL_NEAREST);
	GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, 0);
}
 
Example 3
Source File: Fbo.java    From LowPolyWater with The Unlicense 5 votes vote down vote up
/**
 * Copy the contents of this FBO to another FBO. This can be used to resolve
 * multisampled FBOs.
 * 
 * @param srcColourIndex
 *            - Index of the colour buffer in this (the source) FBO.
 * @param target
 *            - The target FBO.
 * @param targetColourIndex
 *            - The index of the target colour buffer in the target FBO.
 */
public void blitToFbo(int srcColourIndex, Fbo target, int targetColourIndex) {
	GL30.glBindFramebuffer(GL30.GL_DRAW_FRAMEBUFFER, target.fboId);
	GL11.glDrawBuffer(GL30.GL_COLOR_ATTACHMENT0 + targetColourIndex);

	GL30.glBindFramebuffer(GL30.GL_READ_FRAMEBUFFER, fboId);
	GL11.glReadBuffer(GL30.GL_COLOR_ATTACHMENT0 + srcColourIndex);

	int bufferBit = depthAttachment != null && target.depthAttachment != null
			? GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT : GL11.GL_COLOR_BUFFER_BIT;
	GL30.glBlitFramebuffer(0, 0, width, height, 0, 0, target.width, target.height, bufferBit, GL11.GL_NEAREST);
	GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, 0);
}
 
Example 4
Source File: Fbo.java    From LowPolyWater with The Unlicense 5 votes vote down vote up
/**
 * @return True if this framebuffer has been correctly set up and is
 *         complete.
 */
public boolean isComplete() {
	GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, fboId);
	boolean complete = GL30.glCheckFramebufferStatus(GL30.GL_FRAMEBUFFER) == GL30.GL_FRAMEBUFFER_COMPLETE;
	GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, 0);
	return complete;
}
 
Example 5
Source File: OffscreenBuffer.java    From LWJGUI with MIT License 4 votes vote down vote up
/**
 * Resize the buffer to desired width/height
 * @param width
 * @param height
 * @return
 */
public boolean resize(int width, int height) {
	if (this.width == width && this.height == height) {
		return false;
	}
	
	this.width = width;
	this.height = height;

	// resize the texture
	if (texId != 0) {
		GL11.glDeleteTextures(texId);
		GL30.glDeleteFramebuffers(fboId);
		GL30.glDeleteRenderbuffers(renderId);
		texId = 0;
		fboId = 0;
		renderId = 0;
	}
	
	// Create texture
	if ( texId == 0 )
		texId = GL11.glGenTextures();
	GL11.glBindTexture(GL11.GL_TEXTURE_2D, texId);
	GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, width, height, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, 0);
	
	// Set default filtering
	GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
	GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
	GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE);
	GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE);
	
	// update the framebuf
	if (fboId == 0)
		fboId = GL30.glGenFramebuffers();
	GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, fboId);
	GL30.glFramebufferTexture2D(GL30.GL_FRAMEBUFFER, GL30.GL_COLOR_ATTACHMENT0, GL11.GL_TEXTURE_2D, texId, 0);
	
	// The depth buffer
	if ( renderId == 0 )
		renderId = GL30.glGenRenderbuffers();
	GL30.glBindRenderbuffer(GL30.GL_RENDERBUFFER, renderId);
	GL30.glRenderbufferStorage(GL30.GL_RENDERBUFFER, GL11.GL_DEPTH_COMPONENT, width, height);
	GL30.glFramebufferRenderbuffer(GL30.GL_FRAMEBUFFER, GL30.GL_DEPTH_ATTACHMENT, GL30.GL_RENDERBUFFER, renderId);
	
	// remove the old quad
	quadDirty = true;
	

	GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, 0);
	
	return true;
}
 
Example 6
Source File: OffscreenBuffer.java    From LWJGUI with MIT License 4 votes vote down vote up
public void bind() {
	unbindTo = GL11.glGetInteger(GL30.GL_FRAMEBUFFER_BINDING);
	GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, getFboId());
}
 
Example 7
Source File: OffscreenBuffer.java    From LWJGUI with MIT License 4 votes vote down vote up
/**
 * Unbind the buffer
 */
public void unbind() {
	if ( unbindTo == -1 )
		return;
	GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, unbindTo);
}
 
Example 8
Source File: Fbo.java    From LowPolyWater with The Unlicense 4 votes vote down vote up
/**
 * Switch back to the default frame buffer.
 */
public void unbindAfterRender() {
	GL30.glBindFramebuffer(GL30.GL_DRAW_FRAMEBUFFER, 0);
	GL11.glDrawBuffer(GL11.GL_BACK);
	GL11.glViewport(0, 0, Display.getWidth(), Display.getHeight());
}
 
Example 9
Source File: FboBuilder.java    From LowPolyWater with The Unlicense 4 votes vote down vote up
/**
 * Creates an new FBO object.
 * 
 * @return The newly created FBO.
 */
private int createFbo() {
	int fboId = GL30.glGenFramebuffers();
	GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, fboId);
	return fboId;
}
 
Example 10
Source File: DepthProducerImplementation.java    From malmo with MIT License 4 votes vote down vote up
@Override
public void getFrame(MissionInit missionInit, ByteBuffer buffer)
{
    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_DEPTH_COMPONENT, GL_FLOAT, buffer.asFloatBuffer());
    // Depth map is in 32bpp floats in the range [0-1].
    // We want to convert to give real distances in terms of block size.
    // To do this, we need to know the near and far z-planes.
    // First, get our byte buffer as a float buffer.
    FloatBuffer fluffer = buffer.asFloatBuffer();
    // The near and far planes are set by this line in EntityRenderer.renderWorldPass:
    // Project.gluPerspective(this.getFOVModifier(partialTicks, true), (float)this.mc.displayWidth / (float)this.mc.displayHeight, 0.05F, this.farPlaneDistance * MathHelper.SQRT_2);
    // So zNear is hardcoded to 0.05F:
    float zNear = 0.05F;
    // farPlaneDistance is private; we could use reflection to get at it, but we don't need to, because it's set by this line in EntityRenderer.setupCameraTransform:
    // this.farPlaneDistance = (float)(this.mc.gameSettings.renderDistanceChunks * 16);
    float zFar = (float)(Minecraft.getMinecraft().gameSettings.renderDistanceChunks * 16) * MathHelper.SQRT_2;
    float minval = 1;
    float maxval = 0;
    for (int i = 0; i < width * height; i++)
    {
        float f = fluffer.get(i);
        if (f < minval)
            minval = f;
        if (f > maxval)
            maxval = f;
        f = 2.0f * f - 1.0f;
        float zLinear = 2.0f * zNear * zFar / (zFar + zNear - f * (zFar - zNear));
        fluffer.put(i, zLinear);
    }
    this.fbo.unbindFramebuffer();
}
 
Example 11
Source File: LwjglGLFboGL3.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void glBindFramebufferEXT(int param1, int param2) {
    GL30.glBindFramebuffer(param1, param2);
}
 
Example 12
Source File: LwjglGLFboGL3.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void glBindFramebufferEXT(final int target, final int frameBuffer) {
    GL30.glBindFramebuffer(target, frameBuffer);
}
 
Example 13
Source File: Fbo.java    From LowPolyWater with The Unlicense 3 votes vote down vote up
/**
 * Bind the FBO so that it can be rendered to. Anything rendered while the
 * FBO is bound will be rendered to the FBO.
 * 
 * @param colourIndex
 *            - The index of the colour buffer that should be drawn to.
 */
public void bindForRender(int colourIndex) {
	// should add support for binding multiple colour attachments
	GL11.glDrawBuffer(GL30.GL_COLOR_ATTACHMENT0 + colourIndex);
	GL30.glBindFramebuffer(GL30.GL_DRAW_FRAMEBUFFER, fboId);
	GL11.glViewport(0, 0, width, height);
}