在交错的 openGL 顶点缓冲区对象之间复制
使用 opengl 3.3、radeon 3870HD、c++..
我有关于交错数据数组的问题。我在向量中得到了我的应用程序结构,它作为数据发送到缓冲区对象。像这样的东西:
struct data{
int a;
int b;
int c;
};
std::vector<data> datVec;
...
glBufferData(GL_ARRAY_BUFFER, sizeof(data)*datVec.size(), &datVec[0], GL_DYNAMIC_DRAW);
没关系,我经常使用这个东西。但我创建的是交错数组,因此数据如下:
a1,b1,c1,a2,b2,c2,a3,b3,c3
现在我将这个东西发送到 GPU 中进行处理,并通过转换反馈将其读回缓冲区,例如 b 变量。所以它看起来像:
bU1, bU2, bU3
我想将更新的值复制到交错缓冲区中,这可以通过像 glCopyBufferSubData 这样的单个命令来完成吗?这个不合适,因为它只需要偏移量和大小而不是步长(可能类似于 c++ 中的 memcpy)...结果应该如下所示:
a1, bU1, c1, a2, bU2, c2, a3, bU3, c3
如果没有,是否有比我的这 2 个更好的方法?
映射更新的缓冲区,将值复制到应用程序中的临时存储中,取消映射更新,映射数据缓冲区并遍历它设置新值
在常量缓冲区和变量缓冲区上设置单独的缓冲区。常量将随着时间的推移保持不变,但使用 glCopyBufferSubData 可以在一次调用中更新变量。
谢谢
using opengl 3.3, radeon 3870HD, c++..
I got question about interleaved arrays of data. I got in my application structure in vector, which is send as data to buffer object. Something like this:
struct data{
int a;
int b;
int c;
};
std::vector<data> datVec;
...
glBufferData(GL_ARRAY_BUFFER, sizeof(data)*datVec.size(), &datVec[0], GL_DYNAMIC_DRAW);
this is ok I use this thing very often. But what I create is interleaved array so data are like:
a1,b1,c1,a2,b2,c2,a3,b3,c3
Now I send this thing down for processing in GPU and with transform feedback I read back into buffer for example b variables. So it looks like:
bU1, bU2, bU3
I'd like to copy updated values into interleaved buffer, can this be done with some single command like glCopyBufferSubData? This one isn't suitable as it only takes offset and size not stride (probably it's something like memcpy in c++)... The result should look like:
a1, bU1, c1, a2, bU2, c2, a3, bU3, c3
If not is there better approach than these 2 mine?
map updated buffer, copy values into temp storage in app, unmap updated, map data buffer and itterating through it set new values
separate buffers on constant buffer and variable buffer. constant will stay same over time but using glCopyBufferSubData the variable one can be updated in single call..
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
glMapBuffer 似乎是您正在做的事情的更好的解决方案。
据我所知,基本思想是将缓冲区映射到您的地址空间,然后使用您自己的更新方法手动更新缓冲区(可能是迭代循环)。
glMapBuffer seems like a better solution for what you are doing.
The basic idea, from what I can tell, is to map the buffer into your address space, and then update the buffer manually using your own update method (iterative loop likely).
我会将动态部分与静态部分分开(你的观点2)。
如果您仍希望将它们交错保存到单个缓冲区中,并且您有一些空闲视频内存,则可以执行以下操作:
I would separate the dynamic part with a static one (your point 2).
If you still want to keep them interleaved into a single buffer, and you have some spare video memory, you can do the following: