Search code examples
iosiphoneopengl-esscaleframebuffer

How to adapt the old OpenGL ES 1 setup to iPhone 6 Plus?


If I'm not the last man on earth using the very 1st version of OpenGL ES: has anyone dealt with adapting the resizeFromLayer function to the new 3x scaling on iPhone 6 Plus?

The code below works perfectly for all previous iPhones:

- (BOOL)resizeFromLayer:(CAEAGLLayer *)layer {
glGenFramebuffersOES(1, &viewFramebuffer);
glGenRenderbuffersOES(1, &viewRenderbuffer);

glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);
glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
[context renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:layer];
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);

glGenRenderbuffersOES(1, &depthRenderbuffer);
glBindRenderbufferOES(GL_RENDERBUFFER_OES, depthRenderbuffer);
glRenderbufferStorageOES(GL_RENDERBUFFER_OES, GL_DEPTH_COMPONENT16_OES, backingWidth, backingHeight);
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, GL_RENDERBUFFER_OES, depthRenderbuffer);

const GLfloat zNear = 0.1f, zFar = 8100.0f, fieldOfView = 60.0;
CGRect rect = layer.bounds;
GLfloat size;

glEnable(GL_DEPTH_TEST);
glMatrixMode(GL_MODELVIEW);
size = zNear * tanf(DEGREES_TO_RADIANS(fieldOfView) / 2.0);

glFrustumf(-size, size, -size / (rect.size.width / rect.size.height), size / (rect.size.width / rect.size.height), zNear, zFar);

glRotatef(-90.0, 0.0, 0.0, 1.0);

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

return YES;

}

Although I've updated the launch images for new phones (so the app detects 414x736 points), it still seems to act like it's working in 'zoomed mode' (for older apps).

Anyone sees a solution? I'd really appreciate your help.


Solution

  • Although the question is a bit off the issue topic we managed to find the solution. The problem is in getting the render buffer from the UIView layer which was returning a 1x scaled buffer meaning a resolution was too low. This issue is not bound to any version of the openGL ES on the iOS and can be produced on all versions.

    You use a method renderbufferStorage:fromDrawable: which generates a render buffer storage from the layer. The layer itself needs to have its contentScale set to the screen scale to achieve an appropriate resolution using self.layer.contentsScale = [UIScreen mainScreen].scale; as already mentioned in the comment.

    Note that all other code is irrelevant in this matter.