Here is my attemps to pass array to uniform array:
struct Vector{ float x,y,z; }
float threshold[2] = { 0.5, 0.25 };
Vector *kernel = new Vector[_kernel_size]; // _kernel_size==16
// fill kernel
glUniform1fv(glGetUniformLocation(_program, "t"), 2, threshold);
glUniform3fv(glGetUniformLocation(_program, "kernel"), _kernel_size, (const GLfloat*)kernel); // because Vector contains only 3 float fields this kind of casting should be ok
shader:
uniform float t[2];
uniform vec3 kernel[16];
And the results are weird. Only first float or first vector are filled with proper values. For example:
t = {0.5, 7.1830559e-042}
Even when I try change only one value (name = "t[1]") it doesn't work. I checked this on AMD CodeXL.
My graphics card is Radeon HD 5770 and I have the newest drivers. I'm using OpenGL 3.3 and GLSL 330.
What am I doing wrong?
struct Vector{ float x,y,z; }
seems wrong to me. Trystruct Vector {float x; float y; float z;}
– Dan Feb 18 at 6:01value
? Should it bekernel
what you want to pass to the shader? – Dan Feb 18 at 6:03kernel
. I made mistake because I have glUniforms wrapped in functions and I copy, pase and edit this fragment :) I'll try with struct but I tried cast mykernel
toconst float*
and then in0.._kernel_size*3
loop I iterated over this array and values were good. – Harry Feb 18 at 9:03