LWJGL3:重载的glBufferData方法 [英] LWJGL3: Overloaded glBufferData methods

查看:94
本文介绍了LWJGL3:重载的glBufferData方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用LWJGL调用OpenGL函数.

I am using LWJGL to call OpenGL functions.

方法 org.lwjgl.opengl.GL15#glBufferData() 调用等效的 OpenGL方法. 它在LWJGL中有几个重载的变体,而我见过的最常使用的是FloatBuffer,像这样的简单三角形(省略了其他不相关的OpenGL调用):

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);

但是也有一些直接采用数组的变体,例如float []作为数据.由于我从未在网上的任何代码示例中看到过该代码,所以我想知道是否由于任何原因不建议使用该代码?

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?

推荐答案

方法的用法.数组而不是*Buffer的对象不会被精简. 您可能无法在线上找到它们用法的示例,因为它们只是最近才添加的.

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使用这些方法没有什么问题, execpt 可能要比带有*Buffer的方法慢一些,因为数组(及其数据)位于头部.这是否是一个实际的性能问题是有争议的,只能通过分析特定情况来确定.

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.

这篇关于LWJGL3:重载的glBufferData方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