Search in sources :

Example 16 with GL20

use of com.badlogic.gdx.graphics.GL20 in project libgdx by libgdx.

the class SpriteCache method end.

/** Completes rendering for this SpriteCache. */
public void end() {
    if (!drawing)
        throw new IllegalStateException("begin must be called before end.");
    drawing = false;
    shader.end();
    GL20 gl = Gdx.gl20;
    gl.glDepthMask(true);
    if (customShader != null)
        mesh.unbind(customShader);
    else
        mesh.unbind(shader);
}
Also used : GL20(com.badlogic.gdx.graphics.GL20)

Example 17 with GL20

use of com.badlogic.gdx.graphics.GL20 in project libgdx by libgdx.

the class SpriteBatch method end.

@Override
public void end() {
    if (!drawing)
        throw new IllegalStateException("SpriteBatch.begin must be called before end.");
    if (idx > 0)
        flush();
    lastTexture = null;
    drawing = false;
    GL20 gl = Gdx.gl;
    gl.glDepthMask(true);
    if (isBlendingEnabled())
        gl.glDisable(GL20.GL_BLEND);
    if (customShader != null)
        customShader.end();
    else
        shader.end();
}
Also used : GL20(com.badlogic.gdx.graphics.GL20)

Example 18 with GL20

use of com.badlogic.gdx.graphics.GL20 in project libgdx by libgdx.

the class FrameBufferCubemap method attachFrameBufferColorTexture.

@Override
protected void attachFrameBufferColorTexture() {
    GL20 gl = Gdx.gl20;
    int glHandle = colorTexture.getTextureObjectHandle();
    Cubemap.CubemapSide[] sides = Cubemap.CubemapSide.values();
    for (Cubemap.CubemapSide side : sides) {
        gl.glFramebufferTexture2D(GL20.GL_FRAMEBUFFER, GL20.GL_COLOR_ATTACHMENT0, side.glEnum, glHandle, 0);
    }
}
Also used : GL20(com.badlogic.gdx.graphics.GL20) Cubemap(com.badlogic.gdx.graphics.Cubemap)

Example 19 with GL20

use of com.badlogic.gdx.graphics.GL20 in project libgdx by libgdx.

the class GLFrameBuffer method dispose.

/** Releases all resources associated with the FrameBuffer. */
@Override
public void dispose() {
    GL20 gl = Gdx.gl20;
    disposeColorTexture(colorTexture);
    if (hasDepthStencilPackedBuffer) {
        gl.glDeleteRenderbuffer(depthStencilPackedBufferHandle);
    } else {
        if (hasDepth)
            gl.glDeleteRenderbuffer(depthbufferHandle);
        if (hasStencil)
            gl.glDeleteRenderbuffer(stencilbufferHandle);
    }
    gl.glDeleteFramebuffer(framebufferHandle);
    if (buffers.get(Gdx.app) != null)
        buffers.get(Gdx.app).removeValue(this, true);
}
Also used : GL20(com.badlogic.gdx.graphics.GL20)

Example 20 with GL20

use of com.badlogic.gdx.graphics.GL20 in project libgdx by libgdx.

the class GLFrameBuffer method build.

protected void build() {
    GL20 gl = Gdx.gl20;
    // iOS uses a different framebuffer handle! (not necessarily 0)
    if (!defaultFramebufferHandleInitialized) {
        defaultFramebufferHandleInitialized = true;
        if (Gdx.app.getType() == ApplicationType.iOS) {
            IntBuffer intbuf = ByteBuffer.allocateDirect(16 * Integer.SIZE / 8).order(ByteOrder.nativeOrder()).asIntBuffer();
            gl.glGetIntegerv(GL20.GL_FRAMEBUFFER_BINDING, intbuf);
            defaultFramebufferHandle = intbuf.get(0);
        } else {
            defaultFramebufferHandle = 0;
        }
    }
    colorTexture = createColorTexture();
    framebufferHandle = gl.glGenFramebuffer();
    if (hasDepth) {
        depthbufferHandle = gl.glGenRenderbuffer();
    }
    if (hasStencil) {
        stencilbufferHandle = gl.glGenRenderbuffer();
    }
    gl.glBindTexture(colorTexture.glTarget, 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);
    attachFrameBufferColorTexture();
    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);
    }
    gl.glBindRenderbuffer(GL20.GL_RENDERBUFFER, 0);
    gl.glBindTexture(colorTexture.glTarget, 0);
    int result = gl.glCheckFramebufferStatus(GL20.GL_FRAMEBUFFER);
    if (result == GL20.GL_FRAMEBUFFER_UNSUPPORTED && hasDepth && hasStencil && (Gdx.graphics.supportsExtension("GL_OES_packed_depth_stencil") || Gdx.graphics.supportsExtension("GL_EXT_packed_depth_stencil"))) {
        if (hasDepth) {
            gl.glDeleteRenderbuffer(depthbufferHandle);
            depthbufferHandle = 0;
        }
        if (hasStencil) {
            gl.glDeleteRenderbuffer(stencilbufferHandle);
            stencilbufferHandle = 0;
        }
        depthStencilPackedBufferHandle = gl.glGenRenderbuffer();
        hasDepthStencilPackedBuffer = true;
        gl.glBindRenderbuffer(GL20.GL_RENDERBUFFER, depthStencilPackedBufferHandle);
        gl.glRenderbufferStorage(GL20.GL_RENDERBUFFER, GL_DEPTH24_STENCIL8_OES, colorTexture.getWidth(), colorTexture.getHeight());
        gl.glBindRenderbuffer(GL20.GL_RENDERBUFFER, 0);
        gl.glFramebufferRenderbuffer(GL20.GL_FRAMEBUFFER, GL20.GL_DEPTH_ATTACHMENT, GL20.GL_RENDERBUFFER, depthStencilPackedBufferHandle);
        gl.glFramebufferRenderbuffer(GL20.GL_FRAMEBUFFER, GL20.GL_STENCIL_ATTACHMENT, GL20.GL_RENDERBUFFER, depthStencilPackedBufferHandle);
        result = gl.glCheckFramebufferStatus(GL20.GL_FRAMEBUFFER);
    }
    gl.glBindFramebuffer(GL20.GL_FRAMEBUFFER, defaultFramebufferHandle);
    if (result != GL20.GL_FRAMEBUFFER_COMPLETE) {
        disposeColorTexture(colorTexture);
        if (hasDepthStencilPackedBuffer) {
            gl.glDeleteBuffer(depthStencilPackedBufferHandle);
        } else {
            if (hasDepth)
                gl.glDeleteRenderbuffer(depthbufferHandle);
            if (hasStencil)
                gl.glDeleteRenderbuffer(stencilbufferHandle);
        }
        gl.glDeleteFramebuffer(framebufferHandle);
        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);
    }
}
Also used : GL20(com.badlogic.gdx.graphics.GL20) IntBuffer(java.nio.IntBuffer)

Aggregations

GL20 (com.badlogic.gdx.graphics.GL20)52 IntBuffer (java.nio.IntBuffer)3 VertexAttribute (com.badlogic.gdx.graphics.VertexAttribute)2 Cubemap (com.badlogic.gdx.graphics.Cubemap)1 ByteBuffer (java.nio.ByteBuffer)1