+
+# ifdef USE_IPHONE
+ [EAGLContext setCurrentContext: ogl_ctx];
+
+ double s = [self hackedContentScaleFactor];
+ int w = s * [self bounds].size.width;
+ int h = s * [self bounds].size.height;
+
+ if (gl_framebuffer) glDeleteFramebuffersOES (1, &gl_framebuffer);
+ if (gl_renderbuffer) glDeleteRenderbuffersOES (1, &gl_renderbuffer);
+ if (gl_depthbuffer) glDeleteRenderbuffersOES (1, &gl_depthbuffer);
+
+ glGenFramebuffersOES (1, &gl_framebuffer);
+ glBindFramebufferOES (GL_FRAMEBUFFER_OES, gl_framebuffer);
+
+ glGenRenderbuffersOES (1, &gl_renderbuffer);
+ glBindRenderbufferOES (GL_RENDERBUFFER_OES, gl_renderbuffer);
+
+// redundant?
+// glRenderbufferStorageOES (GL_RENDERBUFFER_OES, GL_RGBA8_OES, w, h);
+ [ogl_ctx renderbufferStorage:GL_RENDERBUFFER_OES
+ fromDrawable:(CAEAGLLayer*)self.layer];
+
+ glFramebufferRenderbufferOES (GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES,
+ GL_RENDERBUFFER_OES, gl_renderbuffer);
+
+ glGenRenderbuffersOES (1, &gl_depthbuffer);
+ // renderbufferStorage: must be called before this.
+ glBindRenderbufferOES (GL_RENDERBUFFER_OES, gl_depthbuffer);
+ glRenderbufferStorageOES (GL_RENDERBUFFER_OES, GL_DEPTH_COMPONENT16_OES,
+ w, h);
+ glFramebufferRenderbufferOES (GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES,
+ GL_RENDERBUFFER_OES, gl_depthbuffer);
+
+ int err = glCheckFramebufferStatusOES (GL_FRAMEBUFFER_OES);
+ switch (err) {
+ case GL_FRAMEBUFFER_COMPLETE_OES:
+ break;
+ case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_OES:
+ NSAssert (0, @"framebuffer incomplete attachment");
+ break;
+ case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_OES:
+ NSAssert (0, @"framebuffer incomplete missing attachment");
+ break;
+ case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_OES:
+ NSAssert (0, @"framebuffer incomplete dimensions");
+ break;
+ case GL_FRAMEBUFFER_INCOMPLETE_FORMATS_OES:
+ NSAssert (0, @"framebuffer incomplete formats");
+ break;
+ case GL_FRAMEBUFFER_UNSUPPORTED_OES:
+ NSAssert (0, @"framebuffer unsupported");
+ break;
+/*
+ case GL_FRAMEBUFFER_UNDEFINED:
+ NSAssert (0, @"framebuffer undefined");
+ break;
+ case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER:
+ NSAssert (0, @"framebuffer incomplete draw buffer");
+ break;
+ case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER:
+ NSAssert (0, @"framebuffer incomplete read buffer");
+ break;
+ case GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE:
+ NSAssert (0, @"framebuffer incomplete multisample");
+ break;
+ case GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS:
+ NSAssert (0, @"framebuffer incomplete layer targets");
+ break;
+ */
+ default:
+ NSAssert (0, @"framebuffer incomplete, unknown error 0x%04X", err);
+ break;
+ }
+
+ check_gl_error ("setOglContext");
+
+# endif // USE_IPHONE
+