\r
package com.badlogic.gdx.graphics.glutils;\r
\r
+import java.nio.ByteBuffer;\r
+import java.nio.ByteOrder;\r
import java.nio.IntBuffer;\r
import java.util.ArrayList;\r
import java.util.HashMap;\r
\r
import com.badlogic.gdx.Application;\r
import com.badlogic.gdx.Gdx;\r
+import com.badlogic.gdx.Application.ApplicationType;\r
import com.badlogic.gdx.graphics.GL20;\r
import com.badlogic.gdx.graphics.Pixmap;\r
import com.badlogic.gdx.graphics.Texture;\r
/** the color buffer texture **/\r
private Texture colorTexture;\r
\r
+ /** the default framebuffer handle, a.k.a screen. */\r
+ private static int defaultFramebufferHandle;\r
+ /** true if we have polled for the default handle already. */\r
+ private static boolean defaultFramebufferHandleInitialized = false;\r
+ \r
/** the framebuffer handle **/\r
private int framebufferHandle;\r
\r
private void build () {\r
if (!Gdx.graphics.isGL20Available()) throw new GdxRuntimeException("GL2 is required.");\r
\r
+ GL20 gl = Gdx.graphics.getGL20();\r
+\r
+ // iOS uses a different framebuffer handle! (not necessarily 0)\r
+ if (!defaultFramebufferHandleInitialized) {\r
+ defaultFramebufferHandleInitialized = true;\r
+ if (Gdx.app.getType() == ApplicationType.iOS) {\r
+ IntBuffer intbuf = ByteBuffer.allocateDirect(16 * Integer.SIZE / 8).order(ByteOrder.nativeOrder()).asIntBuffer();\r
+ gl.glGetIntegerv(GL20.GL_FRAMEBUFFER_BINDING, intbuf);\r
+ defaultFramebufferHandle = intbuf.get();\r
+ }\r
+ else {\r
+ defaultFramebufferHandle = 0;\r
+ }\r
+ }\r
+ \r
colorTexture = new Texture(width, height, format);\r
colorTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear);\r
colorTexture.setWrap(TextureWrap.ClampToEdge, TextureWrap.ClampToEdge);\r
- GL20 gl = Gdx.graphics.getGL20();\r
\r
IntBuffer handle = BufferUtils.newIntBuffer(1);\r
gl.glGenFramebuffers(1, handle);\r
\r
gl.glBindRenderbuffer(GL20.GL_RENDERBUFFER, 0);\r
gl.glBindTexture(GL20.GL_TEXTURE_2D, 0);\r
- gl.glBindFramebuffer(GL20.GL_FRAMEBUFFER, 0);\r
+ gl.glBindFramebuffer(GL20.GL_FRAMEBUFFER, defaultFramebufferHandle);\r
\r
if (result != GL20.GL_FRAMEBUFFER_COMPLETE) {\r
colorTexture.dispose();\r
/** Unbinds the framebuffer, all drawing will be performed to the normal framebuffer from here on. */\r
public void end () {\r
Gdx.graphics.getGL20().glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());\r
- Gdx.graphics.getGL20().glBindFramebuffer(GL20.GL_FRAMEBUFFER, 0);\r
+ Gdx.graphics.getGL20().glBindFramebuffer(GL20.GL_FRAMEBUFFER, defaultFramebufferHandle);\r
}\r
\r
private void addManagedFrameBuffer (Application app, FrameBuffer frameBuffer) {\r