PDA

View Full Version : Drawing on multiple windows problem



flure_popsy
12-07-2017, 10:11 AM
Hello,

I'm currently facing a problem while rendering the same scene on different windows, with Opengl 4.1.

I have two windows, and I use wglMakeCurrent() before rendering into each of them.
I have one VAO, one program pipeline, etc. and I want to share them to draw the same scene on both windows.

Everything is fine for the first window, but, while rendering to the second window, the call to glBindVertexArray fails (while using the same VAO as for the first window).
The strangest thing is that, if I create a dummy VAO (by calling glGenVertexArrays) just before rendering - and not using it anymore - the call to glBindVertexArray() that was failing doesn't fail anymore!
Same problem with glBindProgramPipeline() : if I create a dummy program pipeline and don't use it, glBindProgramPipeline() doesn't fail anymore. And then it's the call to glDrawArrays() that fails.
This is a very strange behaviour that I can't explain.

I tried with a rendering context per window (using wglShareLists), and with only one rendering context used by both windows.

If someone has an explaination to this behaviour, and/or a solution to that problem, I would be very grateful.

Thanks

GClements
12-07-2017, 10:45 AM
I'm currently facing a problem while rendering the same scene on different windows, with Opengl 4.1.

I have two windows, and I use wglMakeCurrent() before rendering into each of them.
I have one VAO, one program pipeline, etc. and I want to share them to draw the same scene on both windows.

VAOs and program pipelines are containers (https://www.khronos.org/opengl/wiki/Container_Object), and as such aren't shared between contexts. You have to create a separate VAO or pipeline for each context.



Everything is fine for the first window, but, while rendering to the second window, the call to glBindVertexArray fails (while using the same VAO as for the first window).
The strangest thing is that, if I create a dummy VAO (by calling glGenVertexArrays) just before rendering - and not using it anymore - the call to glBindVertexArray() that was failing doesn't fail anymore!
Same problem with glBindProgramPipeline() : if I create a dummy program pipeline and don't use it, glBindProgramPipeline() doesn't fail anymore. And then it's the call to glDrawArrays() that fails.
This is a very strange behaviour that I can't explain.

This is to be expected. The glGen* functions which allocate names will return names which are unique for the context; there's no need for the names to be globally unique. So when you call e.g. glGenVertexArrays() for the second context, the name will be identical to that used for the first context, although it refers to a different object. When you actually try to use the object, the call will fail because the object hasn't been created (the glGen* functions only reserve the name; they don't create the corresponding object).



I tried with a rendering context per window (using wglShareLists), and with only one rendering context used by both windows.

The latter should work. At least, you won't have the issue with containers not being shared if you only have one context. There are still other factors (e.g. you can only use a context with a "compatible" HDC, which may be an issue if you have windows on different screens).