Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Added stencil buffer support on iOS.

Thanks to Brian Barnes for the initial work on this patch!
  • Loading branch information
icculus committed Oct 22, 2011
1 parent 820f15c commit 17dafb306a7d2b9278a368072cd1c8eabc03909a
@@ -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 @@ - (id)initWithFrame:(CGRect)frame
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 @@ - (id)initWithFrame:(CGRect)frame

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 @@ - (id)initWithFrame:(CGRect)frame
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) {

0 comments on commit 17dafb3

Please sign in to comment.