iOS Stencil Buffer Patch

Not really a patch, but the code required. In iOS, SDL 1.3 doesn’t support stencil buffers. The problem code is in:

SDL_uikitopenglview.m
SDL_uikitopengles.m

Basically, in SDL_uikitopengles, in the function UIKit_GL_CreateContext, you need to pass in the configurations stencil size.

In SDL_uikitopenglview.m, in initWithFrame, you need to accept the stencil size. iOS 4 does not accept separate stencil buffers, only packed stencil/depth buffers. So if both depth and stencil are non-zero,then instead of this code:

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

Do this:

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

Yes, I just re-used the depthRenderBuffer variable, you might want to do more clean code here :slight_smile: You can basically ignore the depth and stencil size, the ONLY thing you can use is 24 depth and 8 stencil.

You’re going to have to make some changes in updateFrame, also, which recreates the depth buffer. Instead of using the saved GL_DEPTH_COMPONENT24_OES, you’ll need to use GL_DEPTH24_STENCIL8_OES dfdf.

Sorry for the crazy formatting, I copied this from Xcode. If anybody ends up doing this, please drop me a line and I’ll retest it!

[>] Brian