Created
November 4, 2011 20:55
-
-
Save anonymous/1340465 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void) layoutSubviews | |
{ | |
NSLog(@"Laying out subview"); | |
[self destroyFramebuffer]; | |
[self createFramebuffer]; | |
[EAGLContext setCurrentContext:context]; | |
if (needsErase) { | |
[self erase]; | |
needsErase = NO; | |
} | |
} | |
- (BOOL) createFramebuffer | |
{ | |
glGenFramebuffersOES(1, &viewFramebuffer); | |
glGenRenderbuffersOES(1, &viewRenderbuffer); | |
glBindFramebuffer(GL_FRAMEBUFFER_OES, viewFramebuffer); | |
glBindRenderbuffer(GL_RENDERBUFFER_OES, viewRenderbuffer); | |
CAEAGLLayer *eaglLayer = (CAEAGLLayer*)self.layer; | |
// This call associates the storage for the current render buffer with the EAGLDrawable (our CAEAGLLayer) allowing us to draw into a buffer that will later be rendered to the screen | |
BOOL status = [context renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:eaglLayer]; | |
if (status == NO) { | |
NSLog(@"Failed to allocate renderbuffer storage!"); | |
} | |
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, viewRenderbuffer); | |
glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &backingWidth); | |
glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &backingHeight); | |
// NSLog(@"Backing Width: %d Height: %d", backingWidth, backingHeight); | |
if (glCheckFramebufferStatus(GL_FRAMEBUFFER_OES) != GL_FRAMEBUFFER_COMPLETE_OES) { | |
NSLog(@"Failed to make a complete framebuffer object %x", glCheckFramebufferStatus(GL_FRAMEBUFFER_OES)); | |
return NO; | |
} | |
return YES; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment