Jump to content
  • Advertisement
Sign in to follow this  
Ashkan

OpenGL wglShareLists and multiple render windows

This topic is 3783 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

MSDN is the only crediable source on wiggle (that I know of) and it's pretty much outdated with plenty of missing functions so there's usually some sort of dark magic involved if one is about to step outside the cozy shelter and enter the dark realm of lesser-used functions. wglShareLists() is one member of this family. MSDN states that this function informs OpenGL server to share the diplay-list space between several rendering contexts but it never talks about other server-side resources. I'm assuming that other server-side resources such as textures and VBOs are also shared, but to my experience server-side states are not. I've been playing around with wglShareLists() for a few days now so my knowledge on the subject is limitted. My interpretation might also be completely wrong, especially considering the scarce documentaion that's available but my experience is that server-side states (states that are set by glEnable/glDisable for instance) are not shared between the rendering contexts so they must be explicitly set for every single rendering context that's available, which is a pain in the rear end in applications with multiple render window setups. These states tend to get out of synch and cause headaches in the long run. So my first question is this: Do you have any experience with wglShareLists()? What's your take on the aforementioned dilemma? As far as I'm concerned, D3D's architecture is a whole lot cleaner in this regard. In D3D, pipeline states are stored inside the device object, which, as far as I know, is not directly related or bound to a window. These states are shared among all windows which in turn, are represented by swap chains. There is always at least one swap chain for each device, known as the implicit swap chain. However, an additional swap chain for rendering multiple views from the same device can be created. In OpenGL, rendering contexts are bound to windows (rendering contexts are bound to device contexts which in turn are bound to windows, to be exact), which makes sharing them non-trivial considering the set of functions that are available. I even went as far as creating a dummy rendering context that's attached to a dummy window and used that as a hub to share other states, but you see, wglShareLists doesn't allow sharing of states. So, do you know of a workaround? Did you find this issue problematic? Thanks

Share this post


Link to post
Share on other sites
Advertisement
Yes, MSDN is outdated. It will soon be updated *

wglShareLists is not such a great name for the function, but essentially it shares objects between 2 or more GL contexts :
- display lists (essentially replaced by VBO/IBO)
- VBO/IBO
- shaders
- textures
- FBO
- PBO

* just kidding

Quote:
I even went as far as creating a dummy rendering context that's attached to a dummy window and used that as a hub to share other states, but you see, wglShareLists doesn't allow sharing of states.


Try just making 1 GL context and use them for both windows.

Share this post


Link to post
Share on other sites
Quote:
Original post by V-man
Yes, MSDN is outdated. It will soon be updated *

wglShareLists is not such a great name for the function, but essentially it shares objects between 2 or more GL contexts :
- display lists (essentially replaced by VBO/IBO)
- VBO/IBO
- shaders
- textures
- FBO
- PBO

* just kidding


You certainly got me for a moment [smile] I thought you work for microsoft or something [grin]

Quote:

Quote:
I even went as far as creating a dummy rendering context that's attached to a dummy window and used that as a hub to share other states, but you see, wglShareLists doesn't allow sharing of states.


Try just making 1 GL context and use them for both windows.


But how?! Each rendering context must be associated with a device context (wglCreateContext needs that) and each window has a device context of its own. So, I think the question boils down to this: how can several windows share a device context? Or am I missing something? A code snippet might help clarify these points.

Any help is greatly appreciated.

Share this post


Link to post
Share on other sites
Yes, wglCreateContext takes a HDC as a parameter but I think the driver doesn't care as other people seem to be doing this for a long time. I don't know what things you must respect. Perhaps both windows must be created from the same process. It shouldn't matter if both windows are created in the same thread or not. I think both windows must be on the same graphics card. If 2 graphics cards are used (like 2 nvidia's), the driver would do some management so it would work.
The pixelformat you give to SetPixelFormat should be the same.

Share this post


Link to post
Share on other sites
Quote:

....server-side states (states that are set by glEnable/glDisable for instance) are not shared between the rendering contexts so they must be explicitly set for every single rendering context that's available, which is a pain in the rear end in applications with multiple render window setups. These states tend to get out of synch and cause headaches in the long run. So my first question is this: Do you have any experience with wglShareLists()? What's your take on the aforementioned dilemma?


