Example usage for org.lwjgl.opengl GL30 GL_RENDERBUFFER

List of usage examples for org.lwjgl.opengl GL30 GL_RENDERBUFFER

Introduction

In this page you can find the example usage for org.lwjgl.opengl GL30 GL_RENDERBUFFER.

Prototype

int GL_RENDERBUFFER

To view the source code for org.lwjgl.opengl GL30 GL_RENDERBUFFER.

Click Source Link

Document

Accepted by the target parameter of BindRenderbuffer, RenderbufferStorage, and GetRenderbufferParameteriv, and returned by GetFramebufferAttachmentParameteriv.

Usage

From source file:com.samrj.devil.gl.RBO.java

final void tempUnbind(int oldID) {
    if (oldID == id)
        return;
    GL30.glBindRenderbuffer(GL30.GL_RENDERBUFFER, oldID);
}

From source file:com.samrj.devil.gl.RBO.java

/**
 * Binds this render buffer./*from w  w  w  .j a  va 2  s.  com*/
 */
public final void bind() {
    if (deleted)
        throw new IllegalStateException("Cannot bind deleted render buffer.");
    GL30.glBindRenderbuffer(GL30.GL_RENDERBUFFER, id);
}

From source file:com.samrj.devil.gl.RBO.java

/**
 * Allocates space on the GPU for an image of the given size and format.
 * /*w  w w  .  j av a 2  s  .  c  om*/
 * @param width The width of the image.
 * @param height The height of the image.
 * @param format The format of the image.
 */
public final void storage(int width, int height, int format) {
    if (width <= 0 || height <= 0)
        throw new IllegalArgumentException("Illegal image dimensions.");

    int oldID = tempBind();
    GL30.glRenderbufferStorage(GL30.GL_RENDERBUFFER, format, width, height);
    tempUnbind(oldID);

    long newVRAM = TexUtil.getBits(format) * width * height;
    Profiler.addUsedVRAM(newVRAM - vramUsage);
    vramUsage = newVRAM;
}

From source file:net.smert.frameworkgl.opengl.helpers.FrameBufferObjectHelper.java

License:Apache License

public void attachRenderBuffer(int attachment, int rboID) {
    GL30.glFramebufferRenderbuffer(GL30.GL_FRAMEBUFFER, attachment, GL30.GL_RENDERBUFFER, rboID);
}

From source file:net.smert.frameworkgl.opengl.helpers.RenderBufferObjectHelper.java

License:Apache License

public void bind(int rboID) {
    GL30.glBindRenderbuffer(GL30.GL_RENDERBUFFER, rboID);
}

From source file:net.smert.frameworkgl.opengl.helpers.RenderBufferObjectHelper.java

License:Apache License

public void storage(int internalFormat, int width, int height) {
    GL30.glRenderbufferStorage(GL30.GL_RENDERBUFFER, internalFormat, width, height);
}

From source file:net.smert.frameworkgl.opengl.helpers.RenderBufferObjectHelper.java

License:Apache License

public void unbind() {
    GL30.glBindFramebuffer(GL30.GL_RENDERBUFFER, 0);
}

From source file:org.spout.engine.resources.ClientRenderTexture.java

License:Open Source License

