glBlitFramebuffer如何工作

时间:2013-05-09 15:05:10

标签: opengl

    GLuint32                fbo[2];
    GLuint32                rbo[2];
    GLuint32                texture[2];

    glGenFramebuffers       (2, fbo);
    glGenTextures           (2, texture);
    glGenRenderbuffers      (2, rbo);

    glBindTexture           (GL_TEXTURE_2D, texture[0]);
    glBindRenderbuffer      (GL_RENDERBUFFER, rbo[0]);
    glBindFramebuffer       (GL_READ_FRAMEBUFFER, fbo[0]);

    glTexImage2D            (GL_TEXTURE_2D, 0, GL_RGBA8, 32, 32, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
    glRenderbufferStorage   (GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 32, 32);
    glFramebufferTexture2D  (GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture[0], 0);
    glFramebufferRenderbuffer(GL_READ_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, rbo[0]);
    glCheckFramebufferStatus(GL_READ_FRAMEBUFFER);

    glBindTexture           (GL_TEXTURE_2D, texture[1]);
    glBindRenderbuffer      (GL_RENDERBUFFER, rbo[1]);
    glBindFramebuffer       (GL_DRAW_FRAMEBUFFER, fbo[1]);

    glTexImage2D            (GL_TEXTURE_2D, 0, GL_RGBA8, 32, 32, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
    glRenderbufferStorage   (GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 32, 32);
    glFramebufferTexture2D  (GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture[1], 0);
    glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, rbo[1]);
    glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER);

稍后在我的代码中,

    glBindTexture           (GL_TEXTURE_2D, texture[0]);
    glTexImage2D            (GL_TEXTURE_2D, 0, GL_RGBA32UI, 32, 32, 0, GL_RGBA_INTEGER, GL_UNSIGNED_INT, NULL);
    glFramebufferTexture2D  (GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture[0], 0);

读取缓冲区格式和写入缓冲区格式相同,其中预期的是:读取缓冲区:GL_RGBA32UI,绘制缓冲区:GL_RGBA

然而,当我这样做时(删除glBindTexture)

glTexImage2D            (GL_TEXTURE_2D, 0, GL_RGBA32UI, 32, 32, 0, GL_RGBA_INTEGER, GL_UNSIGNED_INT, NULL);
glFramebufferTexture2D  (GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture[0], 0);
glBlitFramebuffer       (0, 0, 16, 16, 0, 0, 16, 16, GL_COLOR_BUFFER_BIT, GL_NEAREST);

我得到了预期的结果。我在这里错过了什么?有人可以帮我理解这是如何运作的。

0 个答案:

没有答案