Reputation: 25
I am trying to find a way to set the value of a single element within an array of vec3's. All I can find are ways to write the whole array or a few elements from the start. The problem is that I can't find a way to offset the "address" it's writing to ( I am used to C++ ).
The reason I want to do this is that I have an array of lights with certain variables in my fragment shader. But I want to flag my light's dirty and only send new data to the shader when it has been changed. So when I change light number 4's position, I want to change u_LightPos[3] value.
Fragment Shader:
const int MAX_LIGHTS = 6;
uniform vec3 u_LightPos[MAX_LIGHTS];
OpenGL ES 2.0 (Java, android platform ):
int LightPos = GLES20.glGetUniformLocation(ShaderProgram, "u_LightPos");
GLES20.glUniform3fv(LightPos, 3, m_aLightPos, 0 );
The glUniform3fv function does have a count and offset parameter, but the offset is used for the offset of the array you are reading from, not the shader's array you are writing to.
Upvotes: 0
Views: 2294
Reputation: 56407
You can do this:
int loc = GLES20.glGetUniformLocation(ShaderProgra, "u_LightPos[3]");
GLES20.glUniform3fv(LightPos, 3, m_aLightPos, 0 );
Each element of the array has a individual location, and this applies to structs as well. You can read more about this here
Upvotes: 2