public
anonymous / gist:1340465
Created

  • Download Gist
gistfile1.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
- (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;
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.