Matrix class and FloatBuffer

Hello!

I am writing my own matrix class and have a design problem:

jogl functions, which accept a matrix as float[] or FloatBuffer. I think i read somewhere in the forum that the float[] accepting functions convert them internal to a FloatBuffer. That would coast time.

On the other hand is using a FloatBuffer.in the matrix class more expansive than a float[]?

Should I use a FloatBuffer or float[]? Which is better? Or am I completely wrong?

Thanks for the help?

I guess it depends - my suggestion is to use a FloatBuffer internally, and provide an accessor to it (such as ‘asFloatBuffer() : FloatBuffer’).

Maybe I’m missing something but personally I don’t think that this class would ever pose a performance problem. Are you quite sure this is worth worrying about?

This is incorrect.

All of the OpenGL routines that take matrices as arguments, such as glLoadMatrixf, can accept float[]s so you are probably best using that as your representation.

Before you write a whole linear algebra library you might want to check out the joglutils source code and look at the msg.math package, which has several classes already implemented which are known to work well with OpenGL.

I think the whole ‘internal buffers’ thing should be filed-away under ‘JOGL myths’. If you take a look at how arrays and FloatBuffers are handled on the JNI/C++ side, there is really no difference in the way/swiftness arrays or *Buffers are dealt with.