OpenGL VBO 仅在渲染时上传到 GPU
我的 VBO 仅在第一次使用时发送到 GPU,这会导致第一次绘制对象/对象组时出现轻微冻结。
我尝试以这种方式加载数据:
glBufferData(GL_ARRAY_BUFFER, size, NULL, GL_STATIC_DRAW);
glBufferSubData(GL_ARRAY_BUFFER, 0, size, data);
和这种方式
glBufferData(GL_ARRAY_BUFFER, size, data, GL_STATIC_DRAW);
但结果是一样的。
如果我在 glBufferData: 之后画一个三角形,
glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_BYTE, NULL);
那么问题就解决了,但我发现这个解决方案相当黑客。
有更好的解决方案吗?
(我有一堆小 VBO,每个包含 256 个顶点)
My VBOs are only being sent to the GPU when they are used for the first time, this causes small freezes the first time an object/group of objects is drawn.
I tried loading the data this way:
glBufferData(GL_ARRAY_BUFFER, size, NULL, GL_STATIC_DRAW);
glBufferSubData(GL_ARRAY_BUFFER, 0, size, data);
and this way
glBufferData(GL_ARRAY_BUFFER, size, data, GL_STATIC_DRAW);
But the result is the same.
If I then draw a triangle after glBufferData:
glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_BYTE, NULL);
then the problem is solved, but I find this solution rather hackish.
Is there a better solution?
(I have a bunch of small VBOs containing 256 vertices each)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
嗯,这就是缓冲区对象应该如何工作,即添加一些异步操作。这个想法是,您可以上传一大堆缓冲区对象,然后继续 OpenGL 操作,只有在访问尚未完成上传的数据时管道才会停止。 glBufferData 和 glBufferSubData 要么使指针的页面传递给它们 CoW,要么制作临时副本,无论哪种方式,您都可以在调用返回后安全地丢弃进程中的数据,OpenGL 客户端仍将保留数据(正在进行中)上传过程。
调用 glFinish() 将阻塞,直到操作管道完全完成(因此得名)。
Well, this is how Buffer Objects are supposed to work, namely adding somewhat asynchronous operation. The idea is, that you can upload a large bunch of Buffer Objects, and continue OpenGL operations afterwards, with the pipline stalling only, if data is accessed which upload has not been completed yet. glBufferData and glBufferSubData either make the pages of the pointer passed them CoW or make an interim copy, either way you can safely discard the data in your process after the call returned, the OpenGL client side will still have the data around for (the ongoing) upload process.
Calling glFinish() will block until the operations pipline has been completely finished (hence the name).
尝试在 glBufferData 调用之后调用 glFlush() 。
Try calling glFlush() after your glBufferData call.