Commit ac5be095 authored by Ryan C. Gordon's avatar Ryan C. Gordon

Added stencil buffer support on iOS.

Thanks to Brian Barnes for the initial work on this patch!
parent 0b68d080
......@@ -112,6 +112,7 @@ SDL_GLContext UIKit_GL_CreateContext(_THIS, SDL_Window * window)
bBits: _this->gl_config.blue_size
aBits: _this->gl_config.alpha_size
depthBits: _this->gl_config.depth_size
stencilBits: _this->gl_config.stencil_size
majorVersion: _this->gl_config.major_version];
data->view = view;
......
......@@ -60,6 +60,7 @@
bBits:(int)bBits
aBits:(int)aBits
depthBits:(int)depthBits
stencilBits:(int)stencilBits
majorVersion:(int)majorVersion;
- (void)updateFrame;
......
......@@ -40,10 +40,12 @@
bBits:(int)bBits
aBits:(int)aBits
depthBits:(int)depthBits
stencilBits:(int)stencilBits
majorVersion:(int)majorVersion
{
const BOOL useStencilBuffer = (stencilBits != 0);
const BOOL useDepthBuffer = (depthBits != 0);
NSString *colorFormat = nil;
BOOL useDepthBuffer;
if (rBits == 8 && gBits == 8 && bBits == 8) {
/* if user specifically requests rbg888 or some color format higher than 16bpp */
......@@ -56,21 +58,18 @@
depthBufferFormat = 0;
if (depthBits == 24) {
useDepthBuffer = YES;
depthBufferFormat = GL_DEPTH_COMPONENT24_OES;
}
else if (depthBits == 0) {
useDepthBuffer = NO;
}
else {
/* default case when depth buffer is not disabled */
/*
strange, even when we use this, we seem to get a 24 bit depth buffer on iPhone.
perhaps that's the only depth format iPhone actually supports
*/
useDepthBuffer = YES;
depthBufferFormat = GL_DEPTH_COMPONENT16_OES;
if (useDepthBuffer) {
if (depthBits == 24) {
depthBufferFormat = GL_DEPTH_COMPONENT24_OES;
}
else {
/* default case when depth buffer is not disabled */
/*
strange, even when we use this, we seem to get a 24 bit depth buffer on iPhone.
perhaps that's the only depth format iPhone actually supports
*/
depthBufferFormat = GL_DEPTH_COMPONENT16_OES;
}
}
if ((self = [super initWithFrame:frame])) {
......@@ -103,11 +102,21 @@
glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &backingWidth);
glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &backingHeight);
if (useDepthBuffer) {
if ((useDepthBuffer) || (useStencilBuffer)) {
if (useStencilBuffer) {
// Apparently you need to pack stencil and depth into one buffer.
// !!! FIXME: this is the only thing (currently) supported. May not always be true.
depthBufferFormat = GL_DEPTH24_STENCIL8_OES;
}
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);
if (useDepthBuffer) {
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, GL_RENDERBUFFER_OES, depthRenderbuffer);
}
if (useStencilBuffer) {
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_STENCIL_ATTACHMENT_OES, GL_RENDERBUFFER_OES, depthRenderbuffer);
}
}
if (glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES) != GL_FRAMEBUFFER_COMPLETE_OES) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment