Reputation: 1551
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)
Upvotes: 4
Views: 3502
Reputation: 473272
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.
Upvotes: 5