【问题标题】:GLKView with stencil buffer's glDrawElements results in black screen带有模板缓冲区的 glDrawElements 的 GLKView 导致黑屏
【发布时间】:2017-02-16 01:50:17
【问题描述】:

我有一个使用 GLKViewController 的 iOS 应用程序,我将渲染缓冲区设置如下:

里面 @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];
}

但是,当我稍后调用 draw 时:

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

它会导致黑屏,在Capture GPU Frame 时,会出现此错误:

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

我有什么遗漏的吗?

我记得之前由于深度测试遇到过同样的问题,我用viewDidLoad 上的view.drawableDepthFormat = GLKViewDrawableDepthFormat24; 修复它我不确定模板测试,Apple 的文档要么非常少要么非常笼统,到处都是理论(即:几乎没用)。

【问题讨论】:

    标签: ios opengl-es glkit glkview


    【解决方案1】:

    我找到了罪魁祸首,

    当我渲染到纹理时,我丢失了 GLKView 已经设置的原始 FBO-ID:

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

    然后,当我尝试重置为原始 FBO-ID 时:

    GLint defaultFBO;
    glGetIntegerv(GL_FRAMEBUFFER_BINDING, &defaultFBO);
    

    这里defaultFBO是之前生成的m_nFboId的值。所以解决方法是要么在操作前备份,要么回调[GLKView bindDrawable];

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-13
      • 1970-01-01
      • 1970-01-01
      • 2020-04-19
      相关资源
      最近更新 更多