Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Added stencil buffer support on iOS.
Browse files Browse the repository at this point in the history
Thanks to Brian Barnes for the initial work on this patch!
  • Loading branch information
icculus committed Oct 22, 2011
1 parent 820f15c commit 17dafb3
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 18 deletions.
1 change: 1 addition & 0 deletions src/video/uikit/SDL_uikitopengles.m
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/video/uikit/SDL_uikitopenglview.h
Expand Up @@ -60,6 +60,7 @@
bBits:(int)bBits
aBits:(int)aBits
depthBits:(int)depthBits
stencilBits:(int)stencilBits
majorVersion:(int)majorVersion;

- (void)updateFrame;
Expand Down
45 changes: 27 additions & 18 deletions src/video/uikit/SDL_uikitopenglview.m
Expand Up @@ -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 */
Expand All @@ -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])) {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 17dafb3

Please sign in to comment.