简体   繁体   English

OpenGL VBO更新数据

[英]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: 所以我想知道这样做的最佳方法是:

  1. Split VBO up into smaller VBOs (that hold like 300 verts) and then update individual VBOs with 1 call? 将VBO拆分为较小的VBO(保持300个顶点)然后用1个调用更新单个VBO?
  2. One big VBO and use lots of glBufferSubData() calls? 一个大的VBO并使用大量glBufferSubData()调用?
  3. Use 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(或驱动程序?)将关注这种行为,并且(当发现时)安排事情以便有效地执行。

  1. Doesn't sound like a good idea: it forces you to draw it in several calls while changing the bound buffer between each draw call. 听起来不是一个好主意:它会强制您在多次调用中绘制它,同时在每次绘制调用之间更改绑定缓冲区。
  2. Might do the trick if your buffer is huge. 如果你的缓冲区很大,可能会做的伎俩。
  3. The whole buffer will certainly be uploaded to the GPU. 整个缓冲区肯定会上传到GPU。 This will certainly be as efficient as one glBufferData, but you can do it asynchronously. 这肯定和一个glBufferData一样有效,但你可以异步地完成它。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM