While programming an application with JOGL, I decided to use vertex-arrays to store some data in to send to the VRAM, forcing me to use nio-buffers.
Code was like:
FloatBuffer vertex;
FloatBuffer normal;
FloatBuffer texcoord;
for(every visible tree)
{
vertex.put(float[]);
normal.put(float[]);
texcoord.put(float[]);
}
Dead-slow… Maybe not surprising for you, but for me it was. Frustrated I wondered what was so slow here, and tried the following:
FloatBuffer vertex;
FloatBuffer normal;
FloatBuffer texcoord;
float[] vertexArray;
float[] normalArray;
float[] texcoordArray;
for(every visible tree)
{
System.arraycopy(append float[] -> vertexArray);
System.arraycopy(append float[] -> normalArray);
System.arraycopy(append float[] -> texcoordArray);
}
vertex.put(vertexArray);
normal.put(normalArray);
texcoord.put(texcoordArray);
It was 15x faster! (and 15x is a LOT)
So I was wondering… what is causing directly putting data in (Float)Buffers to be so inefficient (6% of performance in code#2).
~~
Note that the FloatBuffers were native.