Jump to content
  • Advertisement
Sign in to follow this  
niteesh

Uniform variable arrays

This topic is 2522 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement
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]);

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!