2017-02-16 122 views
0

模板緩存的glDrawElements結果我有一個使用GLKViewController iOS應用程序,我成立了渲染緩衝如下:GLKView在黑屏

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

然而,當我打電話平局後來:

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.

有什麼,我錯過了什麼?

我記得由於深度測試之前有同樣的問題,我與view.drawableDepthFormat = GLKViewDrawableDepthFormat24;將其固定到viewDidLoad我不知道有關模板測試,蘋果公司的文檔或者是很小的或非常一般以理論四周(即:漂亮很無用)。

回答

0

我找到了罪魁禍首,

我已經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];