1

I have this uniform in glsl

uniform mat4 u_MVPMatrix[64];

that is filled with 64 matrices

its used to transform 64 shapes in my game. It works good!!!

My question if its possible change a part of this matrix-vector if I for instance want to rotate or resize a certain sprite? Could I use the method:

glUniformMatrix4fv(int location, int count, boolean transpose, float[] value, int offset)

?

I do not understand the offset argument, I thought was it used as an offset into the matrix-vec in glsl but obviously not?

  GLES30.glUniformMatrix4fv(mMVPMatrixHandleEyes, 1, false, mMVPMatrixEyes, 1);  

IF I change the offset argument I get an exception:

 java.lang.IllegalArgumentException: length - offset < count*16 < needed
                                                                                 at android.opengl.GLES20.glUniformMatrix4fv(Native Method)

What is the solution to this issue? Should I instead focus om making the change on the GPU-side? But could a uniform be changed?

BDL
  • 21,052
  • 22
  • 49
  • 55
java
  • 1,165
  • 1
  • 25
  • 50

1 Answers1

2

Uniform arrays in glsl are guaranteed to have consecutive locations. The uniform u_MVPMatrix[i] thus has the location mMVPMatrixHandleEyes + i. This location can be used to set a single matrix (or multiple consecutive ones) by passing it to glUniformMatrix4fv.

The offset parameter, in contrast, is an offset into the float[] array passed, not into the glsl array.

BDL
  • 21,052
  • 22
  • 49
  • 55
  • thanks I'll look into this as soon as possible :-) May accept an upvote if it works – java Oct 11 '17 at 12:35