I am writing a simple GLSL program in which I am passing an array of ints as a three vector (uniform) into my vertex shader. However I am not able to extract the same values that I am sending into the shader for some reason. If instead of an array, I send the values as uniform scalars into the shaders, it is working fine.
This is how I am binding and sending values from my main code:
int testUniform[3] = {8, 0, 1}; //Declared globally
locUniform = glGetUniformLocation (ShaderProgram, (char *)"center");
glUniform3iv (locUniform, 1, testUniform);
And this is how I am receiving and extracting the values inside my shader:
#version 120
uniform vec3 center;
void Main () {
if (center.x == 8 && center.y == 0 && center.z == 1) {
/*MY CODE*/
}
}
.
The code isn't giving any compiler errors but also not going inside the if statement (hence giving no output).
Can anyone please tell me what I am doing wrong? Thanks in advance.
Uniform variable arrays
Well, if you want to access it like center.x, center.y, you should sent it using
glUniform3i(locUniform, testUniform[0], testUniform[1], testUniform[2]);
Shouldn't it be ivec3?
Also having vec3.xyz has nothing to do with the way you pass the data.
Also having vec3.xyz has nothing to do with the way you pass the data.
The ivec3 did the job! Thanks for that.
However, the problem persists if I pass an array of 1 vectors :
loc1 = glGetUniformLocation (ShaderProgram, (char *)"data");
glUniform1fv (loc1, 25, Data); //Data being an array of 25 floats
And access it in the shader as :
uniform vec1 data[25]; - (i)
OR as,
uniform float data[25]; - (ii)
when I declare it as (i) the compiler gives the following error :
ERROR: 0:9: error(#12) Internal error unexpected qualifier
ERROR: 0:9: error(#132) Syntax error: 'data' parse error
when I declare it (ii), again, no output, but no compiler errors too.
I am at my wits end, could you tell me what's wrong, please?
Thanks in advance.
However, the problem persists if I pass an array of 1 vectors :
loc1 = glGetUniformLocation (ShaderProgram, (char *)"data");
glUniform1fv (loc1, 25, Data); //Data being an array of 25 floats
And access it in the shader as :
uniform vec1 data[25]; - (i)
OR as,
uniform float data[25]; - (ii)
when I declare it as (i) the compiler gives the following error :
ERROR: 0:9: error(#12) Internal error unexpected qualifier
ERROR: 0:9: error(#132) Syntax error: 'data' parse error
when I declare it (ii), again, no output, but no compiler errors too.
I am at my wits end, could you tell me what's wrong, please?
Thanks in advance.
vec1 is not a valid type, so indeed use float.
Not sure why the second variation doesn't work, did you try checking for errors with glGetError()?
Not sure why the second variation doesn't work, did you try checking for errors with glGetError()?
Yes I tried glGetError() but it didn't return any error inside the main program.
@V-man : Even that doesn't work; gives a similar output
@V-man : Even that doesn't work; gives a similar output
It might be a driver bug or the GPU doesn't support integers and it is actually converting the integers to float and thus you end up with a precision problem with floats.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement