lwjgl3 uniform array not working

Started by Farion, April 08, 2015, 15:46:13

Previous topic - Next topic

Farion

Hello,

I am quite new to lwjgl3 and have a little issue. I am trying to load an array of vectors to my fragment shader but unfortunately only the first entry of the array receives input and i have no clue what I am doing wrong. Accessing other uniforms / attributes is working fine but i cant access arrays. The shader compiles and links without any errors.

This is my test shader:

#version 400 core

out vec4 out_Color;

uniform vec3 mycolors[4];

void main(void)
{
    out_Color = vec4(mycolors[0], 1.0); /*works*/
    /*out_Color = vec4(mycolors[1], 1.0); not working*/
    /*out_Color = vec4(mycolors[2], 1.0); not working*/
    /*out_Color = vec4(mycolors[3], 1.0); not working*/
}


I can only access mycolors[0] no other array values. I tried to access each location manually by glGetUniformLocation(program, mycolors); but all i get is the location for mycolors[0] ([1-3] return for location -1).
So i tried to load the uniform data with a floatbuffer to mycolors[0] but I get the same result only slot 0 has a value:

FloatBuffer floatBuffer = BufferUtils.createFloatBuffer(12);
floatBuffer.put(new float[]{1,0, 1, 1,0, 1, 1,0, 1, 1, 0, 1});
floatBuffer.flip(); /otherwise [0] has the wrong color*/
glUniform3(location, floatBuffer);


Could someone please give me a hint what i am doing wrong?

Kai

I cannot reproduce this.
GL20.glUniform3(int, FloatBuffer) works fine for me here and correctly uses glUniform3fv with a correct 'count' argument of the number of vec3 instances in the buffer.
I pushed a demo to the git-repository to showcase this:
Java source: https://github.com/LWJGL/lwjgl3/blob/master/src/tests/org/lwjgl/demo/opengl/UniformArrayDemo.java
Vertex shader: https://github.com/LWJGL/lwjgl3/blob/master/res/demo/uniformarray-vs.glsl
Fragment shader: https://github.com/LWJGL/lwjgl3/blob/master/res/demo/uniformarray-fs.glsl

You can cycle through the colors (index into the array) via the up/down keyboard keys. Does this work for you? If so, you probably have some other issue.