@Override
public void writeGPU() {
    if (framebuffer != INVALID_BUFFER)
        throw new IllegalStateException("Framebuffer already created!");

    //Create the color buffer for this renderTexture
    textureID = GL11.glGenTextures();//from w  w  w. j a  v  a2 s  .c  o  m
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureID);

    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
    GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA8, width, height, 0, GL11.GL_RGBA, GL11.GL_INT,
            (java.nio.ByteBuffer) null); // Create the texture data

    if (useEXT) {
        framebuffer = EXTFramebufferObject.glGenFramebuffersEXT();

        EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, framebuffer);
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureID);

        EXTFramebufferObject.glFramebufferTexture2DEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT,
                EXTFramebufferObject.GL_COLOR_ATTACHMENT0_EXT, GL11.GL_TEXTURE_2D, textureID, 0);

        if (useDepthBuffer) {
            depthTarget = GL30.glGenRenderbuffers();
            EXTFramebufferObject.glBindRenderbufferEXT(EXTFramebufferObject.GL_RENDERBUFFER_EXT, depthTarget);
            EXTFramebufferObject.glRenderbufferStorageEXT(EXTFramebufferObject.GL_RENDERBUFFER_EXT,
                    GL11.GL_DEPTH_COMPONENT, this.getWidth(), this.getHeight());
            EXTFramebufferObject.glFramebufferRenderbufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT,
                    GL30.GL_DEPTH_ATTACHMENT, EXTFramebufferObject.GL_RENDERBUFFER_EXT, depthTarget);
        }

        if (EXTFramebufferObject.glCheckFramebufferStatusEXT(
                EXTFramebufferObject.GL_FRAMEBUFFER_EXT) != EXTFramebufferObject.GL_FRAMEBUFFER_COMPLETE_EXT) {
            System.out.println("ERROR: Framebuffer not complete");
            throw new ComputerIsPotatoException("Framebuffer not complete");
        }

    } else {
        framebuffer = GL30.glGenFramebuffers();
        GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, framebuffer);
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureID);

        GL30.glFramebufferTexture2D(GL30.GL_FRAMEBUFFER, GL30.GL_COLOR_ATTACHMENT0, GL11.GL_TEXTURE_2D,
                textureID, 0);

        if (useDepthBuffer) {
            depthTarget = GL30.glGenRenderbuffers();
            GL30.glBindRenderbuffer(GL30.GL_RENDERBUFFER, depthTarget);
            GL30.glRenderbufferStorage(GL30.GL_RENDERBUFFER, GL11.GL_DEPTH_COMPONENT, this.getWidth(),
                    this.getHeight());
            GL30.glFramebufferRenderbuffer(GL30.GL_FRAMEBUFFER, GL30.GL_DEPTH_ATTACHMENT, GL30.GL_RENDERBUFFER,
                    depthTarget);
        }
        GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, SCREEN_BUFFER);

        if (GL30.glCheckFramebufferStatus(GL30.GL_FRAMEBUFFER) != GL30.GL_FRAMEBUFFER_COMPLETE) {
            System.out.println("ERROR: Framebuffer not complete");
            throw new ComputerIsPotatoException("Framebuffer not complete");
        }

    }
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);

}

From source file:org.spoutcraft.api.gui.renderer.GuiRendererFBO.java

License:MIT License

@Override
public void initGui(Gui gui) {
    Minecraft mc = Minecraft.getMinecraft();
    int width = mc.displayWidth;
    int height = mc.displayHeight;
    TextureUtil.bind(guiTex);/*from  ww  w  . ja  v a2 s  .  c  om*/
    GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA8, width, height, 0, GL11.GL_RGBA,
            GL11.GL_UNSIGNED_BYTE, (ByteBuffer) null);
    TextureUtil.bind(0);

    GL30.glBindRenderbuffer(GL30.GL_RENDERBUFFER, stencilBuff);
    GL30.glRenderbufferStorage(GL30.GL_RENDERBUFFER, GL30.GL_DEPTH24_STENCIL8, width, height);
    GL30.glBindRenderbuffer(GL30.GL_RENDERBUFFER, 0);

    GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, fbo);
    GL30.glFramebufferTexture2D(GL30.GL_FRAMEBUFFER, GL30.GL_COLOR_ATTACHMENT0, GL11.GL_TEXTURE_2D, guiTex, 0);
    GL30.glFramebufferRenderbuffer(GL30.GL_FRAMEBUFFER, GL30.GL_DEPTH_ATTACHMENT, GL30.GL_RENDERBUFFER,
            stencilBuff);
    GL30.glFramebufferRenderbuffer(GL30.GL_FRAMEBUFFER, GL30.GL_STENCIL_ATTACHMENT, GL30.GL_RENDERBUFFER,
            stencilBuff);

    GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, 0);
}

From source file:se.angergard.engine.graphics.FrameBuffer.java

License:Apache License

