问题描述
- 创建并绑定FBO
- 创建并绑定缓冲区(纹理,渲染,深度,模具)
- 然后,取消绑定攻击者
- 要与FBO一起使用-绑定FBO,先进行工作,然后取消绑定FBO
- 不过,还可以将纹理缓冲区与纹理缓冲区绑定以便进行读取,写入等
- 从未见过其他装订器(渲染,深度,模版)的重新绑定,为什么?
BUFFERS创建和绑定/解除绑定的示例(下面的代码仅是为了说明我的解释和完美的示例),
// 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.
编辑:附加->绑定并取消附加->取消绑定
我不知道我是否完全了解您,但是绑定到附件点(GL_COLOR_ATTACHMENT
...)的渲染缓冲区是按FBO状态且此FBO状态保持不变,您只需绑定FBO即可告知OpenGL该FBO现在已使用,并且其所有状态(您之前设置的状态)都将生效.
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
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)和渲染深度缓冲区关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!