2

我有一个 IOSurface 支持的纹理,它仅限于 GL_TEXTURE_RECTANGLE_ARB 并且不支持 mipmapping。我正在尝试将此纹理复制到绑定到 GL_TEXTURE_2D 的另一个纹理,然后在该纹理上执行 mipmapping。但是我在复制我的纹理时遇到了问题。我什至无法通过将其复制到另一个 GL_TEXTURE_RECTANGLE_ARB 来使其工作。这是我的代码:

    var arbTexture = GLuint()
    glGenTextures(1, &arbTexture)

    /* Do some stuff to fill arbTexture with image data */

    glEnable(GLenum(GL_TEXTURE_RECTANGLE_ARB))
    glBindTexture(GLenum(GL_TEXTURE_RECTANGLE_ARB), arbTexture)
    // At this point, if I return here, my arbTexture draws just fine

    // Trying to copy to another texture (fbo and texture generated previously):
    glBindFramebuffer(GLenum(GL_FRAMEBUFFER), fbo);
    glFramebufferTexture2D(GLenum(GL_READ_FRAMEBUFFER), GLenum(GL_COLOR_ATTACHMENT0), GLenum(GL_TEXTURE_RECTANGLE_ARB), arbTexture, 0)
    glFramebufferTexture2D(GLenum(GL_DRAW_FRAMEBUFFER), GLenum(GL_COLOR_ATTACHMENT1), GLenum(GL_TEXTURE_RECTANGLE_ARB), texture, 0)
    glDrawBuffer(GLenum(GL_COLOR_ATTACHMENT1))
    glBlitFramebuffer(0, 0, GLsizei(width), GLsizei(height), 0, 0, GLsizei(width), GLsizei(height), GLbitfield(GL_COLOR_BUFFER_BIT)
        , GLenum(GL_NEAREST))
    glBindTexture(GLenum(GL_TEXTURE_RECTANGLE_ARB), texture)
    // At this point, the texture is all black
4

1 回答 1

0

您的第二个参数glFramebufferTexture2D()与您的描述不符:

glFramebufferTexture2D(
    GLenum(GL_DRAW_FRAMEBUFFER), GLenum(GL_COLOR_ATTACHMENT1),
    GLenum(GL_TEXTURE_RECTANGLE_ARB), texture, 0)

由于您说第二个纹理是 a GL_TEXTURE_2D,因此需要与调用的textarget参数匹配。它应该是:

glFramebufferTexture2D(
    GLenum(GL_DRAW_FRAMEBUFFER), GLenum(GL_COLOR_ATTACHMENT1),
    GLenum(GL_TEXTURE_2D), texture, 0)

顺便说一句,GL_TEXTURE_RECTANGLE在 OpenGL 3.1 及更高版本中是标准的,因此不需要使用 ARB 形式。

于 2016-07-12T04:39:18.910 回答