Example usage for com.badlogic.gdx.graphics GL20 GL_FRAMEBUFFER

List of usage examples for com.badlogic.gdx.graphics GL20 GL_FRAMEBUFFER

Introduction

In this page you can find the example usage for com.badlogic.gdx.graphics GL20 GL_FRAMEBUFFER.

Prototype

int GL_FRAMEBUFFER

To view the source code for com.badlogic.gdx.graphics GL20 GL_FRAMEBUFFER.

Click Source Link

Usage

From source file:com.bitfire.postprocessing.filters.CubemapEquirectangularFilter.java

License:Apache License

public void setSides(FrameBuffer xpositive, FrameBuffer xnegative, FrameBuffer ypositive, FrameBuffer ynegative,
        FrameBuffer zpositive, FrameBuffer znegative) {
    cubemapSides = new TextureData[6];
    cubemapSides[0] = xpositive.getColorBufferTexture().getTextureData();
    cubemapSides[1] = xnegative.getColorBufferTexture().getTextureData();
    cubemapSides[2] = ypositive.getColorBufferTexture().getTextureData();
    cubemapSides[3] = ynegative.getColorBufferTexture().getTextureData();
    cubemapSides[4] = zpositive.getColorBufferTexture().getTextureData();
    cubemapSides[5] = znegative.getColorBufferTexture().getTextureData();

    FrameBuffer[] fbos = new FrameBuffer[6];
    fbos[0] = xpositive;/*  w  w w . j  a v  a 2 s  . c om*/
    fbos[1] = xnegative;
    fbos[2] = ypositive;
    fbos[3] = ynegative;
    fbos[4] = zpositive;
    fbos[5] = znegative;

    if (cmId < 0)
        cmId = Gdx.gl.glGenTexture();

    // Make active
    Gdx.gl.glActiveTexture(GL20.GL_TEXTURE0 + u_texture1);
    Gdx.gl.glBindTexture(GL20.GL_TEXTURE_CUBE_MAP, cmId);

    // Call glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i) for all sides
    for (int i = 0; i < cubemapSides.length; i++) {
        if (cubemapSides[i].getType() == TextureData.TextureDataType.Custom) {
            cubemapSides[i].consumeCustomData(GL20.GL_TEXTURE_CUBE_MAP_POSITIVE_X + i);
        }
    }

    for (int i = 0; i < cubemapSides.length; i++) {
        fbos[i].begin();
        Gdx.gl.glFramebufferTexture2D(GL20.GL_FRAMEBUFFER, GL20.GL_COLOR_ATTACHMENT0,
                GL20.GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, cmId, 0);
        fbos[i].end();
    }

    Gdx.gl.glTexParameteri(GL20.GL_TEXTURE_CUBE_MAP, GL20.GL_TEXTURE_MAG_FILTER, GL20.GL_LINEAR);
    Gdx.gl.glTexParameteri(GL20.GL_TEXTURE_CUBE_MAP, GL20.GL_TEXTURE_MIN_FILTER, GL20.GL_LINEAR);
    Gdx.gl.glTexParameteri(GL20.GL_TEXTURE_CUBE_MAP, GL20.GL_TEXTURE_WRAP_S, GL20.GL_CLAMP_TO_EDGE);
    Gdx.gl.glTexParameteri(GL20.GL_TEXTURE_CUBE_MAP, GL20.GL_TEXTURE_WRAP_T, GL20.GL_CLAMP_TO_EDGE);
    Gdx.gl.glBindTexture(GL20.GL_TEXTURE_CUBE_MAP, 0);

    setParam(Param.Cubemap, u_texture1);

}

From source file:com.iLoong.launcher.Widget3D.FrameBuffer.java

License:Open Source License

