Reputation: 3955
I am using LWJGL to call OpenGL functions.
The method org.lwjgl.opengl.GL15#glBufferData()
calls the equivalent OpenGL method.
It has several overloaded variants in LWJGL, and the most used I've seen is with FloatBuffer
, like this for a simple triangle (other unrelated OpenGL calls omitted):
float[] triangle = new float[]{
0.0f, 0.5f, 0.0f,
-0.5f, -0.5f, 0.0f,
0.5f, -0.5f, 0.0f
};
FloatBuffer buf = BufferUtils.createFloatBuffer(triangle.length);
buf.put(triangle).flip();
int vbo = glGenBuffers();
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, buf, GL_STATIC_DRAW);
But there are also variants that directly take an array, e.g. float[] as the data. Since I never saw that used in any code examples online, I wonder if it is discouraged for any reason?
Upvotes: 3
Views: 257
Reputation: 581
The usage of the methods. with arrays rather than *Buffer
are not discouraged.
You may not find example of their usage online because the have only been added recently.
AFAIK there is nothing wrong with using these methods, execpt they might be a fraction slower than the ones with *Buffer
as the arrays (and their data) is in the head. Whether that is an actual performance concern is arguable and can only be identified by profiling the specific situation.
So just use whatever is more comfortable to you.
Upvotes: 1