View Full Version : Sharing OpenGL VAO/VBO/etc. via QGLWidget contexts

04-22-2011, 01:49 AM
Hi all,

Although I'm doing all this through the Qt framework, I'm pretty certain my problems are stemming from the way I envisage OpenGL context sharing.

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?

Alfonse Reinheart
04-22-2011, 02:22 AM
VAOs are not shared across contexts.

04-22-2011, 03:18 AM
I said I was doing something stupid... Thanks!