private void build() {
    if (!Gdx.graphics.isGL20Available())
        throw new GdxRuntimeException("GL2 is required.");
    colorTexture = new Texture(width, height, format);
    colorTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
    colorTexture.setWrap(TextureWrap.ClampToEdge, TextureWrap.ClampToEdge);
    GL20 gl = Gdx.graphics.getGL20();/*from   w  w  w.j a  v  a 2s  . c o  m*/
    IntBuffer handle = BufferUtils.newIntBuffer(1);
    gl.glGenFramebuffers(1, handle);
    framebufferHandle = handle.get(0);
    if (hasDepth) {
        gl.glGenRenderbuffers(1, handle);
        depthbufferHandle = handle.get(0);
    }
    gl.glBindTexture(GL20.GL_TEXTURE_2D, colorTexture.getTextureObjectHandle());
    if (hasDepth) {
        gl.glBindRenderbuffer(GL20.GL_RENDERBUFFER, depthbufferHandle);
        gl.glRenderbufferStorage(GL20.GL_RENDERBUFFER, GL20.GL_DEPTH_COMPONENT16, colorTexture.getWidth(),
                colorTexture.getHeight());
    }
    gl.glBindFramebuffer(GL20.GL_FRAMEBUFFER, framebufferHandle);
    gl.glFramebufferTexture2D(GL20.GL_FRAMEBUFFER, GL20.GL_COLOR_ATTACHMENT0, GL20.GL_TEXTURE_2D,
            colorTexture.getTextureObjectHandle(), 0);
    if (hasDepth) {
        gl.glFramebufferRenderbuffer(GL20.GL_FRAMEBUFFER, GL20.GL_DEPTH_ATTACHMENT, GL20.GL_RENDERBUFFER,
                depthbufferHandle);
    }
    int result = gl.glCheckFramebufferStatus(GL20.GL_FRAMEBUFFER);
    gl.glBindRenderbuffer(GL20.GL_RENDERBUFFER, 0);
    gl.glBindTexture(GL20.GL_TEXTURE_2D, 0);
    gl.glBindFramebuffer(GL20.GL_FRAMEBUFFER, 0);
    if (result != GL20.GL_FRAMEBUFFER_COMPLETE) {
        colorTexture.dispose();
        if (hasDepth) {
            handle.put(depthbufferHandle);
            handle.flip();
            gl.glDeleteRenderbuffers(1, handle);
        }
        colorTexture.dispose();
        handle.put(framebufferHandle);
        handle.flip();
        gl.glDeleteFramebuffers(1, handle);
        if (result == GL20.GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT)
            throw new IllegalStateException("frame buffer couldn't be constructed: incomplete attachment");
        if (result == GL20.GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS)
            throw new IllegalStateException("frame buffer couldn't be constructed: incomplete dimensions");
        if (result == GL20.GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT)
            throw new IllegalStateException("frame buffer couldn't be constructed: missing attachment");
    }
}

From source file:com.iLoong.launcher.Widget3D.FrameBuffer.java

License:Open Source License

/** Makes the frame buffer current so everything gets drawn to it. */
public void begin() {
    Gdx.graphics.getGL20().glViewport(0, 0, colorTexture.getWidth(), colorTexture.getHeight());
    Gdx.graphics.getGL20().glBindFramebuffer(GL20.GL_FRAMEBUFFER, framebufferHandle);
}

From source file:com.iLoong.launcher.Widget3D.FrameBuffer.java

License:Open Source License

/** Unbinds the framebuffer, all drawing will be performed to the normal framebuffer from here on. */
public void end() {
    Gdx.graphics.getGL20().glViewport(0, 0, Utils3D.getScreenWidth(), Utils3D.getScreenHeight());
    Gdx.graphics.getGL20().glBindFramebuffer(GL20.GL_FRAMEBUFFER, 0);
}

From source file:com.mbrlabs.mundus.editor.tools.picker.BasePicker.java

License:Apache License

public Pixmap getFrameBufferPixmap(Viewport viewport) {
    int w = viewport.getScreenWidth();
    int h = viewport.getScreenHeight();
    int x = viewport.getScreenX();
    int y = viewport.getScreenY();
    final ByteBuffer pixelBuffer = BufferUtils.newByteBuffer(w * h * 4);

    Gdx.gl.glBindFramebuffer(GL20.GL_FRAMEBUFFER, fbo.getFramebufferHandle());
    Gdx.gl.glReadPixels(x, y, w, h, GL30.GL_RGBA, GL30.GL_UNSIGNED_BYTE, pixelBuffer);
    Gdx.gl.glBindFramebuffer(GL20.GL_FRAMEBUFFER, 0);

    final int numBytes = w * h * 4;
    byte[] imgLines = new byte[numBytes];
    final int numBytesPerLine = w * 4;
    for (int i = 0; i < h; i++) {
        pixelBuffer.position((h - i - 1) * numBytesPerLine);
        pixelBuffer.get(imgLines, i * numBytesPerLine, numBytesPerLine);
    }//from   w w w. j a  v  a 2  s.  c  o  m

    Pixmap pixmap = new Pixmap(w, h, Pixmap.Format.RGBA8888);
    BufferUtils.copy(imgLines, 0, pixmap.getPixels(), imgLines.length);

    return pixmap;
}

From source file:com.microbasic.sm.tools.FrameBufferCubeMap.java

License:Apache License

