2

I have a IOSurface backed texture which is limited to GL_TEXTURE_RECTANGLE_ARB and doesn't support mipmapping. I'm trying to copy this texture to another texture bound to GL_TEXTURE_2D and then perform mipmapping on that one instead. But I'm having problems copying my texture. I can't even get it to work by just copying it to another GL_TEXTURE_RECTANGLE_ARB. Here is my code:

    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
Oskar
  • 3,625
  • 2
  • 29
  • 37

1 Answers1

0

The arguments of your second glFramebufferTexture2D() do not match your description:

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

Since you're saying that the second texture is a GL_TEXTURE_2D, this needs to be matched by the textarget argument of the call. It should be:

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

BTW, GL_TEXTURE_RECTANGLE is standard in OpenGL 3.1 and later, so there should be no need to use the ARB form.

Reto Koradi
  • 53,228
  • 8
  • 93
  • 133
  • My end goal is a GL_TEXTURE_2D, but that doesn't work either. So I'm reverting to simply copying to another GL_TEXTURE_RECTANGLE_ARB and that doesn't work either. So I'm at a loss. The original target is required to be GL_TEXTURE_RECTANGLE_ARB because the texture is from an IOSurface which can only be represented this way. – Oskar Jul 12 '16 at 18:52