FBO in iOS - stencil buffer

Hello,

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.


OF: OF_LOG_ERROR: FRAMEBUFFER_UNSUPPORTED

I changed the line in ofFBO allocate function.

settings.useStencil = true;
to
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();  
scratchFBO->allocate(settings);  
  

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 )  
	{  
#ifndef TARGET_OPENGLES  
		stencilBuffer = depthBuffer = createAndAttachRenderbuffer(GL_DEPTH_STENCIL, GL_DEPTH_STENCIL_ATTACHMENT);  
#else  
        stencilBuffer = depthBuffer = createAndAttachRenderbuffer(GL_DEPTH_STENCIL, GL_DEPTH_ATTACHMENT);  
          
        glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, stencilBuffer);  
#endif  
		retainRB(depthBuffer);  
		retainRB(stencilBuffer);  
	}else  
[...]  
  

COOL!
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