如何定义将纹理数组附加到FBO的颜色附着点?

时间:2013-08-17 08:42:27

标签: opengl textures glsl framebuffer

我在分层渲染中读到,我们创建了一个2D纹理数组(GL_TEXTURE_2D_ARRAY):

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

并可以将其附加到FBO:

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

我觉得难以理解的是,如何将一层纹理绑定到FBO中的单个颜色附着点?非颜色附件0(或任何GL_COLOR_ATTACHMENTi)本身就是一个“图像”吗?

更详细:

在阅读纹理数组之前,这是我对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)

但是在阅读了纹理数组后,这是真的吗?

                          +--------------+
             +-----------+| 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]|
  |                |  |                 |            |                |
  |                |  |                 |            |                |
  |                |  |                 |            |                |
  +----------------+  +-----------------+            +----------------+

即每个附件本身是各种纹理的集合?

我很难想象出1个颜色附着点如何映射到多个纹理。

如果我从1个FBO(一个绑定到texture_2d_array)到另一个(一个绑定到texture_2d)的blit会发生什么?

1 个答案:

答案 0 :(得分:3)

纹理是图像的集合。您没有将纹理附加到FBO附加点;您将 纹理中的图像附加到FBO附加点。

因此,您不会将多个纹理附加到单个附着点。

Array textures只是在mipmap级别存储图像数组的纹理。非数组2D纹理仅在每个mipmap级别存储一个图像。立方体贴图每个mipmap存储6个图像。数组纹理存储每个mipmap的用户提供的图像数量。

但是,您可以将layered image附加到附件点。 array texture的mipmap级别是分层图像,还有其他一些内容。

通过分层图像构建的FBO可以通过几何着色器用于layered rendering。这允许GS将特定的基元输出传递给分层FBO中的特定层索引。

您如何想象这取决于您。

相关问题