More cleanup in SDL_uikitopenglview.m
authorRyan C. Gordon
Mon, 24 Oct 2011 11:38:52 -0400
changeset 6022e0327dd7d0c0
parent 6021 a4bf2a9b0fd0
child 6023 6279958d571d
More cleanup in SDL_uikitopenglview.m
src/video/uikit/SDL_uikitopenglview.m
     1.1 --- a/src/video/uikit/SDL_uikitopenglview.m	Sat Oct 22 01:23:21 2011 -0400
     1.2 +++ b/src/video/uikit/SDL_uikitopenglview.m	Mon Oct 24 11:38:52 2011 -0400
     1.3 @@ -43,37 +43,22 @@
     1.4        stencilBits:(int)stencilBits
     1.5        majorVersion:(int)majorVersion
     1.6  {
     1.7 -    const BOOL useStencilBuffer = (stencilBits != 0);
     1.8 -    const BOOL useDepthBuffer = (depthBits != 0);
     1.9 -    NSString *colorFormat = nil;
    1.10 -
    1.11 -    if (rBits == 8 && gBits == 8 && bBits == 8) {
    1.12 -        /* if user specifically requests rbg888 or some color format higher than 16bpp */
    1.13 -        colorFormat = kEAGLColorFormatRGBA8;
    1.14 -    }
    1.15 -    else {
    1.16 -        /* default case (faster) */
    1.17 -        colorFormat = kEAGLColorFormatRGB565;
    1.18 -    }
    1.19 -
    1.20      depthBufferFormat = 0;
    1.21  
    1.22 -    if (useDepthBuffer) {
    1.23 -        if (depthBits == 24) {
    1.24 -            depthBufferFormat = GL_DEPTH_COMPONENT24_OES;
    1.25 +    if ((self = [super initWithFrame:frame])) {
    1.26 +        const BOOL useStencilBuffer = (stencilBits != 0);
    1.27 +        const BOOL useDepthBuffer = (depthBits != 0);
    1.28 +        NSString *colorFormat = nil;
    1.29 +
    1.30 +        if (rBits == 8 && gBits == 8 && bBits == 8) {
    1.31 +            /* if user specifically requests rbg888 or some color format higher than 16bpp */
    1.32 +            colorFormat = kEAGLColorFormatRGBA8;
    1.33 +        } else {
    1.34 +            /* default case (faster) */
    1.35 +            colorFormat = kEAGLColorFormatRGB565;
    1.36          }
    1.37 -        else {
    1.38 -            /* default case when depth buffer is not disabled */
    1.39 -            /*
    1.40 -               strange, even when we use this, we seem to get a 24 bit depth buffer on iPhone.
    1.41 -               perhaps that's the only depth format iPhone actually supports
    1.42 -            */
    1.43 -            depthBufferFormat = GL_DEPTH_COMPONENT16_OES;
    1.44 -        }
    1.45 -    }
    1.46  
    1.47 -    if ((self = [super initWithFrame:frame])) {
    1.48 -        // Get the layer
    1.49 +        /* Get the layer */
    1.50          CAEAGLLayer *eaglLayer = (CAEAGLLayer *)self.layer;
    1.51  
    1.52          eaglLayer.opaque = YES;
    1.53 @@ -104,10 +89,13 @@
    1.54  
    1.55          if ((useDepthBuffer) || (useStencilBuffer)) {
    1.56              if (useStencilBuffer) {
    1.57 -                // Apparently you need to pack stencil and depth into one buffer.
    1.58 -                // !!! FIXME: this is the only thing (currently) supported. May not always be true.
    1.59 +                /* Apparently you need to pack stencil and depth into one buffer. */
    1.60                  depthBufferFormat = GL_DEPTH24_STENCIL8_OES;
    1.61 +            } else if (useDepthBuffer) {
    1.62 +                /* iOS only has 24-bit depth buffers, even with GL_DEPTH_COMPONENT16_OES */
    1.63 +                depthBufferFormat = GL_DEPTH_COMPONENT24_OES;
    1.64              }
    1.65 +
    1.66              glGenRenderbuffersOES(1, &depthRenderbuffer);
    1.67              glBindRenderbufferOES(GL_RENDERBUFFER_OES, depthRenderbuffer);
    1.68              glRenderbufferStorageOES(GL_RENDERBUFFER_OES, depthBufferFormat, backingWidth, backingHeight);