[英]OpenGL VBO updating data
I have to draw a buffer that holds a couple thousand vertices. 我必须绘制一个包含几千个顶点的缓冲区。 I am using a vbo to store the data. 我正在使用vbo来存储数据。
I know I will have to update the VBO many times - but only in small parts at a time. 我知道我将不得不多次更新VBO - 但一次只能处理一小部分。
So I am wondering what the best method to doing so is: 所以我想知道这样做的最佳方法是:
glBufferSubData()
calls? 一个大的VBO并使用大量的glBufferSubData()
调用? glMapBuffer()
and one big VBO? 使用glMapBuffer()
和一个大的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. 还有另一个选项,有点像选项3 - 使用一个大的VBO(可能是GL_STREAM_DRAW
模式),每个帧重置一次(通过调用带有NULL
缓冲区指针的glBufferData
和每次相同的大小)然后glMapBuffer
-ed 。 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. 对glBufferData
的调用告诉OpenGL不需要旧的缓冲区内容,因此glMapBuffer
不必等待确保GPU完成GPU。
This approach seems to be the one officially sanctioned by the vertex_buffer_object
extension. 这种方法似乎是由vertex_buffer_object
扩展正式批准的vertex_buffer_object
。 See the "Vertex arrays using a mapped buffer object" example: 请参阅“使用映射的缓冲区对象的顶点数组”示例:
http://www.opengl.org/registry/specs/ARB/vertex_buffer_object.txt 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(或驱动程序?)将关注这种行为,并且(当发现时)安排事情以便有效地执行。
If think that glBufferData or glMapBuffer are the better solution if your buffer is small. 如果你的缓冲区很小,那么认为glBufferData或glMapBuffer是更好的解决方案。 100000 * sizeof(float) * 3 ~= 1MB
. 100000 * sizeof(float) * 3 ~= 1MB
。 There should be no problem with that. 应该没有问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.