0

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.

0

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.