OpenGL VBO更新数据 [英] OpenGL VBO updating data

查看:1796
本文介绍了OpenGL VBO更新数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须绘制一个包含几千个顶点的缓冲区。我使用vbo存储数据。



我知道我必须更新VBO很多次,但一次只能在很小的部分。

所以我想知道最好的方法是:


  1. 将VBO拆分成一个大的VBO,并使用 glBufferSubData的批次。 ()调用?

  2. 使用 glMapBuffer()和一个大VBO?


解决方案

还有一个选项,这有点像选项3 - 使用一个大VBO (通过调用 glBufferData 并使用 NULL )来重置每个帧($ c> GL_STREAM_DRAW >缓冲区指针和每次相同的大小)然后 glMapBuffer -ed立即。缓冲区被留下映射,因为它被填充,然后在绘制之前不被映射。重复。



调用 glBufferData 会告诉OpenGL不需要旧的缓冲区内容,因此 glMapBuffer 不必等待GPU确保GPU完成。



这种方法似乎这是由 vertex_buffer_object 扩展名正式批准的。请参阅使用映射缓冲区对象的顶点数组示例:



http://www.opengl.org/registry/specs/ARB/vertex_buffer_object.txt



这表明OpenGL(或驱动程序?)将监视这种行为,并且(当被发现时)安排事物以使其有效地执行。


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:

  1. Split VBO up into smaller VBOs (that hold like 300 verts) and then update individual VBOs with 1 call?
  2. One big VBO and use lots of glBufferSubData() calls?
  3. Use glMapBuffer() and one big VBO?

解决方案

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 calling glBufferData with a NULL buffer pointer and the same size each time) then glMapBuffer-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 the glMapBuffer 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.

这篇关于OpenGL VBO更新数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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