0

I have an iOS app that uses GLKViewController and I set up the render buffer as follows:

inside @interface RootViewController : GLKViewController<UIKeyInput>

- viewDidLoad {
    [super viewDidLoad];

    _context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];

    GLKView* view = (GLKView*)self.view;
    view.context = _context;
    view.drawableColorFormat = GLKViewDrawableColorFormatRGBA8888;
    view.drawableDepthFormat = GLKViewDrawableDepthFormat24;
    view.drawableStencilFormat = GLKViewDrawableStencilFormat8;
    view.drawableMultisample = GLKViewDrawableMultisampleNone;
    self.preferredFramesPerSecond = 60;

    [EAGLContext setCurrentContext:_context];
}

However, when I call draw later:

glDrawElements(getGlPrimitiveType(ePrimType), numIndis, GL_UNSIGNED_SHORT, startIndis);

It results in black screen and upon Capture GPU Frame, this error shows up:

Your app rendered with STENCIL_TEST enabled into a framebuffer without an attached stencil buffer.

Is there anything that I missed?

I remembered having the same problem before due to depth testing, and I fix it with the view.drawableDepthFormat = GLKViewDrawableDepthFormat24; on viewDidLoad I am not sure about stencil testing, Apple's documentation is either very minimal or very general with theories all around (i.e: pretty much useless).

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
Zennichimaro
  • 5,236
  • 6
  • 54
  • 78

1 Answers1

0

I found the culprit,

I've lost the original FBO-ID already setup by GLKView when I do render to texture:

uint m_nFboId;
glGenFramebuffers(1, &m_nFboId);
glBindFramebuffer(GL_FRAMEBUFFER, m_nFboId);

then, when I try to reset back to the original FBO-ID:

GLint defaultFBO;
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &defaultFBO);

here, the defaultFBO is the value of m_nFboId generated before.. So the solution is to either back it up before the operation, or call back [GLKView bindDrawable];

Zennichimaro
  • 5,236
  • 6
  • 54
  • 78