I'm practising animations using bones/skinning. I am trying to send the shader one matrix per vertex. I can think of these two approaches.
Method 1
I have one uniform handle for each bone matrix like this
u_Bone0 = GLES20.glGetUniformLocation(mProgram, "u_Bone[0]");
u_Bone1 = GLES20.glGetUniformLocation(mProgram, "u_Bone[1]");
and in the onDraw
I send each of them to the shader:
GLES20.glUniformMatrix4fv(u_Bone0, 1, false, matrix0, 0);
This obviously isn't a good approach if I have a large number of matrices. My second idea which I haven't tried yet since there is a lot of code to refactor
Method 2
Is to use the glUniformMatrix4fv
to send them all at once like (assume I have 20 matrices)
GLES20.glUniformMatrix4fv(u_Bones, 20, false, matrices, 0);
where matrices
is float[16 * 20]
. But then modifying the matrices for each bones becomes a bit tedious. For example, if I want to get the 3rd matrix, I need something along the lines of
float[] _3rd = Arrays.copy(matrices, 3*16, 4*16);
and saving back the values can become even more annoying.
I'm using Method 1 now, but it doesn't look very smart...
What is the best way to send multiple matrices to an OpenGL ES 2 shader?
LE: I'm using Android, so I'm looking for a Java solution.