First, the most important question I have is:
What are you using multiple windows for?

Then the others:
Can you give an example of "states get out of sync"?

My thinking is quite different (maybe I am just stuck with thinking of making the best of what apis have to offer to date?): I cannot see a real dilemma(until you answer the "states get out of sync" and other question above perhaps).

Quote:

...experience with wglShareLists()?

wglShareLists() can actually be well suited to mfc or forms applications(once you get over its undocumented idiosyncracies): windows manages the err..windows, and each window's contents is managed (or rather rendered) by the graphics api of choice..(obviously opengl, in this case). However, this depends on your specific application too really. The example application I have in mind is something like 3ds max: in so far has having multiple views of the same scene, and even numerous other windows that may display other things such as materials/texures.

The only real disadvantage of not being able to share state changes with wglShareLists I can see is:
You have already mentioned-> making unneccessary server-side state calls(e.g. having to Re-glEnable()/Re-glDisable() etc..of the same state after a context change). Ultimately, you could minimize the number of server-side state change calls which is apparently always good (some would say critical) for max performance. And it's even better if you do not need to change any more states after that!

See any others?

From the point of view that states do change and each window has the option of rendering its contents differently:
I would still want to manage/keep track of my state changes.
Whether they are 'global' to all(or more than 1) contexts or only 'local' to each context. Interestingly, let's just say I could share state changes among contexts via wglShareLists() and I still want to manage/keep track of state changes for what gets rendered in each window. I would hope for increased performance, but managing those state changes could become a little more complex as I may need to then consider which states I am dealing with, the 'global' ones(where more than one window currently shares it) or the 'local' ones(one window's current state). A minor price to pay if the performance increase is worth it. So, in a way, in this case, if you have a lot of state changes happening, your task of managing them becomes more complex, unless each state change applies to every window all the time (i.e. not only multiple windows, but duplicate windows? for what purpose?)

I imagine possible performance enhancements may be had by a programmer actually implementing such a similar scheme even in a one windowed app to avoid the notorious redundant state change?(By the by, non-pure directx devices can be more forgiving, filtering out redundant state changes)

So, after all that, I would presume that you are really searching for a better way to manage your server-side state changes(Your "states get out of sync" remark is indicative of this to me) instead of assuming server-state sharing may be a solution to your pain?
Yes? No?

Terrible, aren't I, answering the question I wish you had asked, instead of answering the question you actually asked? Maybe I should become a politician (but it pays too much and I am not a very good liar).

Or maybe I am barking up the wrong tree? woof. It's easy to do.

Quote:

....So, do you know of a workaround? Did you find this issue problematic?

Since when is programming not problematic! ;)
I think I know what you mean: realtively speaking, no: You may just need to be more (boringly) systematic in your approach as the size of your state changes
grow. It depends how many state changes per frame you have to manage.
Again, with your "states out of sync" problem you either have hundreds/thousands or you are finding it difficult to manage the few you have.

Tell us. Who knows, maybe "Try just making 1 GL context and use them for both windows" may just be more suitable. There's nothing wrong with throwing it out there as an option, but I see no evidence to presume it happens to be the most suitable one?

