Sharing OpenGL VAO/VBO/etc. via QGLWidget

我的未来我决定 提交于 2019-12-07 09:18:26

问题


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?


回答1:


Thanks to Alfonse Reinheart over at the OpenGL forums, I now know that it is because VAOs are not shared between contexts.



来源:https://stackoverflow.com/questions/5750454/sharing-opengl-vao-vbo-etc-via-qglwidget

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!