How to pass float array to glVertexAttribPointer
i'm working on OpenGL ES 2.0 shaders on android...
i have a float array with position of vertices along with other attributes of vertices. position and other attributes may change over time.
how can i pass this modified array to glVertexAttribPointer, so that i ca开发者_如何学JAVAn draw the scene with updated values
when i tried to pass it, i got
The method glVertexAttribPointer(int, int, int, boolean, int, Buffer) in the type GLES20 is not applicable for the arguments (int, int, int, boolean, int, float[])
FloatBuffer yourFloatBuffer;
float[] yourFloatArray;
FloatBuffer byteBuf = ByteBuffer.allocateDirect(yourFloatArray.length * 4);
byteBuf.order(ByteOrder.nativeOrder());
yourFloatBuffer = byteBuf.asFloatBuffer();
yourFloatBuffer.put(yourFloatArray);
yourFloatBuffer.position(0);
This should work.
Is it java.nio.Buffer? Because it seems you need
java.nio.FloatBuffer
and call floatBuffer.array()
to get the float[] array out of it.
But, obviously it is final in FloatBuffer.java:
final float[] hb;
So it seems that you'll need to... maybe extend FloatBuffer and make the array non-final.
精彩评论