使用glBufferData后可以删除浮点数组吗? [英] Can I delete a float array when I have used glBufferData?

查看:170
本文介绍了使用glBufferData后可以删除浮点数组吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究OpenGL API,我想问问我,将其传递给OpenGL后是否可以删除顶点的浮点数组.

I'm studying OpenGL API and I would like to ask you if I can delete a float array of vertices after passing it to OpenGL.

示例代码:

GLuint VBO;
float *vertices = new float[2];
vertices[0] = 0.0f;
vertices[1] = 1.0f;

glGenBuffers(1, &VBO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);

delete[] vertices;

您能告诉我这样做的后果吗?

Could you tell me consequences about doing it?

推荐答案

是的,绝对可以. glBufferData()调用返回后,您可以对数据进行任何操作.覆盖,删除等.

Yes, absolutely. After the glBufferData() call returns, you can do anything you want with the data. Overwrite it, delete it, etc.

结果是OpenGL实现要么必须在调用过程中立即更新缓冲区(这与OpenGL所喜欢的异步方式有点冲突),要么创建数据的临时副本(这对于性能而言是不希望的)原因).

The consequence is that the OpenGL implementation either has to update the buffer immediately during the call (which is somewhat against the asynchronous way that OpenGL likes to operate in), or create a temporary copy of the data (which is undesirable for performance reasons).

这是引入诸如glMapBufferRange()之类的调用的主要原因.它们避免了使用glBufferData()glBufferSubData()时经常在幕后发生的额外数据复制.如果使用不当,它们会有自己的同步警告.

This is a main reason why calls like glMapBufferRange() were introduced. They avoid the extra data copy that often happens under the hood when glBufferData() and glBufferSubData() are used. They have their own synchronization caveats if not used carefully.

纹理数据的情况非常相似,其中glTexImage2D()之类的调用通常会在OpenGL实现中导致数据的额外副本.在这种情况下,性能影响可能会更糟,因为纹理数据通常要大得多. Apple为此有一个扩展名( APPLE_client_storage ),在此可以避免通过保证在OpenGL消耗完数据之前保持不变,来保留额外的副本.

There is a very similar case for texture data, where calls like glTexImage2D() often cause an extra copy of the data in the OpenGL implementation. The performance implications can be worse in that case because texture data is typically much bigger. Apple has an extension for this purpose (APPLE_client_storage), where you can avoid the extra copy by promising to keep the data untouched until it has been consumed by OpenGL.

几乎所有以数据指针为参数的OpenGL调用都将数据作为调用的一部分.在没有VBO的情况下,我能想到的唯一值得注意的例外是glVertexAttribPointer().这种用法通常称为客户端顶点数组",并且数据在绘制调用期间被消耗,这可能在glVertexAttribPointer()调用之后很长时间.此用法已被弃用,并且在OpenGL Core Profile中不可用.

Almost all OpenGL calls with data pointers as arguments consume the data as part of the call. The only notable exception I can think of is glVertexAttribPointer() when used without VBOs. This usage is often called "client side vertex arrays", and the data is consumed during the draw call, which can be long after the glVertexAttribPointer() call. This usage is deprecated, and not available in the OpenGL Core Profile.

这篇关于使用glBufferData后可以删除浮点数组吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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