RE: wglShareLists() undocumented idiosyncracies. e.g. I have found that in a forms application the contexts of 4 views works appropriately only before any context is actually made current (i.e. call wglShareLists() before any calls to
wglMakeCurrent()....go figure ( the cause could be elsewhere?...but this was a solution).

Share this post


Link to post
Share on other sites
OK, maybe I went too far with my "states get out of synch" statement, or maybe you just based too much of your arguments on that [smile]. Anyway, all I meant was that having to manage a different set of states for every single window is sure too much work to do. My argument was mainly a result of comparing OpenGL's unintuitive approach and D3D's more elegant method of handling things in this regard (that's just my opinion).

I haven't yet experimented with V-man's approach (i.e. having a single rendering context for multiple windows), but as there seems to be quite a few people suggesting that approach (I asked the same question at OpenGL.org forums and got the same answer; greedy me!), I'm going to assume that it works well which as far as I'm conrened is miles better than using wglShareLists, but the downside to both of these approaches (i.e. 1- having one rendering context for multiple windows and 2- using wglShareLists to share server-side resources), is that all DCs must have the same pixel format, which is even a greater concern compared to the aforementioned state management issue. What if I want to enable anti-aliasing for one of my windows and disable that on all others? What if I want to have several windows with different depth percisions? Should I load all server-side resource several times? You've gotta admit that this really sucks.

Quote:
Tell us. Who knows, maybe "Try just making 1 GL context and use them for both windows" may just be more suitable. There's nothing wrong with throwing it out there as an option, but I see no evidence to presume it happens to be the most suitable one?

So why do you prefer using wglShareLists()?

Quote:

RE: wglShareLists() undocumented idiosyncracies. e.g. I have found that in a forms application the contexts of 4 views works appropriately only before any context is actually made current (i.e. call wglShareLists() before any calls to
wglMakeCurrent()....go figure ( the cause could be elsewhere?...but this was a solution).

You mean one should call wglShareLists() before ANY calls to wglMakeCurrent() or only before wglMakeCurrent() calls that take place on the rendering context that's to be shared?

Share this post


Link to post
Share on other sites
Quote:
OK, maybe I went too far with my "states get out of synch" statement, or maybe you just based too much of your arguments on that .


No problem. If I had to enter a plea it would be: guilty as charged.
I kept on thinking "how do you do that"? So I invented my little "server state mis-management" agenda. sorry.

So, are you now saying your states do not get out of sync? Did you try to go for a more dramatic effect or something? Well... it worked!

Quote:

My argument was mainly a result of comparing OpenGL's unintuitive approach and D3D's more elegant method of handling things in this regard (that's just my
opinion).


That is easily evident from your orginal D3D comments. And I would slightly tend to agree (if I forced myself).

Quote:

..but the downside to both of these approaches (i.e. 1- having one rendering context for multiple windows and 2- using wglShareLists to share server-side resources), is that all DCs must have the same pixel format, which is even a greater concern compared to the aforementioned state management issue. What if I want to enable anti-aliasing for one of my windows and disable that on all others? What if I want to have several windows with different depth percisions? Should I load all server-side resource several times? You've gotta admit that this really sucks.


fair enough. Being in a pragmatic state of mind, I guess the majority of what's left of the opengl graphics programming community has bitten the bullet(waiting...and waiting..and waiting...for..what is it..that new thing...Opengl 3.0?) and tolerated it to date, if they haven't already moved over exclusively to Directx. If there was an actual specific problem you are trying to present, maybe I could respond in a better way (I'll assume you just need to express your frustration).

Quote:

So why do you prefer using wglShareLists()?

I cannot really give you any compelling reasons why. It's the first thing I found that allowed me to share those resources listed above in as many windows as I want. Pretty simple really, and it's worked fine ever since. Now I guess if someone gave me a compelling reason to simply change to one rendering context for multiple windows(e.g. increase my current 260fps in 4 views to say ...I dunno..300fps) I might consider not using it any longer(and go with the flow?..hoping as little as possible server state-changing/management code would need to be reorganised to make it worth it...now that would be a dilemma!).

Quote:

I'm going to assume that it works well which as far as I'm conrened is miles better than using wglShareLists

I'd like to hear how it goes. Give me a compelling reason to do likewise and I won't be able to resist joining you.

Quote:

You mean one should call wglShareLists() before ANY calls to wglMakeCurrent() or only before wglMakeCurrent() calls that take place on the rendering context that's to be shared?


sorry about that. To clarify:
Call wglShareLists() on shared contexts before any of those shared contexts are made current with wglMakeCurrent(). So that implies wglMakeCurrent() can be called before wglShareLists() as long as it is called on a context you do not intend to be a sharer/sharee (hope that's better - it only occurs in C++ forms applications. No such problem in mfc apps). (incidently, you should view this problem for what it is: an isolated incident...until it is/has been shown to be repeatable by others - as you said - since not much info around about wglShareLists() ).

Share this post


Link to post
Share on other sites
Quote:
What if I want to enable anti-aliasing for one of my windows and disable that on all others? What if I want to have several windows with different depth percisions? Should I load all server-side resource several times? You've gotta admit that this really sucks.


Yes, that is correct.
In general, like the previous person said it's better to just have 1 window with multiple views just like 3dS max does andmany other CAD and content creation software.

Share this post


Link to post
Share on other sites
Quote:

Yes, that is correct.
In general, like the previous person said it's better to just have 1 window with multiple views just like 3dS max does andmany other CAD and content creation software.

now you are confusing me.

apparently, 3ds max used to be a slightly different beast again:

"Since MAX is highly multi-threaded, it is absolutely imperative that the OpenGL driver be thread safe. In particular, MAX maintains one "draw thread" per viewport (four total), and these threads create and hold on to their own OpenGL rendering contexts (OGLRC) for the entire run of MAX. In more detail, the contexts are created and made current at the beginning of the MAX session (one context per each of the four drawing threads), and the four contexts remain current in their respective threads until MAX is terminated. "

if this ancient history is to be believed from here Some pertinent questions would be:

(1)would said opengl contexts have been shared?(an almost rhetorical question?)

(2)Does it apply to the latest 3dsmax today?
Another almost rhetorical question, but more unanswerable than rhetorical.

Share this post


Link to post
Share on other sites
Thank you both of you guys.

Quote:

Quote:

My argument was mainly a result of comparing OpenGL's unintuitive approach and D3D's more elegant method of handling things in this regard (that's just my
opinion).


That is easily evident from your orginal D3D comments. And I would slightly tend to agree (if I forced myself).

I'd like to add that I'm not bashing OpenGL in anyway... and not that you implied that I'm influenced by such mentality. Far from it. I just wanted to clarify that I like both APIs the same and my only purpose is to get myself acquianted with the quirks. D3D has its own weaknesses too.

Quote:

Quote:

..but the downside to both of these approaches (i.e. 1- having one rendering context for multiple windows and 2- using wglShareLists to share server-side resources), is that all DCs must have the same pixel format, which is even a greater concern compared to the aforementioned state management issue. What if I want to enable anti-aliasing for one of my windows and disable that on all others? What if I want to have several windows with different depth percisions? Should I load all server-side resource several times? You've gotta admit that this really sucks.


fair enough. Being in a pragmatic state of mind, I guess the majority of what's left of the opengl graphics programming community has bitten the bullet(waiting...and waiting..and waiting...for..what is it..that new thing...Opengl 3.0?) and tolerated it to date, if they haven't already moved over exclusively to Directx. If there was an actual specific problem you are trying to present, maybe I could respond in a better way (I'll assume you just need to express your frustration).


It seems that the community has been waiting for OpenGL 3.0 forever...

Back to our discussion, to reiterate my earlier question, do you know of an approach that allows several windows to have different pixel formats while the server-side resources are still shared?

Quote:

Quote:

So why do you prefer using wglShareLists()?

I cannot really give you any compelling reasons why. It's the first thing I found that allowed me to share those resources listed above in as many windows as I want. Pretty simple really, and it's worked fine ever since. Now I guess if someone gave me a compelling reason to simply change to one rendering context for multiple windows(e.g. increase my current 260fps in 4 views to say ...I dunno..300fps) I might consider not using it any longer(and go with the flow?..hoping as little as possible server state-changing/management code would need to be reorganised to make it worth it...now that would be a dilemma!).

Quote:

I'm going to assume that it works well which as far as I'm conrened is miles better than using wglShareLists

I'd like to hear how it goes. Give me a compelling reason to do likewise and I won't be able to resist joining you.

It addresses the first issue: state management. You won't be needing to keep track of states for different rendering contexts since all states reside in a single context. It simplifies the design to some extent. Of course, you'd be needing some form of state management to cull redundant states.

Quote:

Quote:

You mean one should call wglShareLists() before ANY calls to wglMakeCurrent() or only before wglMakeCurrent() calls that take place on the rendering context that's to be shared?


sorry about that. To clarify:
Call wglShareLists() on shared contexts before any of those shared contexts are made current with wglMakeCurrent(). So that implies wglMakeCurrent() can be called before wglShareLists() as long as it is called on a context you do not intend to be a sharer/sharee (hope that's better - it only occurs in C++ forms applications. No such problem in mfc apps). (incidently, you should view this problem for what it is: an isolated incident...until it is/has been shown to be repeatable by others - as you said - since not much info around about wglShareLists() ).


Thanks for the tip.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!