FBO in iOS - stencil buffer


I tried to use ofFbo in iOS4.3 with xcode 4.1 in lion w/ 007 iphone.
but there was a Error message like bellow.


I changed the line in ofFBO allocate function.

settings.useStencil = true;
settings.useStencil = false;

Then it works.

But I think if it is the case that i need stencil buffer, how should i treat these things?

thanks in advance.

Two parts here. I was getting the same error, but you don’t need to change the oF source. Just create your FBO with something like

ofFbo::Settings settings;  
settings.width = 1024;  
settings.height = 1024;  
settings.internalformat = GL_RGB;  
settings.numSamples = 0;  
settings.useDepth = false;  
settings.useStencil = false;  
scratchFBO = new ofFbo();  

That will work fine, but of course there’s still the problem of what to do if you DO want a stencil and depth buffer. I believe the problem is that ofFbo.cpp tries to do separate depth and stencil buffers when building for GLES, but iOS no longer supports that, it wants a single packed depth+stencil buffer. Trouble is, it is setup in a slightly different way to the current non-ES path, there’s no GL_DEPTH_STENCIL_ATTACHMENT in ES.

I’m pretty sure changing ofFbo::allocate(Settings _settings) to include the following is the right fix, but does anyone else want to weigh in? I’m no GL expert.

	// If we want both a depth AND a stencil buffer tehn combine them into a single buffer  
	if( settings.useDepth && settings.useStencil )  
		stencilBuffer = depthBuffer = createAndAttachRenderbuffer(GL_DEPTH_STENCIL, GL_DEPTH_STENCIL_ATTACHMENT);  
        stencilBuffer = depthBuffer = createAndAttachRenderbuffer(GL_DEPTH_STENCIL, GL_DEPTH_ATTACHMENT);  
        glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, stencilBuffer);  

thank you.
it worked fine for my case.

i’m really interesting in a small example how you’re using the fbo as stencil buffer,
i’ve been messing around a bit and inserted that patch from above,
but i can’t get anything to work (also: i have no idea what i’m doing :slight_smile: )

1 Like