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

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

Introduction

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

Prototype

int GL_DEPTH_COMPONENT16

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

Click Source Link

Usage

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 .jav  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.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 {/*from ww  w .  ja  va2 s .  c  o  m*/
            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);
    }
}