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?
Thanks to Alfonse Reinheart over at the OpenGL forums, I now know that it is because VAOs are not shared between contexts.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With