您可以在同一纹理的不同级别之间使用 glBlitFramebuffer 吗?

Can you glBlitFramebuffer between different levels of the same texture?

假设我有一个纹理需要进行 mipmap,但我希望 mipmap 完成硬件加速。我决定最好的路线是这样的:

    int read = glGenFramebuffers();
    int draw = glGenFramebuffers();
    int wh = 256;
    int glObject = glGenTextures();
    glBindTexture(GL_TEXTURE_2D, glObject);

    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, wh, wh, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);

    for(int i = 0; i < mipLevels; ++i) {
        glBindFramebuffer(GL_FRAMEBUFFER, read);
        glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, glObject, i);
            
        glTexImage2D(GL_TEXTURE_2D, i + 1, GL_RGBA8, wh / 2, wh / 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, (ByeBuffer)null);
        glBindFramebuffer(GL_FRAMEBUFFER, draw);
        glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, glObject, i + 1);
            
        glBindFramebuffer(GL_READ_FRAMEBUFFER, read);
        glBindFramebuffer(GL_DRAW_FRAMEBUFFER, draw);
        glBlitFramebuffer(0, 0, wh, wh, 0, 0, wh / 2, wh / 2,  GL_COLOR_BUFFER_BIT, GL_LINEAR);
            
        wh /= 2;
    }

调用 glCheckFramebufferStatus 时,此代码块中的两个帧缓冲区 return INCOMPLETE_ATTACHMENT。我究竟做错了什么?我是否正确分配了空白 mipmap 级别?

回答:我使用 glTexImage2D 来分配空白 mip 级别,而在这种情况下我应该使用 glTexStorage2D 来分配空白级别。这是 glTexStorage2D 手册页的 link 以了解更多详细信息:https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glTexStorage2D.xhtml