private void build() {
    final GL20 gl = Gdx.gl20;

    // iOS uses a different framebuffer handle! (not necessarily 0)
    if (!defaultFramebufferHandleInitialized) {
        defaultFramebufferHandleInitialized = true;
        if (Gdx.app.getType() == ApplicationType.iOS) {
            final IntBuffer intbuf = ByteBuffer.allocateDirect(16 * Integer.SIZE / 8)
                    .order(ByteOrder.nativeOrder()).asIntBuffer();
            gl.glGetIntegerv(GL20.GL_FRAMEBUFFER_BINDING, intbuf);
            defaultFramebufferHandle = intbuf.get(0);
        } else {/*ww w. j  av  a  2  s. com*/
            defaultFramebufferHandle = 0;
        }
    }

    setupTexture();

    final IntBuffer handle = BufferUtils.newIntBuffer(1);
    gl.glGenFramebuffers(1, handle);
    framebufferHandle = handle.get(0);

    if (hasDepth) {
        handle.clear();
        gl.glGenRenderbuffers(1, handle);
        depthbufferHandle = handle.get(0);
    }

    if (hasStencil) {
        handle.clear();
        gl.glGenRenderbuffers(1, handle);
        stencilbufferHandle = handle.get(0);
    }

    gl.glBindTexture(GL20.GL_TEXTURE_CUBE_MAP, colorTexture.getTextureObjectHandle());

    if (hasDepth) {
        gl.glBindRenderbuffer(GL20.GL_RENDERBUFFER, depthbufferHandle);
        gl.glRenderbufferStorage(GL20.GL_RENDERBUFFER, GL20.GL_DEPTH_COMPONENT16, colorTexture.getWidth(),
                colorTexture.getHeight());
    }

    if (hasStencil) {
        gl.glBindRenderbuffer(GL20.GL_RENDERBUFFER, stencilbufferHandle);
        gl.glRenderbufferStorage(GL20.GL_RENDERBUFFER, GL20.GL_STENCIL_INDEX8, colorTexture.getWidth(),
                colorTexture.getHeight());
    }

    gl.glBindFramebuffer(GL20.GL_FRAMEBUFFER, framebufferHandle);
    gl.glFramebufferTexture2D(GL20.GL_FRAMEBUFFER, GL20.GL_COLOR_ATTACHMENT0, GL20.GL_TEXTURE_CUBE_MAP,
            colorTexture.getTextureObjectHandle(), 0);
    if (hasDepth) {
        gl.glFramebufferRenderbuffer(GL20.GL_FRAMEBUFFER, GL20.GL_DEPTH_ATTACHMENT, GL20.GL_RENDERBUFFER,
                depthbufferHandle);
    }

    if (hasStencil) {
        gl.glFramebufferRenderbuffer(GL20.GL_FRAMEBUFFER, GL20.GL_STENCIL_ATTACHMENT, GL20.GL_RENDERBUFFER,
                stencilbufferHandle);
    }

    final int result = gl.glCheckFramebufferStatus(GL20.GL_FRAMEBUFFER);

    gl.glBindRenderbuffer(GL20.GL_RENDERBUFFER, 0);
    gl.glBindTexture(GL20.GL_TEXTURE_CUBE_MAP, 0);
    gl.glBindFramebuffer(GL20.GL_FRAMEBUFFER, defaultFramebufferHandle);

    /*for (int i = 0; i < 6; i++)
    {
       gl.glTexImage2D(GL20.GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL20.GL_ALPHA, width, height, 0, GL20.GL_ALPHA, GL20.GL_UNSIGNED_BYTE, null);
    }*/

    if (result != GL20.GL_FRAMEBUFFER_COMPLETE) {
        colorTexture.dispose();
        if (hasDepth) {
            handle.clear();
            handle.put(depthbufferHandle);
            handle.flip();
            gl.glDeleteRenderbuffers(1, handle);
        }

        if (hasStencil) {
            handle.clear();
            handle.put(stencilbufferHandle);
            handle.flip();
            gl.glDeleteRenderbuffers(1, handle);
        }

        handle.clear();
        handle.put(framebufferHandle);
        handle.flip();
        gl.glDeleteFramebuffers(1, handle);

        if (result == GL20.GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT) {
            throw new IllegalStateException("frame buffer couldn't be constructed: incomplete attachment");
        }
        if (result == GL20.GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS) {
            throw new IllegalStateException("frame buffer couldn't be constructed: incomplete dimensions");
        }
        if (result == GL20.GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT) {
            throw new IllegalStateException("frame buffer couldn't be constructed: missing attachment");
        }
        if (result == GL20.GL_FRAMEBUFFER_UNSUPPORTED) {
            throw new IllegalStateException(
                    "frame buffer couldn't be constructed: unsupported combination of formats");
        }
        throw new IllegalStateException("frame buffer couldn't be constructed: unknown error " + result);
    }
}

From source file:com.microbasic.sm.tools.FrameBufferCubeMap.java

License:Apache License

/** Makes the frame buffer current so everything gets drawn to it. */
public void bind(final int side) {
    Gdx.gl20.glBindFramebuffer(GL20.GL_FRAMEBUFFER, framebufferHandle);
    Gdx.gl20.glFramebufferTexture2D(GL20.GL_FRAMEBUFFER, GL20.GL_COLOR_ATTACHMENT0, side,
            colorTexture.getTextureObjectHandle(), 0);
}

From source file:com.microbasic.sm.tools.FrameBufferCubeMap.java

License:Apache License

/**
 * Unbinds the framebuffer, all drawing will be performed to the normal framebuffer from here
 * on.//from  www  .  j a  v a  2s  .  c  o m
 */
public static void unbind() {
    Gdx.gl20.glBindFramebuffer(GL20.GL_FRAMEBUFFER, defaultFramebufferHandle);
}

From source file:com.watabou.glwrap.Framebuffer.java

License:Open Source License

public void bind() {
    Gdx.gl.glBindFramebuffer(GL20.GL_FRAMEBUFFER, id);
}

From source file:com.watabou.glwrap.Framebuffer.java

License:Open Source License

public boolean status() {
    bind();
    return Gdx.gl.glCheckFramebufferStatus(GL20.GL_FRAMEBUFFER) == GL20.GL_FRAMEBUFFER_COMPLETE;
}