PDA

View Full Version : Drawing to multiple windows



grivescorbett
07-28-2012, 12:05 PM
Hello! It seems as though information on the net is limited about using multiple contexts/multiple windows. What I'm trying to do is use two contexts to draw scenes to different windows, I think I'm not totally clear on what OpenGL calls are affected by which context is made current. This is the pseudo-code of how I thought it should go:

Make Current Window 1
Generate VAO 1
Bind VAO 1
Generate VBO 1 for vertices
Bind VBO 1
Buffer VBO 1
Generate VBO 2 for uvs
Bind VBO 2
Buffer VBO 2
Make Current Window 2
Generate VAO 2
Bind VAO 2
Generate VBO 3 for vertices
Bind VBO 3
Buffer VBO 3
Generate VBO 4 for uvs
Bind VBO 4
Buffer VBO 4
Do shader stuff which gets shared
While True
Make Current Window 1
Clear
Bind VAO 1
Bind VBO 1
VertexAttribPointer VBO 1
Bind VBO 2
VertexAttribPointer VBO 2
glDrawArrays
Make Current Window 2
Clear
Bind VAO 2
Bind VBO 3
VertexAttribPointer VBO 3
Bind VBO 4
VertexAttribPointer VBO 4
glDrawArrays
Loop

But I end up only seeing drawing on one of two windows, if I reverse the order at the top so that the other window is made current at the beginning, then I see drawing on that window. Am I missing something being shared or not shared?

Dan Bartlett
07-29-2012, 04:43 AM
From Appendix D of the OpenGL 4.2 core spec:


Objects that can be shared between contexts include buffer objects, program
and shader objects, renderbuffer objects, sync objects, and texture objects (except
for the texture objects named zero).


Objects which contain references to other objects include framebuffer, program
pipeline, query, and vertex array objects. Such objects are called container objects
and are not shared.


So you can't use the VAOs you generate in the 2nd context, you will need to create new ones for that context.