创建一个OpenGL FBO并将颜色缓冲区和模板缓冲区绑定到它。
glCheck(glBindFramebuffer(GL_FRAMEBUFFER, fbo));
// Delete old framebuffers if ever created.
if ( clrRbo != 0)
glDeleteRenderbuffers(1, & clrRbo);
if ( stencilRbo != 0)
glDeleteRenderbuffers(1, & stencilRbo);
// Create new framebuffers with new size.
int maxSize; glGetIntegerv(GL_MAX_RENDERBUFFER_SIZE, &maxSize);
glCheck(glGenRenderbuffers(1,&clrRbo));
glCheck(glBindRenderbuffer(GL_RENDERBUFFER,clrRbo));
glCheck(glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA, (std::min)(maxSize,m_localvp.pix_width),(std::min)(maxSize, m_localvp.pix_height)))
glCheck(glGenRenderbuffers(1,&stencilRbo));
glCheck(glBindRenderbuffer(GL_RENDERBUFFER,stencilRbo));
glCheck(glRenderbufferStorage(GL_RENDERBUFFER, GL_STENCIL_INDEX, (std::min)(maxSize,m_localvp.pix_width),(std::min)(maxSize, m_localvp.pix_height)))
// Bind new framebuffers to FBO;
glCheck(glBindFramebuffer(GL_FRAMEBUFFER, fbo));
glCheck(glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, clrRbo));
glCheck(glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, stencilRbo));
困扰我的问题在于:
glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA, (std::min)(maxSize,m_localvp.pix_width),(std::min)(maxSize, m_localvp.pix_height))
当使用不同的内部格式时,此调用失败(获取GL_INVALID_OPERATION错误),这导致创建FBO失败。有些机器适用于GL_RGBA,有些适用于GL_RGBA8,有些适用于两者。 GL_RGBA8和GL_RGBA之间有什么区别。我怎么能弄清楚当前机器支持哪种格式?