共享 OpenGL VAO/VBO/等。通过 QGLWidget
我正在使用 QGLWidgets 的 3 层层次结构在我的类似 CAD 的应用程序中的 5 个 OpenGL 视口之间共享着色器和顶点数据。根上下文用于编译应用程序范围的着色器,每个文档上下文用于共享模型顶点数据,视口上下文是实际进行渲染的上下文(还包含网格顶点数据和其他每个视口的内容)。
着色器共享似乎工作正常,网格绘图也是如此,但是当涉及到共享顶点数据时,它失败了,说实话 - 我不明白它应该如何工作......
我为一个项目构建了一个 3D 图标虽然模型上下文是当前的,因为它是第一个 VAO,它的“名称”为 1。当我开始绘制对象时,视口上下文(记住与模型上下文共享)是当前的,因此 VAO 1 是被调用,但绘制的是视口的 VAO 1 - 我漂亮的红色网格中心线。 OpenGL 上下文可以共享,但由于名称不唯一,如何指定每个项目所属的“命名空间”?
我尝试在模型 VAO 调用之前将模型上下文设置为当前,但是绘制了正确的 VAO 和视口,我认为在 QPainter::beginNativePainting() 块期间切换上下文并不会让 OpenGL 满意。
这对我来说似乎是一件非常基本的事情,所以我一定做了一些愚蠢的事情 - 有什么建议吗?
I am using a 3 layer hierarchy of QGLWidgets to share shaders and vertex data between 5 OpenGL viewports in my CAD-like app. The root context is used for compiling application-wide shaders, the per document context is used to share model vertex data, and the viewport contexts are the ones that actually do the rendering (and also contain grid vertex data and other per viewport stuff).
The shader sharing seems to work fine, and so does the grid drawing, but when it comes to sharing vertex data it fails and to be honest - I cannot see how it is supposed to work...
I built a 3D icon for an item whilst the model context was current, as it was the first VAO it had a 'name' of 1. When I come to draw the object, the viewport context (which is shared with the model context remember) is current, so VAO 1 is called but it's the viewport's VAO 1 that is drawn - my nice red grid centre line. The OpenGL contexts can be shared but how can you specify the 'namespace' each item belongs to as the names are not unique?
I tried making the model context current just before the model VAO calls, but the proper VAO nor the viewport one are drawn, I think switching context during a QPainter::beginNativePainting() block does not make OpenGL happy.
This seems a very basic thing to me so I must be doing something stupid - any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
感谢 OpenGL 论坛上的 Alfonse Reinheart,我现在知道这是因为 VAO 不在上下文之间共享。
Thanks to Alfonse Reinheart over at the OpenGL forums, I now know that it is because VAOs are not shared between contexts.