Apeforce
Apeforce

Reputation: 83

What is the final parameter for this function good for?

I have tried hunting down the answer to this question for some days, but it's really not explained anywhere, and it's hard to make an experiment to determine the answer.

Look at the documentation for this function: http://developer.android.com/reference/android/opengl/GLES20.html#glUniformMatrix4fv%28int,%20int,%20boolean,%20float[],%20int%29 pretty exhaustive, right?

Sarcasm aside, what is offset good for in: glUniformMatrix4fv (int location, int count, boolean transpose, float[] value, int offset)

I was thinking that if value[] holds for example 4 matrixes, ie a float[4*4*4] array, the offset determines which following 16 floats that will be uploaded to the GPU.

So if value is:

{
  0, 0, 0, 0,
  0, 0, 0, 0,
  0, 0, 0, 0,
  0, 0, 0, 0,
  1, 0, 0, 0,
  0, 1, 0, 0,
  0, 0, 1, 0,
  0, 0, 0, 1,
  0, 0, 0, 0,
  0, 0, 0, 0,
  0, 0, 0, 0,
  0, 0, 0, 0
}

and i call the function like so:

GLES20.glUniformMatrix4fv(location, 1, false, values, 16);

the identity matrix would be uploaded to the GPU on the specified uniform location?

I've browsed really much and tried to find source code to determine if this is the case, but alas. I'm sorry for asking a question that SHOULD be covered by an API specification, but it's not.

Upvotes: 1

Views: 321

Answers (1)

Andon M. Coleman
Andon M. Coleman

Reputation: 43389

GL's v functions are somewhat difficult to explain in a language like Java, which does not support pointers. In C, you can use them to pass all of the arguments it needs using an address to a contiguous block of memory. It is a simple way of passing arguments by array.

Because of the flexibility of passing addresses in a language like C, the C language binding requires only one parameter to represent an arbitrary memory location. In order to replicate the ability to chose an arbitrary location in an array to copy data from, offset is necessary in Java.

glBufferData (...) has a similar construct, it uses a java.nio.Buffer's "current" position to mark the beginning. This is why you have to flip (...) buffers if you fill them by calling put (...) repeatedly - it moves the current position back to the beginning of the buffer.

In fact, the other overload of GLES20.glUniformMatrix4fv (...) (the one that uses FloatBuffer) works exactly the same way as glBufferData (...).

Upvotes: 4

Related Questions