OpenGL ES 2.0 Buffer Configuration

I noticed that if I bind the depth buffer in front of the color buffer, the application works as intended:

glGenRenderbuffers(1, &_depthbuffer);
glBindRenderbuffer(GL_RENDERBUFFER, _depthbuffer);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, _sw, _sh);
glGenRenderbuffers(1, &_renderbuffer);
glBindRenderbuffer(GL_RENDERBUFFER, _renderbuffer);
[_context renderbufferStorage:GL_RENDERBUFFER fromDrawable:_eaglLayer];

      

However, binding the depth buffer does not render afterwards, even my setting glClearColor is ignored:

glGenRenderbuffers(1, &_renderbuffer);
glBindRenderbuffer(GL_RENDERBUFFER, _renderbuffer);
[_context renderbufferStorage:GL_RENDERBUFFER fromDrawable:_eaglLayer];
glGenRenderbuffers(1, &_depthbuffer);
glBindRenderbuffer(GL_RENDERBUFFER, _depthbuffer);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, _sw, _sh);

      

I figured out how OpenGL ES 2.0 works by looking closely at the individual components, but it looks like it's the only thing everyone only does in their tutorials / books, but doesn't explain why. Any ideas? Is this even a problem, or maybe something wrong with the rest of my setup? (if so, I'll include all the code)

EDIT

@cli_hlt - the depth buffer is already being added to the framebuffer:

glGenFramebuffers(1, &_framebuffer);
glBindFramebuffer(GL_FRAMEBUFFER, _framebuffer);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, _depthbuffer);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, _renderbuffer);

      

EDIT

Corner border before:

enter image description hereenter image description here

Depth setting after:

enter image description here

+3


source to share


1 answer


I could be completely wrong - I'm just sorting out this stuff myself, but as I understand it, glBind commands only report OpenGL which renderbuffer / texture / any is used for subsequent functions. This is an odd pattern if you're used to object oriented programming. In the template setup code, you need to bind the created buffer to the GL_RENDERBUFFER slot so that the next glRenderbufferStorage () or - [EAGLContext renderbufferStorage: fromDrawable:] call knows which buffer to use. I think the problem is that you are not binding the active GL_RENDERBUFFER to your color buffer before you call - [EAGLContext presentRenderBuffer:], so you are actually showing the depth buffer. Adding

glBindRenderbuffer(GL_RENDERBUFFER, _renderbuffer);

      



before the real RenderBuffer: the call should fix this .... I guess.

+3


source







All Articles