LWJGL3: Overloaded glBufferData methods

为君一笑 提交于 2019-12-10 21:41:47

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/37930330/lwjgl3-overloaded-glbufferdata-methods

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!