I'm building a level (map) design tool using Qt, and my user interface will contain multiple different OpenGL-driven viewports. In Qt, each different viewport is created with its own context, and I currently have the application-wide setting enabled so that all contexts share resources with each other. I'm currently targeting OpenGL 4.1 core.
My current implementation uses one "render model" per map - the map's actual geometry (the "model", with planes and texture projection parameters and all that stuff) is converted when required to OpenGL-specific geometry data, which is stored and batched in the render model for that map. Each render model, for better or worse, uses a single VAO - I figured having one VAO per batch would equate to an awful lot of objects.
However, I've just learned today that VAOs cannot be shared between contexts. It's my suspicion that this is what's causing OpenGL to return INVALID_OPERATION when attempting to bind a VAO, or do any other drawing whatsoever, now that I've refactored my code to begin using multiple viewports. Helpfully, Mac doesn't give any errors at all, and just renders in incredibly confusing and undefined ways.
In theory I'd like for any viewport to be considered a rendering destination, so that a map's render model is the one location that stores all the geometry required, and can be drawn onto any renderable surface. If VAOs cannot be shared, I don't think I'll be able to store one per render model.
I have the following questions:
- Should I be using one VAO per viewport, created when the viewport's context is initialised? Will this obstruct the population process of the render model (ie. does that have to be done in the same context)? Will the data still be shareable with other contexts/VAOs?
- Alternatively, should I be using one VAO per batch? I'd imagine this would definitely tie the creation of the batch to one of the viewports' contexts, and I'm not sure how I'd manage that.