Added stencil buffer support on iOS.
authorRyan C. Gordon
Sat, 22 Oct 2011 01:23:21 -0400
changeset 6021a4bf2a9b0fd0
parent 6020 5374ddd99862
child 6022 e0327dd7d0c0
Added stencil buffer support on iOS.

Thanks to Brian Barnes for the initial work on this patch!
src/video/uikit/SDL_uikitopengles.m
src/video/uikit/SDL_uikitopenglview.h
src/video/uikit/SDL_uikitopenglview.m
     1.1 --- a/src/video/uikit/SDL_uikitopengles.m	Mon Oct 24 11:25:03 2011 -0400
     1.2 +++ b/src/video/uikit/SDL_uikitopengles.m	Sat Oct 22 01:23:21 2011 -0400
     1.3 @@ -112,6 +112,7 @@
     1.4                                      bBits: _this->gl_config.blue_size
     1.5                                      aBits: _this->gl_config.alpha_size
     1.6                                      depthBits: _this->gl_config.depth_size
     1.7 +                                    stencilBits: _this->gl_config.stencil_size
     1.8                                      majorVersion: _this->gl_config.major_version];
     1.9  
    1.10      data->view = view;
     2.1 --- a/src/video/uikit/SDL_uikitopenglview.h	Mon Oct 24 11:25:03 2011 -0400
     2.2 +++ b/src/video/uikit/SDL_uikitopenglview.h	Sat Oct 22 01:23:21 2011 -0400
     2.3 @@ -60,6 +60,7 @@
     2.4      bBits:(int)bBits
     2.5      aBits:(int)aBits
     2.6      depthBits:(int)depthBits
     2.7 +    stencilBits:(int)stencilBits
     2.8      majorVersion:(int)majorVersion;
     2.9  
    2.10  - (void)updateFrame;
     3.1 --- a/src/video/uikit/SDL_uikitopenglview.m	Mon Oct 24 11:25:03 2011 -0400
     3.2 +++ b/src/video/uikit/SDL_uikitopenglview.m	Sat Oct 22 01:23:21 2011 -0400
     3.3 @@ -40,10 +40,12 @@
     3.4        bBits:(int)bBits
     3.5        aBits:(int)aBits
     3.6        depthBits:(int)depthBits
     3.7 +      stencilBits:(int)stencilBits
     3.8        majorVersion:(int)majorVersion
     3.9  {
    3.10 +    const BOOL useStencilBuffer = (stencilBits != 0);
    3.11 +    const BOOL useDepthBuffer = (depthBits != 0);
    3.12      NSString *colorFormat = nil;
    3.13 -    BOOL useDepthBuffer;
    3.14  
    3.15      if (rBits == 8 && gBits == 8 && bBits == 8) {
    3.16          /* if user specifically requests rbg888 or some color format higher than 16bpp */
    3.17 @@ -56,21 +58,18 @@
    3.18  
    3.19      depthBufferFormat = 0;
    3.20  
    3.21 -    if (depthBits == 24) {
    3.22 -        useDepthBuffer = YES;
    3.23 -        depthBufferFormat = GL_DEPTH_COMPONENT24_OES;
    3.24 -    }
    3.25 -    else if (depthBits == 0) {
    3.26 -        useDepthBuffer = NO;
    3.27 -    }
    3.28 -    else {
    3.29 -        /* default case when depth buffer is not disabled */
    3.30 -        /*
    3.31 -           strange, even when we use this, we seem to get a 24 bit depth buffer on iPhone.
    3.32 -           perhaps that's the only depth format iPhone actually supports
    3.33 -        */
    3.34 -        useDepthBuffer = YES;
    3.35 -        depthBufferFormat = GL_DEPTH_COMPONENT16_OES;
    3.36 +    if (useDepthBuffer) {
    3.37 +        if (depthBits == 24) {
    3.38 +            depthBufferFormat = GL_DEPTH_COMPONENT24_OES;
    3.39 +        }
    3.40 +        else {
    3.41 +            /* default case when depth buffer is not disabled */
    3.42 +            /*
    3.43 +               strange, even when we use this, we seem to get a 24 bit depth buffer on iPhone.
    3.44 +               perhaps that's the only depth format iPhone actually supports
    3.45 +            */
    3.46 +            depthBufferFormat = GL_DEPTH_COMPONENT16_OES;
    3.47 +        }
    3.48      }
    3.49  
    3.50      if ((self = [super initWithFrame:frame])) {
    3.51 @@ -103,11 +102,21 @@
    3.52          glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &backingWidth);
    3.53          glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &backingHeight);
    3.54  
    3.55 -        if (useDepthBuffer) {
    3.56 +        if ((useDepthBuffer) || (useStencilBuffer)) {
    3.57 +            if (useStencilBuffer) {
    3.58 +                // Apparently you need to pack stencil and depth into one buffer.
    3.59 +                // !!! FIXME: this is the only thing (currently) supported. May not always be true.
    3.60 +                depthBufferFormat = GL_DEPTH24_STENCIL8_OES;
    3.61 +            }
    3.62              glGenRenderbuffersOES(1, &depthRenderbuffer);
    3.63              glBindRenderbufferOES(GL_RENDERBUFFER_OES, depthRenderbuffer);
    3.64              glRenderbufferStorageOES(GL_RENDERBUFFER_OES, depthBufferFormat, backingWidth, backingHeight);
    3.65 -            glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, GL_RENDERBUFFER_OES, depthRenderbuffer);
    3.66 +            if (useDepthBuffer) {
    3.67 +                glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, GL_RENDERBUFFER_OES, depthRenderbuffer);
    3.68 +            }
    3.69 +            if (useStencilBuffer) {
    3.70 +                glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_STENCIL_ATTACHMENT_OES, GL_RENDERBUFFER_OES, depthRenderbuffer);
    3.71 +            }
    3.72          }
    3.73  
    3.74          if (glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES) != GL_FRAMEBUFFER_COMPLETE_OES) {