public FrameBuffer(int width, int height, boolean hasDepth, boolean hasStencil) {
    this.width = width;
    this.height = height;

    if ((width + height) % 4 != 0.0) {
        new Exception("Width + Height must be divisible by 4");
    }/*w  ww.  j a  v a  2s  . com*/

    frameBufferID = GL30.glGenFramebuffers();
    GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, frameBufferID);

    if (hasDepth && hasStencil) {
        depthAndStencilBufferID = GL30.glGenRenderbuffers();
        GL30.glBindRenderbuffer(GL30.GL_RENDERBUFFER, depthAndStencilBufferID);
        GL30.glRenderbufferStorage(GL30.GL_RENDERBUFFER, GL30.GL_DEPTH24_STENCIL8, width, height);
        GL30.glFramebufferRenderbuffer(GL30.GL_FRAMEBUFFER, GL30.GL_DEPTH_STENCIL_ATTACHMENT,
                GL30.GL_RENDERBUFFER, depthAndStencilBufferID);
        GL30.glBindRenderbuffer(GL30.GL_RENDERBUFFER, 0);
    }

    else if (hasDepth) {
        depthBufferID = GL30.glGenRenderbuffers();
        GL30.glBindRenderbuffer(GL30.GL_RENDERBUFFER, depthBufferID);
        GL30.glRenderbufferStorage(GL30.GL_RENDERBUFFER, GL30.GL_DEPTH_COMPONENT32F, width, height);
        GL30.glFramebufferRenderbuffer(GL30.GL_FRAMEBUFFER, GL30.GL_DEPTH_ATTACHMENT, GL30.GL_RENDERBUFFER,
                depthBufferID);
        GL30.glBindRenderbuffer(GL30.GL_RENDERBUFFER, 0);
    }

    else if (hasStencil) {
        stencilBufferID = GL30.glGenRenderbuffers();
        GL30.glBindRenderbuffer(GL30.GL_RENDERBUFFER, stencilBufferID);
        GL30.glRenderbufferStorage(GL30.GL_RENDERBUFFER, GL30.GL_STENCIL_INDEX16, width, height);
        GL30.glFramebufferRenderbuffer(GL30.GL_FRAMEBUFFER, GL30.GL_STENCIL_ATTACHMENT, GL30.GL_RENDERBUFFER,
                stencilBufferID);
        GL30.glBindRenderbuffer(GL30.GL_RENDERBUFFER, 0);
    }

    colorTexture = GL11.glGenTextures();
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, colorTexture);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_CLAMP);
    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);

    GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA8, width, height, 0, GL11.GL_RGBA,
            GL11.GL_UNSIGNED_BYTE, (ByteBuffer) null);

    GL30.glFramebufferTexture2D(GL30.GL_FRAMEBUFFER, GL30.GL_COLOR_ATTACHMENT0, GL11.GL_TEXTURE_2D,
            colorTexture, 0);

    int result = GL30.glCheckFramebufferStatus(GL30.GL_FRAMEBUFFER);
    GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, 0);
    if (result != GL30.GL_FRAMEBUFFER_COMPLETE) {
        if (result == GL30.GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT) {
            new Exception("Frame Buffer Error: incomplete attachment").printStackTrace();
        }
        if (result == GL30.GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER) {
            new Exception("Frame Buffer Error: incomplete draw buffer").printStackTrace();
        }
        if (result == GL30.GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT) {
            new Exception("Frame Buffer Error: missing attachment").printStackTrace();
        }
        if (result == GL30.GL_FRAMEBUFFER_UNSUPPORTED) {
            new Exception("Frame Buffer Error: unsupported combination of formats").printStackTrace();
        }
        if (result == GL30.GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE) {
            new Exception("Frame Buffer Error: incomplete multisample").printStackTrace();
        }
        if (result == GL30.GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER) {
            new Exception("Frame Buffer Error: incomplete read buffer").printStackTrace();
        }

        new Exception("frame buffer couldn't be constructed: unknown error " + result).printStackTrace();
    }
    RenderUtil.unbindFrameBuffer();
    RenderUtil.unbindTexture();

    frameBufferShader = new ShaderProgram().createDefault2DShader();
}