Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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?

share|improve this question
    
This struct struct Vector{ float x,y,z; } seems wrong to me. Try struct Vector {float x; float y; float z;} –  Dan Feb 18 at 6:01
    
Also, what is value? Should it be kernel what you want to pass to the shader? –  Dan Feb 18 at 6:03
    
Yes, it should be kernel. 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 my kernel to const float* and then in 0.._kernel_size*3 loop I iterated over this array and values were good. –  Harry Feb 18 at 9:03

2 Answers 2

I checked another simple project where passing array to uniform works and checked what CodeXL is showing. And again only first value was ok.

So I believe that this is some kind of bug/limited functionality. Maybe name of uniform which CodeXL shows (kernel[0]) is a hint that only first value is presented.

share|improve this answer

Try using glUniform2fv on threshold.

share|improve this answer
    
Result is the same: Active Uniforms: t[0] Type: GL_FLOAT Value: {0,5, 7,1830559e-042} –  Harry Feb 17 at 21:46

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.