[英]GLKView with stencil buffer's glDrawElements results in black screen
我有一个使用GLKViewController的iOS应用,并按如下所示设置了渲染缓冲区:
在@interface RootViewController : GLKViewController<UIKeyInput>
内部@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.
有什么我想念的吗?
我记得之前由于深度测试而遇到了相同的问题,我使用view.drawableDepthFormat = GLKViewDrawableDepthFormat24;
进行了修复view.drawableDepthFormat = GLKViewDrawableDepthFormat24;
在viewDidLoad
我不确定是否要进行模版测试,Apple的文档非常少,或者非常笼统,包含各种理论(即:几乎没有用)。
我找到了罪魁祸首,
当我渲染到纹理时,我已经失去了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];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.