PDA

View Full Version : Strange problem using #define vs passing uniform



mobeen
02-20-2011, 01:17 AM
Hi all,
I have come across a strange problem. If I define a constant as follows,


#define FUNC_X TILE_X/2.0
#define FUNC_Y TILE_Y/2.0

The code works fine. If I convert the variables to uniform and then pass the uniform from code like this,


//in glsl shader
uniform float FUNC_X;
uniform float FUNC_Y;

//in client code
glUniform1f(glGetUniformLocation(progID, "FUNC_X"), (tileX/2.0f));
glUniform1f(glGetUniformLocation(progID, "FUNC_Y"), (tileY/2.0f));

it does not give the correct output. I even tried changing the #define in the glsl code to this


float FUNC_X=TILE_X/2.0;
float FUNC_Y=TILE_Y/2.0;


and it also gives me the wrong result.
Why do i get this behaviour

kyle_
02-20-2011, 03:02 AM
Wild guess - is your program active when you set the uniforms?
Also, you may want to log with intercept with uniform logging on render call enabled.

mobeen
02-20-2011, 04:17 AM
Wild guess - is your program active when you set the uniforms?
Yes the program is active and the locations of the variables are also fine.


Also, you may want to log with intercept with uniform logging on render call enabled.
I will check this but it really beats me doing the same thing with uniforms or global variable it does not work, however with #define it works fine. I have the latest drivers installed. Any other thing that might be causing this behaviour.