Skip to content

Commit

Permalink
Issue 1153, new patch which addresses problems with previous patch. C…
Browse files Browse the repository at this point in the history
…hecking whether the size of the view has changed is now done in the ES1Renderer where the correct width and height can be retrieved.

It is tested with issue 914 test and tested without UIKit autorotation.

Changed:
ES1Renderer.m
- resizeFromLayer:
  • Loading branch information
araker committed Sep 18, 2011
1 parent 1dfac50 commit 93076dd
Showing 1 changed file with 51 additions and 43 deletions.
94 changes: 51 additions & 43 deletions cocos2d/Platforms/iOS/ES1Renderer.m
Expand Up @@ -65,6 +65,8 @@ - (id) initWithDepthFormat:(unsigned int)depthFormat withPixelFormat:(unsigned i
[self release];
return nil;
}

backingWidth_ = backingHeight_ = 0;

// Create default framebuffer object. The backing will be allocated for the current layer in -resizeFromLayer
glGenFramebuffersOES(1, &defaultFramebuffer_);
Expand Down Expand Up @@ -114,67 +116,73 @@ - (BOOL)resizeFromLayer:(CAEAGLLayer *)layer

glBindRenderbufferOES(GL_RENDERBUFFER_OES, colorRenderbuffer_);

int oldWidth = backingWidth_;
int oldHeight = backingHeight_;

if (![context_ renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:layer])
{
CCLOG(@"failed to call context");
}

glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &backingWidth_);
glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &backingHeight_);

if (oldWidth != backingWidth_ || oldHeight != backingHeight_)
{

CCLOG(@"cocos2d: surface size: %dx%d", (int)backingWidth_, (int)backingHeight_);
CCLOG(@"cocos2d: surface size: %dx%d", (int)backingWidth_, (int)backingHeight_);

if (multiSampling_)
{
if (multiSampling_)
{

if ( msaaColorbuffer_) {
glDeleteRenderbuffersOES(1, &msaaColorbuffer_);
msaaColorbuffer_ = 0;
}

/* Create the offscreen MSAA color buffer.
After rendering, the contents of this will be blitted into ColorRenderbuffer */

//msaaFrameBuffer needs to be binded
glBindFramebufferOES(GL_FRAMEBUFFER_OES, msaaFramebuffer_);
glGenRenderbuffersOES(1, &msaaColorbuffer_);
glBindRenderbufferOES(GL_RENDERBUFFER_OES, msaaColorbuffer_);
glRenderbufferStorageMultisampleAPPLE(GL_RENDERBUFFER_OES, samplesToUse_,pixelFormat_ , backingWidth_, backingHeight_);
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, msaaColorbuffer_);

if (glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES) != GL_FRAMEBUFFER_COMPLETE_OES)
{
CCLOG(@"Failed to make complete framebuffer object %x", glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES));
return NO;
}
}

if ( msaaColorbuffer_) {
glDeleteRenderbuffersOES(1, &msaaColorbuffer_);
msaaColorbuffer_ = 0;
if (depthFormat_)
{
if( ! depthBuffer_ )
glGenRenderbuffersOES(1, &depthBuffer_);

glBindRenderbufferOES(GL_RENDERBUFFER_OES, depthBuffer_);
if( multiSampling_ )
glRenderbufferStorageMultisampleAPPLE(GL_RENDERBUFFER_OES, samplesToUse_, depthFormat_,backingWidth_, backingHeight_);
else
glRenderbufferStorageOES(GL_RENDERBUFFER_OES, depthFormat_, backingWidth_, backingHeight_);
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, GL_RENDERBUFFER_OES, depthBuffer_);

// bind color buffer
glBindRenderbufferOES(GL_RENDERBUFFER_OES, colorRenderbuffer_);
}

/* Create the offscreen MSAA color buffer.
After rendering, the contents of this will be blitted into ColorRenderbuffer */

//msaaFrameBuffer needs to be binded
glBindFramebufferOES(GL_FRAMEBUFFER_OES, msaaFramebuffer_);
glGenRenderbuffersOES(1, &msaaColorbuffer_);
glBindRenderbufferOES(GL_RENDERBUFFER_OES, msaaColorbuffer_);
glRenderbufferStorageMultisampleAPPLE(GL_RENDERBUFFER_OES, samplesToUse_,pixelFormat_ , backingWidth_, backingHeight_);
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, msaaColorbuffer_);

glBindFramebufferOES(GL_FRAMEBUFFER_OES, defaultFramebuffer_);

if (glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES) != GL_FRAMEBUFFER_COMPLETE_OES)
{
CCLOG(@"Failed to make complete framebuffer object %x", glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES));
return NO;
}
}

if (depthFormat_)
{
if( ! depthBuffer_ )
glGenRenderbuffersOES(1, &depthBuffer_);

glBindRenderbufferOES(GL_RENDERBUFFER_OES, depthBuffer_);
if( multiSampling_ )
glRenderbufferStorageMultisampleAPPLE(GL_RENDERBUFFER_OES, samplesToUse_, depthFormat_,backingWidth_, backingHeight_);
else
glRenderbufferStorageOES(GL_RENDERBUFFER_OES, depthFormat_, backingWidth_, backingHeight_);
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, GL_RENDERBUFFER_OES, depthBuffer_);

// bind color buffer
glBindRenderbufferOES(GL_RENDERBUFFER_OES, colorRenderbuffer_);
}

glBindFramebufferOES(GL_FRAMEBUFFER_OES, defaultFramebuffer_);

if (glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES) != GL_FRAMEBUFFER_COMPLETE_OES)
{
CCLOG(@"Failed to make complete framebuffer object %x", glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES));
return NO;
}

CHECK_GL_ERROR();

CHECK_GL_ERROR();
}
return YES;
}

Expand Down

0 comments on commit 93076dd

Please sign in to comment.