Read image data from GL_TEXTURE_2D_ARRAY

Is it possible to read the pixel data from GL_TEXTURE_2D_ARRAY? I’ve binded the image before with glBindTexture(GL_TEXTURE_2D_ARRAY, frameIn.DepthTexture) and I wanted to read the pixel data as an array. I’ve tried functions like glReadPixels or glTexSubImage3D but they don’t seem to work, and I’m wondering either if I’m doing something wrong or it’s not possible at all.

glReadPixels requires that the appropriate layer of the texture is bound to the current read buffer (see glFramebufferTextureLayer and glReadBuffer). If you bind an entire 2D array texture to create a layered framebuffer, glReadPixels reads from layer 0; there is no way to select a different layer for reading.

glTexSubImage3D copies data from client memory (or a buffer bound to the GL_PIXEL_UNPACK_BUFFER target) into a texture. To read data out of a texture, you need to use glGetTexImage, glGetnTexImage, glGetTextureImage or glGetTextureSubImage. The first three read the entire image; the last one reads an arbitrary region. glGetTextureImage and glGetTextureSubImage require OpenGL 4.5.

1 Like