OpenGL 2.1:在VBO中重新缓冲子区域 [英] OpenGL 2.1: Rebuffering sub-region in VBO

查看:56
本文介绍了OpenGL 2.1:在VBO中重新缓冲子区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在VBO中存储了一个地形网格物体.网格是由直角三角形组成的网格.换句话说,它看起来像是带有对角线的直线网格.网格的宽度和高度是已知的,因此很容易计算给定XY的顶点索引,反之亦然.

I have a terrain mesh stored in a VBO. The mesh is a grid composed of right triangles. In other words, it looks like a rectilinear grid with diagonals. The width and height of the mesh are known, so it's easy to calculate the vertex indices for a given XY or vice-versa.

地形网格物体将是可编辑的.我的问题是在编辑地形时重新缓冲顶点数据.我将能够确定任何编辑操作都会弄脏的顶点的矩形区域,因此,显然,我希望只重新缓冲那些顶点,而让其余部分搁浅.

The terrain mesh will be editable. My question concerns rebuffering the vertex data when the terrain is edited. I will be able to determine the rectangular region of vertices that are dirtied by any edit operation, so obviously I'd prefer to rebuffer only those and leave the rest alone.

首先想到的是glBufferSubData.但是我无法提出一种方法来布置我的VBO,以致glBufferSubData仅会影响脏顶点.例如,假设我的网格是5 x 5顶点. (实际上,它会更大;这只是一个例子.)就像这样:

The first thing that comes to mind is glBufferSubData. But I can't come up with a way to lay out my VBO such that glBufferSubData would only affect the dirty vertices. For example, suppose my mesh is 5 x 5 vertices. (It would actually be much larger; this is just an example.) Like this:

 0  1  2  3  4
 5  6  7  8  9
10 11 12 13 14
15 16 17 18 19
20 21 22 23 24

(上图中的每个数字代表顶点距VBO起点的偏移量.)

(Each number in the diagram above represents the vertex's offset from the start of the VBO.)

假设中心的3 x 3区域需要重新缓冲.这意味着我想打顶点6、7、8、11、12、13、16、17和18.所以我可以调用glBufferSubData,从索引6开始到18:

Suppose the 3 x 3 region in the center needs to be rebuffered. That means I want to hit vertices 6, 7, 8, 11, 12, 13, 16, 17, and 18. So I could call glBufferSubData starting at index 6 and ending at 18:

  0   1   2   3   4
  5  *6  *7  *8  *9
*10 *11 *12 *13 *14
*15 *16 *17 *18  19
 20  21  22  23  24

(在上图中,标记为*的顶点被重新缓冲.)

(In the diagram above, the vertices marked with * are rebuffered.)

请注意,顶点10、14和15并不脏,但它们仍被重新缓冲,因为它们在glBufferSubData给出的范围内.这使我感到无能为力.对于大型网格,在大多数情况下,我将以比所需更多的方式来重新缓冲数据.

Notice that vertices 10, 14, and 15 are not dirty, and yet they get rebuffered, because they're in the range given to glBufferSubData. This strikes me as inefficient. For a large mesh, I'd be rebuffering way more data than I need to in most cases.

是否存在针对此问题的知名解决方案?我是否应该每行调用一次glBufferSubData(这可以解决当前的问题,但是会产生开销)?还是仅仅为了缓冲整个范围并吃掉不必要的写作而付出的代价是标准的?

Is there a well-known solution to this problem? Should I call glBufferSubData once per row (which would solve the present problem, but would come with its own overhead)? Or is it standard just to buffer the full range and eat the cost of the unnecessary writing?

此外,地形编辑有时(但不经常)进行.启用后,将对其进行动画处理,因此在进行动画处理时,必须反复更新脏顶点.我想GL_DYNAMIC_DRAW会很好.听起来不错吗?

Also, terrain editing happens sometimes but not often. When it does, it will be animated, so the dirty vertices will have to be updated repeatedly while the animation is occurring. I'm thinking GL_DYNAMIC_DRAW would be good. Does this sound right?

推荐答案

您应使用缓冲对象映射.您可以将缓冲区对象作为内存数组进行访问,实际上可以访问稀疏顶点.驱动程序(希望)将为您优化它.

You shall use buffer object mapping. You can access to buffer object as a memory array, indeed accessing sparse vertices. The driver (hopefully) will optimize it for you.

使用GL_DYNAMIC_DRAW是正确的.

这篇关于OpenGL 2.1:在VBO中重新缓冲子区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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