colorTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
colorTexture.setWrap(TextureWrap.ClampToEdge, TextureWrap.ClampToEdge);
}
private 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;
}
}
setupTexture();
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);
}
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, defaultFramebufferHandle);
if (result != GL20.GL_FRAMEBUFFER_COMPLETE) {
colorTexture.dispose();
if (hasDepth) {
handle.clear();
handle.put(depthbufferHandle);
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");