简体   繁体   English

是否可以将默认帧缓冲区复制到 OpenGL 中的另一个帧缓冲区 object?

[英]is it possible to copy the default framebuffer to another framebuffer object in OpenGL?

I am trying to copy the default framebuffer after rendering on to the screen to another custom framebuffer in OpenGL.我正在尝试将渲染到屏幕后的默认帧缓冲区复制到 OpenGL 中的另一个自定义帧缓冲区。 Below is my code.下面是我的代码。 Do you see anything wrong?你看有什么不对吗? BLit call is successful but I don't see anything rendering. BLit 调用成功,但我没有看到任何渲染。

void drawDisplayList() {

    setNormalDraw();
    clear();
    drawDisplayLists();
    drawDisplayLists();
    
    glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
    glReadBuffer(GL_FRONT);
    glBindFramebuffer(GL_FRAMEBUFFER, geomFBO);
    glBindFramebuffer(GL_DRAW_FRAMEBUFFER, geomFBO);
    glDrawBuffer(GL_COLOR_ATTACHMENT0);
    glBlitFramebuffer(0, 0, _scrWidth, _scrHeight, 0, 0, _scrWidth, _scrHeight, GL_COLOR_BUFFER_BIT, GL_NEAREST);
    GLenum errorCode1;
    errorCode1 = glGetError();
    if (errorCode1 != GL_NO_ERROR) {
        printf("glBlitFramebuffer Success!");
    }

    glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
    glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);

}

My FBO Intialization我的 FBO 初始化

void createFboBuffers()
{
      
    glGenFramebuffers(1, &geomFBO);
    glBindFramebuffer(GL_FRAMEBUFFER, geomFBO);

    glGenRenderbuffers(1, &color_rbo);
    glBindRenderbuffer(GL_RENDERBUFFER, color_rbo);
    glRenderbufferStorage(GL_RENDERBUFFER, GL_RGB, this->size().width(), this->size().height());
    glBindRenderbuffer(GL_RENDERBUFFER, 0);
    glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, color_rbo);

        
    glGenRenderbuffers(1, &depth_rbo);
    glBindRenderbuffer(GL_RENDERBUFFER, depth_rbo);
    glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, _scrWidth, _scrHeight);
    glBindRenderbuffer(GL_RENDERBUFFER, 0);
    glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depth_rbo);
    
 }   
 

Any pointers please.请任何指点。 Looks like Nothing is copied to another FrameBuffer.看起来没有任何内容被复制到另一个 FrameBuffer。

The instruction glBindFramebuffer(GL_FRAMEBUFFER, geomFBO) binds the framebuffer object to both the read and draw framebuffer targets (see glBindFramebuffer ).指令glBindFramebuffer(GL_FRAMEBUFFER, geomFBO)将帧缓冲区 object 绑定到读取和绘制帧缓冲区目标(请参阅glBindFramebuffer )。 This breaks the binding of the default framebuffer to the read framebuffer target.这会破坏默认帧缓冲区与读取帧缓冲区目标的绑定。 Just remove:只需删除:

glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
glReadBuffer(GL_FRONT);
// glBindFramebuffer(GL_FRAMEBUFFER, geomFBO);   <-- DELETE
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, geomFBO);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM