c++带有缓冲区资源的 OpenGL 多线程
我有一个 OpenGL 程序需要定期更新纹理。但同时我希望程序在更新这些纹理时能够做出响应(具体来说,继续运行绘制/显示代码)。
但这似乎是不可能的:如果我让 thread1 执行绘制/显示代码,而 thread2 执行纹理移动,那么它们将在资源 GL_ARRAY_BUFFER_ARB 下发生冲突,因为 thread2 必须保留该资源才能将某些纹理移动到 vbo。我需要 GL_ARRAY_BUFFER_ARB 来为 thread1 执行绘制/显示代码,因为它使用不同的 vbo。
例如,此代码
glBindBufferARB(GL_ARRAY_BUFFER_ARB, tVboId);
glBufferDataARB(GL_ARRAY_BUFFER_ARB, numVertices*2*sizeof(GLfloat), texCoords, GL_DYNAMIC_DRAW_ARB);
glBindBufferARB(GL_ARRAY_BUFFER_ARB,0);
将移动一些纹理,但这需要一段时间。在此期间,显示代码应该运行多次,但它会崩溃,因为 GL_ARRAY_BUFFER_ARB 正在使用中。
我以为我可以做类似 GL_ARRAY_BUFFER_ARB2 的事情,但我认为没有这样的事情。
I have an OpenGL program that needs to periodically update the textures. But at the same time I want the program to be responsive (specifically, to continue running the draw/display code) while it's updating these textures.
But this seems impossible: If I make thread1 do the draw/display code and thread2 to the texture moving, then they will conflict under the resource GL_ARRAY_BUFFER_ARB because thread2 has to keep that resource to move some textures over to a vbo. And I need GL_ARRAY_BUFFER_ARB to do the draw/display code for thread1 because that uses different vbo's.
For example this code
glBindBufferARB(GL_ARRAY_BUFFER_ARB, tVboId);
glBufferDataARB(GL_ARRAY_BUFFER_ARB, numVertices*2*sizeof(GLfloat), texCoords, GL_DYNAMIC_DRAW_ARB);
glBindBufferARB(GL_ARRAY_BUFFER_ARB,0);
will move some textures over but it will take a while. During that time the display code is supposed to run many times but it will instead crash, because GL_ARRAY_BUFFER_ARB is in use.
I thought I could do something like GL_ARRAY_BUFFER_ARB2 but there is no such thing, I think.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 PBO,它们允许您进行异步传输,请在此处了解更多信息。
Use PBOs they allow you to do asynchronous transfers, read more here.
这应该有帮助: http://hacksoflife.blogspot.com /2008/02/creating-opengl-objects-in-second.html
This should help: http://hacksoflife.blogspot.com/2008/02/creating-opengl-objects-in-second.html