Search code examples
opengltexturestexture-mapping

Attaching particular layer in GL_2D_ARRAY_TEXTURE to framebuffer


I have a texture with target GL_TEXTURE_2D_ARRAY. I want to render to each layer separately as FBO attachment. how do i bind particular layer to framebuffer as attachment?


Solution

  • Use the glFramebufferTextureLayer function to attach the texture layer to the FBO.

    glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, someTexture, mipmapLevel, layer);
    

    Alternatively, use the gl_Layer variable in a geometry shader to select at render time which layer to render to.