Discussion:
glGetUniformLocation for sampler2dArray returns -1
(too old to reply)
Cathy L.
2013-09-17 14:45:11 UTC
Permalink
Hello
For multitexturing, here is my vertex shader:

---------------------------------
#version 330

uniform mat4 ModelViewProjectionMatrix;
in vec3 VertexPosition;
in vec2 ColorTexCoord;
in vec2 AlphaTexCoord;
out vec2 oColorTexCoord;
out vec2 oAlphaTexCoord;

invariant gl_Position;

void main(void)
{
oColorTexCoord=ColorTexCoord;
oAlphaTexCoord=AlphaTexCoord;
gl_Position=ModelViewProjectionMatrix*vec4(VertexPosition,1.0);
}
---------------------------------

and here is the fragment shader:

---------------------------------
#version 330
in vec2 oColorTexCoord;
in vec2 oAlphaTexCoord;
out vec4 FColor;
uniform sampler2DArray ColTex;
uniform sampler2DArray AlpTex;
uniform int nlayers;

void main(void)
{
vec3 t3dc=vec3(oColorTexCoord,floor(0.5));
vec4 color=texture(ColTex,t3dc);
vec4 alpha;
int i;

for (i=1;i<nlayers;i++)
{
t3dc=vec3(oAlphaTexCoord,floor(i-1+0.5));
alpha=texture(AlpTex,t3dc);
if (alpha.r>0.09)
{
t3dc=vec3(oColorTexCoord,floor(i+0.5));
if (alpha.r>0.91) color=texture3D(ColTex,t3dc);
else color=color*(1-alpha.r)+texture(ColTex,t3dc)*alpha.r;
}
}

FColor=color;
}
---------------------------------

The compilation works but when I get the indices this way:

---------------------------------
*pshp=gl33_InitShader("heightmap.vsh","heightmap.fsh");
if (*pshp==(unsigned int)-1) return FALSE;
glUseProgram(*pshp);
hm_uicol=glGetUniformLocation(*pshp,"ColTex");
hm_uialp=glGetUniformLocation(*pshp,"AlpTex");
hm_uinlayers=glGetUniformLocation(*pshp,"nlayers");
hm_uimMVP=glGetUniformLocation(*pshp,"ModelViewProjectionMatrix");
hm_uivpos=glGetAttribLocation(*pshp,"VertexPosition");
hm_uivtcol=glGetAttribLocation(*pshp,"ColorTexCoord");
hm_uivtalp=glGetAttribLocation(*pshp,"AlphaTexCoord");
glUseProgram(0);
---------------------------------

hm_uicol and hm_uialp return -1 when all others give an index>=0.

Could somebody tell me where is the problem?

Thanks a lot
Cathy L.
Nobody
2013-09-18 02:30:57 UTC
Permalink
Post by Cathy L.
Could somebody tell me where is the problem?
Check the info logs from compiling and linking. It should at least warn
you about using texture3D() with a sampler2DArray.

I note that ColTex and AlpTex are only used by the fragment shader
(although the same is also true of nlayers, so I would expect that to
return -1 if the fragment shader fails to compile).
Cathy L.
2013-09-18 07:46:08 UTC
Permalink
Post by Nobody
Post by Cathy L.
Could somebody tell me where is the problem?
Check the info logs from compiling and linking. It should at least warn
you about using texture3D() with a sampler2DArray.
Hello

Sorry, it was a change I made to try to fix it but didn't recompile
after. I check for info logs, so I should have sent the right one with
texture() and not texture3D(). So I change back with texture() and the
compilation is ok. But the problem is still the same.
Post by Nobody
I note that ColTex and AlpTex are only used by the fragment shader
(although the same is also true of nlayers, so I would expect that to
return -1 if the fragment shader fails to compile).
So should I use ColTex and AlpTex in the vertex shader? How and what
for? I need it to:

glUniform1i(hm_uicol, 0); //associate with glActiveTexture(GL_TEXTURE0+0)
glUniform1i(hm_uialp, 1); //associate with glActiveTexture(GL_TEXTURE0+1)


Thanks for your help
Cathy L.
Nobody
2013-09-19 00:35:02 UTC
Permalink
Post by Cathy L.
So should I use ColTex and AlpTex in the vertex shader?
No, you should ensure that all shaders compile without error, the program
links without error, and that the fragment shader is actually being
linked into the program.

The compiler will remove variables which aren't actually required (e.g. if
you comment-out a section of code for testing, that often results in
variables no longer affecting the output, and the variables get deleted;
it doesn't matter whether the variables are still referenced in live code
if the values they are used to compute aren't used).

However, that isn't the case for the code you posted, as ColTex definitely
affects the output, and AlpTex will if nlayers >= 1.

So if those variables aren't present in the program, either there was an
error, or the fragment shader isn't being linked into the program, or
you're using the wrong program, or something.

Loading...