Permalink
Browse files

Added depth buffer

  • Loading branch information...
1 parent 2636692 commit 9cf8d7807600b000e578ee540c7491685e0990a6 Edward Patel committed Mar 14, 2010
Showing with 24 additions and 4 deletions.
  1. +1 −0 src/EPGLTransitionView.h
  2. +23 −4 src/EPGLTransitionView.m
View
@@ -61,6 +61,7 @@
GLuint defaultFramebuffer;
GLuint colorRenderbuffer;
+ GLuint depthRenderbuffer;
GLuint textureFromView;
GLuint textureToView;
View
@@ -101,15 +101,23 @@ - (id)initWithView:(UIView*)view
glGenFramebuffersOES(1, &defaultFramebuffer);
glGenRenderbuffersOES(1, &colorRenderbuffer);
+ glGenRenderbuffersOES(1, &depthRenderbuffer);
glBindFramebufferOES(GL_FRAMEBUFFER_OES, defaultFramebuffer);
glBindRenderbufferOES(GL_RENDERBUFFER_OES, colorRenderbuffer);
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES,
GL_COLOR_ATTACHMENT0_OES,
GL_RENDERBUFFER_OES,
- colorRenderbuffer);
-
+ colorRenderbuffer);
+ glBindRenderbufferOES(GL_RENDERBUFFER_OES, depthRenderbuffer);
+ glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES,
+ GL_DEPTH_ATTACHMENT_OES,
+ GL_RENDERBUFFER_OES,
+ depthRenderbuffer);
+
glViewport(0, 0, size.width, size.height);
+ glEnable(GL_DEPTH_TEST);
+
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glScalef(size.width/512.0, size.height/512.0, 1.0); // Convert to screen part of the 512x512 texture
@@ -245,6 +253,12 @@ - (void) dealloc
colorRenderbuffer = 0;
}
+ if (depthRenderbuffer)
+ {
+ glDeleteRenderbuffersOES(1, &depthRenderbuffer);
+ depthRenderbuffer = 0;
+ }
+
if ([EAGLContext currentContext] == context)
[EAGLContext setCurrentContext:nil];
@@ -264,7 +278,7 @@ - (BOOL) render
clearColor[1],
clearColor[2],
clearColor[3]);
- glClear(GL_COLOR_BUFFER_BIT);
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, textureFromView);
@@ -284,7 +298,12 @@ - (BOOL) resizeFromLayer:(CAEAGLLayer *)layer
glBindRenderbufferOES(GL_RENDERBUFFER_OES, colorRenderbuffer);
[context renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:layer];
glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &backingWidth);
- glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &backingHeight);
+ glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &backingHeight);
+ glBindRenderbufferOES(GL_RENDERBUFFER_OES, depthRenderbuffer);
+ glRenderbufferStorageOES(GL_RENDERBUFFER_OES,
+ GL_DEPTH_COMPONENT16_OES,
+ backingWidth,
+ backingHeight);
if (glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES) != GL_FRAMEBUFFER_COMPLETE_OES)
{

0 comments on commit 9cf8d78

Please sign in to comment.