OpenGL VBO更新数据
我必须绘制一个包含数千个顶点的缓冲区。我正在使用 vbo 来存储数据。
我知道我必须多次更新 VBO - 但一次只能更新一小部分。
所以我想知道最好的方法是什么:
- 将 VBO 分割成更小的 VBO(大约 300 个顶点),然后通过 1 次调用更新各个 VBO?
- 一个大型 VBO 并使用大量
glBufferSubData()
调用? - 使用
glMapBuffer()
和一个大的 VBO?
I have to draw a buffer that holds a couple thousand vertices. I am using a vbo to store the data.
I know I will have to update the VBO many times - but only in small parts at a time.
So I am wondering what the best method to doing so is:
- Split VBO up into smaller VBOs (that hold like 300 verts) and then update individual VBOs with 1 call?
- One big VBO and use lots of
glBufferSubData()
calls? - Use
glMapBuffer()
and one big VBO?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
还有另一个选项,有点像选项 3 - 使用一个大 VBO(可能使用 GL_STREAM_DRAW 模式),该 VBO 会重置每一帧(通过使用
glBufferData
调用>NULL 缓冲区指针且每次大小相同),然后立即进行glMapBuffer
编辑。缓冲区在填充时保持映射状态,然后在绘制之前取消映射。重复。对
glBufferData
的调用告诉 OpenGL 不需要旧的缓冲区内容,因此glMapBuffer
不必潜在地等待以确保 GPU 完成 GPU 的处理。这种方法似乎是由
vertex_buffer_object
扩展正式认可的方法。请参阅“使用映射缓冲区对象的顶点数组”示例:http://www. opengl.org/registry/specs/ARB/vertex_buffer_object.txt
这表明 OpenGL(或驱动程序?)将监视这种行为,并且(当发现时)进行安排,以便高效执行。
There is another option, which is a bit like option 3 - use one big VBO (probably with
GL_STREAM_DRAW
mode) that is reset each frame (by callingglBufferData
with aNULL
buffer pointer and the same size each time) thenglMapBuffer
-ed right away. The buffer is left mapped as it is filled in, then unmapped just before drawing. Repeat.The call to
glBufferData
tells OpenGL that the old buffer contents aren't needed, so theglMapBuffer
doesn't have to potentially wait to ensure the GPU is finished with by the GPU.This approach seems to be the one officially sanctioned by the
vertex_buffer_object
extension. See the "Vertex arrays using a mapped buffer object" example:http://www.opengl.org/registry/specs/ARB/vertex_buffer_object.txt
This suggests that OpenGL (or the driver?) will be watching for this sort of behaviour, and (when spotted) arrange things so that it is performed efficiently.
如果您的缓冲区很小,则认为 glBufferData 或 glMapBuffer 是更好的解决方案。
100000 * sizeof(float) * 3 ~= 1MB
。应该没有问题。If think that glBufferData or glMapBuffer are the better solution if your buffer is small.
100000 * sizeof(float) * 3 ~= 1MB
. There should be no problem with that.