Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sharing OpenGL VAO/VBO/etc. via QGLWidget

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?

like image 576
cmannett85 Avatar asked Apr 21 '11 22:04

cmannett85


1 Answers

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

like image 116
cmannett85 Avatar answered Oct 23 '22 00:10

cmannett85