Edit : see @Rabbid76 answer, question was not truly related to GL_TEXTURE_2D_ARRAY, only to framebuffer color attachment activation!
I'm having trouble updating a shader that use to ouput into a single texture to multiple textures. Here's the simplified code, I'll put all I find relevant, feel free to ask for other parts of the code if they are important.
glGenTexture(1, tex);
glBindTexture(GL_TEXTURE_2D_ARRAY, tex);
glTexStorage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA32F, x, y, 2);
glGenFramebuffers(1, &FBO);
glBindFramebuffer(GL_FRAMEBUFFER, FBO);
glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, tex, 0, 0);
glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, tex, 0, 1);
frag shader that writes :
#version 330
layout(location = 0) out vec4 col1;
layout(location = 1) out vec4 col2;
int main()
{
col1 = vec4(1.0);
col2 = vec4(2.0);
}
other shader that uses the result :
#version 330 core
uniform sampler2DArray tex;
in vec2 Coord;
int main()
{
vec4 val = texture(tex, vec3(Coord, 0));
val += texture(tex, vec3(Coord, 1));
}
The problem is that col1
is well written in layout 0
(regardless of texture layer, glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texDefo, 0, 1);
works as well), but I don't get to write in layout 1
(GL_COLOR_ATTACHMENT1
).
Am I missing something here ?
Extensive tests :
From what I could narrow it down to, it really looks like layout(location = 1)
doesn't work how I would have expected. With the code provided I get
- val = col1 when
layout(location = 0) out vec4 col1;
- val = col2 when
layout(location = 0) out vec4 col2;
both regarless which texture layer I did bind theGL_COLOR_ATTACHMENTi
, ie both layers seems to work in theGL_TEXTURE_2D_ARRAY
.