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, eg float[] as the data. Since I never saw that used in any code examples online, I wonder if it is discouraged for any reason?
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 .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.