本文介绍了OpenGL ES中的"glBufferData"有什么用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了我移植到OpenGL ES 2.0的示例OpenGL代码(实际上没有什么要做的),但是我不禁要问glBufferData函数的作用是什么.原始来源是这样的:

I run across a sample OpenGL code that I ported to OpenGL ES 2.0 (there wasn't much to be done actually), but I cannot help wondering what the glBufferData function is for. The original source is like that:

glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * 2 * 6, quad, GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 2, (void *) 0);

但是我可以成功地简化为:

But I can successfully simplify it as:

glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 2, quad);

也就是说,仅使用指向glVertexAttribPointer中四元数组的有效指针,就可以省略glBufferData函数.

That is, I can omit the glBufferData function just by using a valid pointer to the quad array in glVertexAttribPointer.

那么,谁能解释glBufferData函数的作用是什么?从我所做的事情来看,这似乎是多余的,但这一定是因为我严重缺乏对API的了解.事实上,我尝试阅读 khronos.org ,但这并没有帮助我理解其用法.

So, could anyone explain what's the glBufferData function for? From what I'm doing it seems to be redundant but that must be because of my serious lack of knowledge of the API. As a matter of fact I tried reading the docs at khronos.org but this didn't help me understand its use.

推荐答案

如果要在多个帧中重复使用相同的数据,则在设置/初始化过程中使用glBufferData只会将数据从CPU传输到GPU一次. glVertexAttribPointer必须在每一帧都被调用,因此使用它传输数据会导致使用更多的总线带宽.

If you are reusing the same data in multiple frames, using glBufferData as part of your setup/initialization will transfer data from the CPU to the GPU only once. Whereas glVertexAttribPointer must be called every frame, so using it to transfer data results in using a lot more bus bandwidth.

如果要每帧更新属性数组,则一种方法或另一种方法没有太多优势.

If you're updating the attribute array every frame, there's not much advantage one way or the other.

这篇关于OpenGL ES中的"glBufferData"有什么用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 08:22