PDA

View Full Version : Problem with texture arrays



tonyo_au
04-28-2012, 02:51 AM
I am having a probelm with some shader code using a texture array.

If I create a texture with the follwoing


glBindTexture(GL_TEXTURE_2D, c_Textures[RESOLVE]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, GLsizei(c_Width), GLsizei(c_Height),GL_FALSE,GL_RGBA,GL_UNSIGNED_INT ,0);
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, c_Textures[RESOLVE], 0);


I can add 2 textures together with


#version 420 core
layout(location = 0, index = 0) out vec4 fFragColour;

uniform sampler2DMS u_BackgroundTexture;
uniform sampler2D u_ResolvedColourTexture;


void main()
{
ivec2 pos2d = ivec2(gl_FragCoord.xy);

vec4 background = texelFetch(u_BackgroundTexture,pos2d, gl_SampleID);
vec4 transparentColor = texelFetch(u_ResolvedColourTexture,pos2d,0);

background += transparentColor;
fFragColour = background;
}




If I convert it to a texture array


glBindTexture(GL_TEXTURE_2D_ARRAY, c_Textures[RESOLVE]);
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage3D(
GL_TEXTURE_2D_ARRAY,
0,
GL_RGBA16F,
GLsizei(c_Width),
GLsizei(c_Height),
GLsizei(c_Layers), //depth
0,
GL_RGBA,
GL_FLOAT,
NULL);




#version 420 core
layout(location = 0, index = 0) out vec4 fFragColour;

uniform sampler2DMS u_BackgroundTexture;
uniform sampler2DArray u_ResolvedColourTexture;

void main()
{
ivec2 pos2d = ivec2(gl_FragCoord.xy);

vec4 background = texelFetch(u_BackgroundTexture,pos2d, gl_SampleID);
vec4 transparentColor = texelFetch(u_ResolvedColourTexture,ivec3(pos2d, 0),0);

background += transparentColor;
fFragColour = background;
}


this code generates an opengl invalid operation error

I can display both textures separately; it is only a problem when I try to combine them with some function