4

I read that in layered rendering, we create a 2D texture array (GL_TEXTURE_2D_ARRAY):

glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D_ARRAY, TextureColorbufferName);
glTexParameteri(....
glTexImage3D(...

and can attach it to FBO:

glGenFramebuffers(1, &FramebufferName);
glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName);
glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, TextureColorbufferName, 0);

What i find hard to understand visually is how can a layer of textures be bound to a single color attachment point in FBO? Isnt color attachment 0 (or any of GL_COLOR_ATTACHMENTi ) a single "image" in themselves?

In more detail:

Before reading about texture arrays, this was my understanding of FBOS

                      +--------------+
         +-----------+| FBO object   ++--------------------------------------------+
         |            |              +---------------------+                       |
         |            +--------------+                     |                       |
         |                     +                           |                       |
         |                     |                           |                       |
         |                     |                           |                       |
         v                     v                           v                       v
 +-----------------+     +-----------------+      +-----------------+       +------------------+
 |color attachment |     |color attachment |      |depth attachment |       |stencil attachment|
 |    0            |     |   1             |      |                 |       |                  |
 +-----------------+     +-----------------+      +-----------------+       +------------------+
                                                                               (this too)
  (this is actually        (this is also a                (this too)
   one texture or          texture of renderbuffer)
    one renderbuffer)

But after reading about texture arrays, is this how it really is?

                          +--------------+
             +-----------+| FBO object   ++--------------------------------------------+
             |            |              +---------------------+                       |
             |            +--------------+                     |                       |
             |                     +                           |                       |
             |                     |                           |                       |
             |                     |                           |                       |
             v                     v                           v                       v
     +-----------------+     +-----------------+      +-----------------+       +------------------+
     |color attachment |     |color attachment |      |depth attachment |       |stencil attachment|
     |    0            |     |   1             |      |                 |       |                  |
     +-----+--+------+-+     +-----------------+      +-----------------+       +------------------+
           |  |      |
           |  |      v+
           |  v+      +----------------------------------+
           |   +--------->+                              v
           v              |                              +
  +----------------+  +---v-------------+                |
  |                |  |                 |            +---v------------+
  |texture array[0]|  |texture array[1] |            |texture array[n]|
  |                |  |                 |            |                |
  |                |  |                 |            |                |
  |                |  |                 |            |                |
  +----------------+  +-----------------+            +----------------+

i.e is each attachment itself a collection of various textures?

This is hard for me to visualize how 1 color attachment point maps to multiple textures.

What happens if i blit from 1 FBO (one that is bound to texture_2d_array) to another(one that is bound to texture_2d)

viktorzeid
  • 1,521
  • 1
  • 22
  • 35
  • I don't really understand the question. It works because OpenGL defines that it *does work*. What goes into a framebuffer binding point is exactly what OpenGL *says* goes in one. – Nicol Bolas Aug 17 '13 at 08:56
  • I edited my questioon with more detail. Thanks – viktorzeid Aug 17 '13 at 09:14

1 Answers1

5

A texture is a collection of images. You do not attach a texture to an FBO attachment point; you attach an image within the texture to an FBO attachment point.

So at no point do you attach multiple textures to a single attachment point.

Array textures are just textures that store an array of images within a mipmap level. A non array 2D texture only stores one image per mipmap level. A cubemap stores 6 images per mipmap. An array texture stores a user-provided number of images per mipmap.

However, you can attach a layered image to an attachment point. A mipmap level of an array texture is a layered image, as are several other things.

An FBO that is built from layered images can be used for layered rendering via a Geometry Shader. This allows the GS to pipe a particular primitive output to a specific layer index within the layered FBO.

How you visualize this is up to you.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
  • 1
    @Nicol.As you pointed out [this link](https://www.opengl.org/wiki/Framebuffer_Object#Layered_Images) is also a very good explanation. Thank you. – viktorzeid Aug 17 '13 at 16:18
  • 1
    After a lot of reading and trial-and-error, I finally solved this with `glFramebufferTextureLayer`. I was originally trying to bind the array texture with `glFramebufferTexture3D`. Leaving this here in case it helps someone. – Dan Bechard Aug 13 '20 at 12:14