帧缓冲区对象 (FBO) 和渲染与渲染深度缓冲区关系
我在网上看到了很多示例(例如),它们执行以下
- 创建和绑定 FBO
- 创建并绑定缓冲区(纹理、渲染、深度、模板)
- 然后,取消绑定缓冲区
- 要使用 FBO - 绑定 FBO,请执行以下操作取消绑定 FBO
- 但是,还使用纹理缓冲区绑定纹理缓冲区以进行读取、写入等
- 但从未见过重新绑定其他缓冲区(渲染、深度、模板),为什么?
缓冲区创建和绑定的示例/unbind (下面的代码仅作为示例,仅用于展示我所解释的内容并且完美运行),
// create a framebuffer object, you need to delete them when program exits.
glGenFramebuffersEXT(1, &fboId);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fboId);
// create color buffer object and attached to fbo
glGenRenderbuffersEXT(1, &rboId);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, rboId);
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGB, TEXTURE_WIDTH, TEXTURE_HEIGHT);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0); //UnBind
if(useDepthBuffer) {
glGenRenderbuffersEXT(1, &rboIdDepth);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, rboIdDepth);
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, TEXTURE_WIDTH, TEXTURE_HEIGHT);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0); //UnBind
}
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, rboId);
if(useDepthBuffer)
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, rboIdDepth);
// check FBO status
printFramebufferInfo();
bool status = checkFramebufferStatus();
if(!status)
fboUsed = false;
.
//then,
.
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fboId);
// Do the work
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
1。为什么我们不需要再次绑定所有缓冲区(我的意思是同时 使用/绘制对象 FBO)?
2.这里到底发生了什么?
编辑: Attach->绑定和解除连接->解绑
I saw many examples on the web (for example) which do the following
- Create and Bind FBO
- Create and Bind BUFFERS (texture, render, depth, stencil)
- Then, UnBind BUFFERS
- To work with FBO- Bind FBO, do the work then UnBind FBO
- However, also Bind texture BUFFER for read, write etc. with texture BUFFER
- BUT NEVER EVER SEEN re-Bind of other BUFFERS (render, depth, stencil), Why?
Example of BUFFERS creation and bind/unbind (Below code is just for example only to show what I explained and works perfectly),
// create a framebuffer object, you need to delete them when program exits.
glGenFramebuffersEXT(1, &fboId);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fboId);
// create color buffer object and attached to fbo
glGenRenderbuffersEXT(1, &rboId);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, rboId);
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGB, TEXTURE_WIDTH, TEXTURE_HEIGHT);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0); //UnBind
if(useDepthBuffer) {
glGenRenderbuffersEXT(1, &rboIdDepth);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, rboIdDepth);
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, TEXTURE_WIDTH, TEXTURE_HEIGHT);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0); //UnBind
}
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, rboId);
if(useDepthBuffer)
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, rboIdDepth);
// check FBO status
printFramebufferInfo();
bool status = checkFramebufferStatus();
if(!status)
fboUsed = false;
.
//then,
.
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fboId);
// Do the work
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
1. Why dont we need to bind all the BUFFERS again (I mean while
working-with/drawing-objects-to
FBO)?
2. What is going on under-the-hood here?
EDIT: attach-> Bind and deattach-> UnBind
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不知道我是否完全理解你的意思,但是绑定到附着点(
GL_COLOR_ATTACHMENT
...)的渲染缓冲区是每个FBO状态,并且这个FBO状态保持不变,你只需要绑定FBO告诉 OpenGL 该 FBO 现在已被使用,并且其所有状态(您之前设置的)都将生效。I don't know if I completely understood you, but the renderbuffers bound to the attachment points (
GL_COLOR_ATTACHMENT
...) are per-FBO state and this FBO state remains unchanged you only need to bind the FBO to tell OpenGL that this FBO is now used and all its state (that you set earlier) will take effect.我认为通过
你参考这个
但是这不是分离,这是一个解除绑定,这意味着不同的东西。渲染缓冲区仍然附加到 FBO。然而,绑定会选择要对其执行以下缓冲区对象操作的缓冲区对象。它有点像某些语言中的
with
语句。缓冲区对象的实际附加(不必绑定)发生在这里
它将被匹配的分离
I think by
You refer to this
However this is not a detach, this is a unbind, which means something different. The renderbuffer is still attached to the FBO. The binding however selects the buffer object on which the following buffer object operations are to be performed on. It's kinda like the
with
statement found in some languages.The actual attaching of a buffer object, that doesn't have to be bound, happens here
It would be detached by a matching