1
votes

If I bind individual layers of a texture array (GL_TEXTURE_2D_ARRAY) to different color attachment points (e.g I am binding the 4 layers of texture array 'textureName' to color attachments 0,1,2 and 3):

glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + 0, textureName, 0, 0);
glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + 1, textureName, 0, 1);
glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + 2, textureName, 0, 2);
glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + 3, textureName, 0, 3);

And in the geometry shader , I use gl_Layer to assign vertices to different layers. (I am just duplicating geometry)

2 Followup questions:

Case 1: My Fragment shader writes to only first color buffer. (location = 0.)

What do the 4 layers of texture array contain at end of the program execution? Did geometry duplication occur (because of using gl_Layer) or the last 3 textures are blank(because I did not write to other color buffers in fragment shader)?

Case 2: I write to all 4 color buffers in the fragment shader (location = 0, 1, 2, 3)

What do the 4 layers of texture array contain at end of the program execution?

By these 2 cases, I am trying to understand if layered rendering has any impact on multiple render targets.

1

1 Answers

1
votes

In either case, you invoke undefined behavior because gl_Layer is out of bounds. Therefore the contents of any of the attachments is undefined. It may be anything, most likely the clear color.

If you own a copy of 8th edition of "The Red Book", see pages 556 to 558.

The reason is that you do not use layered rendering at all. What glFramebufferTextureLayer(..., n) is doing is bind a single layer of an array texture.

You're doing this 4 times, binding 4 single layers of one texture (but that's irrelevant, this could as well be 4 individual, normal textures) to 4 attachments, unlayered. You need glFramebufferTexture, not glFramebufferTextureLayer.

On the other hand, you're writing 4 different values to gl_Layer when in reality there is only one layer.