共享第二个上下文中的GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT

时间:2016-04-20 17:26:44

标签: opengl textures fbo

我需要在两个OpenGL上下文之间共享颜色/深度/模板缓冲区。 2D纹理附加到缓冲区的framebuffer对象。代码如下所示:

// === Start of context 1
//
Create _hDC1, _hRC1;
wglMakeCurrent(hDC1, hRC1);
glGenFramebuffers(1, &_FBO1);
glBindFramebuffer(GL_FRAMEBUFFER, _FBO1);

// color buffer
glGenTextures(1, &_color1);
glBindTexture(GL_TEXTURE2D, _color1);
glTexParameteri(GL_TEXTURE_2D, ..., ); // GL_TEXTURE_WRAP_S, ..., etc.
glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA16F, 512, 512);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, _color1, 0);

// depth buffer
glGenTextures(1, &_depth1);
glBindTexture(GL_TEXTURE2D, _depth1);
glTexParameteri(GL_TEXTURE_2D, ..., ); // GL_TEXTURE_WRAP_S, ..., etc.
glTexStorage2D(GL_TEXTURE_2D, 1, GL_DEPTH24_STENCIL8, 512, 512);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, _depth1, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_TEXTURE_2D, _depth1, 0);

// check completeness
GLenum  status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
assert(status == GL_FRAMEBUFFER_COMPLETE); // *pass fine here*

// detach _FBO1
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0);
glReadBuffer(GL_NONE);
glDrawBuffer(GL_NONE);
//
// === End of context 1


// === Start of context 2
//
Create _hDC2, _hRC2; // pixel format is same as _hDC1
wglShareLists(_hRC2, hRC1); // share objects between _hRC1 and _hRC2
wglMakeCurrent(_hDC2, _hRC2);

// Create another frame buffer, since it is not sharable
glGenFramebuffers(1, &_FBO2);
glBindFramebuffer(GL_FRAMEBUFFER, _FBO2);

// Use the shared textures for color/depth/stencil buffers
glBindTexture(GL_TEXTURE2D, _color1);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, _color1, 0);
glBindTexture(GL_TEXTURE2D, _depth1);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, _depth1, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_TEXTURE_2D, _depth1, 0);

// check completeness
GLenum  status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
assert(status == GL_FRAMEBUFFER_COMPLETE); // *fail here, status is GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT*
//
// === End of context 2

第二次完整性检查总是失败。

  • 尝试在连接颜色缓冲区后立即移动第二次完整性检查,我也遇到了同样的失败。
  • 还尝试在创建第二个上下文之前取消绑定_color和_depth,但是,它没有帮助。
  • glGetError()是在每次OpenGL调用之后放置的,没有检测到错误。

来自https://www.khronos.org/opengles/sdk/docs/man/xhtml/glCheckFramebufferStatus.xml

  

并非所有帧缓冲附加点都是帧缓冲附件完成。这意味着附加了渲染缓冲区或纹理的至少一个附着点的附加对象不再存在,或者具有宽度或高度为零的附加图像,或者颜色附着点附加了不可着色的图像,或者深度连接点附有非深度可渲染图像,或者模板连接点附有非模板可渲染图像。

无法弄清楚会错过什么。在线检查了几个帖子,但没有一个与我的用例相同。

1 个答案:

答案 0 :(得分:1)

啊哈,我在调用wglShareLists()时搞砸了参数顺序,这应该是:

wglShareLists(_hRC1, hRC2);

现在一切正常。我应该对它进行错误检查。