OpenGL wglShareLists and multiple render windows

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 on other sites
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
- 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 on other sites
Quote:
 Original post by V-manYes, 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 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 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 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 towglMakeCurrent()....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 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?

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 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 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 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?

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 on other sites
Quote:
Original post by steven katic
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 and many other CAD and content creation software.

now you are confusing me.

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

Sorry for using 3dS max as an example since you seemed to have read some in depth material about it and it is rather lengthy.

All I'm saying is that instead of having 2 windows, just make 1, use half of the window for 1 thing and the other half for something else.

If that is not possible for you then I think the previous answers here cover all your questions.

Share on other sites
Quote:
 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.

come on now...you should be careful...it sounds like you are clutching at straws to justify its use to me - there is no need to justify any of your actions. I am here to discuss...not to convince..or to otherwise be convinced of anything.

Having said that I'lI continue to be blunt:
I fail to see any reason in that statement, let alone a compelling one to cease the use of wglShareLists() the way I do.

All I see there is a statement that applies equally to the shared contexts implementation I have. The major difference being that I have a context switch statement as the first statement in my viewport rendering function. In fact it is probably the only code wise difference to be had (I guess my implementation just happens to be organised in such a way by chance that allows me to say that i.e. point is it depends on you application implementation).OOps - should be real easy to just change it over to the one context multiple window method then!!! I put my foot in it now hey?

I can give you an example of how simple it works if you like?

In the meantime, if I were to try and convince you of anything..it would be to go with the 1 context with multiple windows - I actually want to know how it compares - but I'm to lazy to do the research! (But you have to be kind enough to share what you have learnt from it with us....*gulp*

V-man
Quote:
 Sorry for using 3dS max as an example since you seemed to have read some in depth material about it and it is rather lengthy.

I found it in a galaxy far, far away,... long ago, and the haze is temporarily lifting from my memory, so I have to type quickly...before it returns!(this is now a memory... of a memory...of a memeory...of a mem.. unfortunately). It is probably ONE of the real reasons that prompted me to go with the multiple shared contexts concept. I had a soft spot for 3dsMax long ago and had to find out everything I could about how they implemented there multitude of windows. Being such a powerful premium product of choice was compelling enough a reason to attempt to emulate bits of it; Perhaps not much empirical rigor in that logic at all hey? Then the little boy grew up a little, hopefully.
Rather lengthy you say? Nah... Hey what do you think I read that stuff? It's reference material, scan it for info like I do, don't read it!

Quote:
 All I'm saying is that instead of having 2 windows, just make 1, use half of the window for 1 thing and the other half for something else.Multithreading not required.

yeah well....its not the contents(it may be dated info?) of that 3dsMax document that is important, it is its possible level of credibility that is important compared to your statement about 3dsMax.

[Edited by - steven katic on May 10, 2008 4:37:48 PM]

Share on other sites
Quote:
Original post by steven katic
Quote:
 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.

come on now...you should be careful...it sounds like you are clutching at straws to justify its use to me - there is no need to justify any of your actions. I am here to discuss...not to convince..or to otherwise be convinced of anything.

It's not like I'll win a free trip to moon if I manage to convince you?! I can't believe how you started getting so defensive all of a sudden after being so helpful all the way. I was just expressing my opinion for the sake of discussion and I don't see any reason to start getting hostile. If you're not convinced that managing one rendering context instead of several is both easier and more convinient, so be it. We have different opinions, big deal. Even if I was blindly insisting on a falacy, which I was *not*... well, it's my loss if I want to act blindly and there's no need for you to get defensive over it.

Thank you both of you guys for sharing your knowledge with me.

Share on other sites
Something you may find interesting Ashkan:
I thought I would start a little investigating into the notorious expense of opengl render context switching vs 1 context + multiple device contexts.

I also said:
Quote:
 OOps - should be real easy to just change it over to the one context multiple window method then!!! I put my foot in it now hey?

And it is true: All I did is the following:
private: System::Void ShareGLContexts(){   /**** (A)changed this ***********************/   // get the contexts to share resources   HGLRC c1 = m_OpenglViewports[0]->GetContext();   HGLRC c2 = m_OpenglViewports[1]->GetContext();   HGLRC c3 = m_OpenglViewports[2]->GetContext();   HGLRC c4 = m_OpenglViewports[3]->GetContext();   // whats with the going overboard with sharing both ways?: could be a problem.   if(!wglShareLists( c1,c2  ) || !wglShareLists( c3,c2  ) ||       !wglShareLists( c4,c2  ) || !wglShareLists( c2,c1  ) ||      !wglShareLists( c2,c3  ) || !wglShareLists( c2,c4  ) )   {      bGLContextShared = false;   }   /* (B)to this: *************************/   // 4 devices sharing one render context test   		    HGLRC c1 = m_OpenglViewports[0]->GetContext();			   m_OpenglViewports[1]->SetContext(c1);   m_OpenglViewports[2]->SetContext(c1);   m_OpenglViewports[3]->SetContext(c1);}

So far in testing nothing has changed: not even my fps metric of 260(or so I thought).
I tried out gDebugger for more reliable metrics and it records the following:
Option (A) 4 shared render contexts: 130 fps.[edited: 15th may 08 only 2 contexts where mesured!]
(Edit 15th may 08: Option(A) 4 shared contexts where all 4 where measured (65 fps per context)
Option (B) 1 render context shared among 4 DCs 260 fps.

Now that might be potentially compelling (so far). But something is not right (e.g. My fps counter?, or the way I use gDebugger is not right?). I need to continue testing, but with more rigor before making conclusions just yet. I must say gDebugger's metrics/testing options are very impressive (and very quick and easy to use).

Something of maybe more interest Ashkan, may be talk from here:
Quote:
 ...today with FBOs, there's no reason to use more than one context per GPU. You either just don't need it(no Pbuffers anymore) or got something else wrong (there' s no point in talking to the same gfx cards from two threads concurrently)....

FBO specs (and other docs) do mention FBO superiority to and substitution for context switching. Apparently different precision depths(you mention) can be achieved if you delve further into the use of FBOs. However, I have my doubts about FBO as suitable for multi windows (could it be a square peg for a round whole?): meaning "try it see" tests are required (there are 2 typical uses of FBOs, mutli windows is not one of them, as far as I can tell so far).

Hope this tentative speculation has been of interest.

[Edited by - steven katic on May 15, 2008 5:59:04 AM]

Create an account

Register a new account

• Forum Statistics

• Total Topics
628379
• Total Posts
2982344
• Similar Content

• Hi all,

I'm starting OpenGL using a tut on the Web. But at this point I would like to know the primitives needed for creating a window using OpenGL. So on Windows and using MS VS 2017, what is the simplest code required to render a window with the title of "First Rectangle", please?

• Hi, New here.
I need some help. My fiance and I like to play this mobile game online that goes by real time. Her and I are always working but when we have free time we like to play this game. We don't always got time throughout the day to Queue Buildings, troops, Upgrades....etc....
I was told to look into DLL Injection and OpenGL/DirectX Hooking. Is this true? Is this what I need to learn?
How do I read the Android files, or modify the files, or get the in-game tags/variables for the game I want?
Any assistance on this would be most appreciated. I been everywhere and seems no one knows or is to lazy to help me out. It would be nice to have assistance for once. I don't know what I need to learn.
So links of topics I need to learn within the comment section would be SOOOOO.....Helpful. Anything to just get me started.
Thanks,
Dejay Hextrix
• By mellinoe
Hi all,
First time poster here, although I've been reading posts here for quite a while. This place has been invaluable for learning graphics programming -- thanks for a great resource!
Right now, I'm working on a graphics abstraction layer for .NET which supports D3D11, Vulkan, and OpenGL at the moment. I have implemented most of my planned features already, and things are working well. Some remaining features that I am planning are Compute Shaders, and some flavor of read-write shader resources. At the moment, my shaders can just get simple read-only access to a uniform (or constant) buffer, a texture, or a sampler. Unfortunately, I'm having a tough time grasping the distinctions between all of the different kinds of read-write resources that are available. In D3D alone, there seem to be 5 or 6 different kinds of resources with similar but different characteristics. On top of that, I get the impression that some of them are more or less "obsoleted" by the newer kinds, and don't have much of a place in modern code. There seem to be a few pivots:
The data source/destination (buffer or texture) Read-write or read-only Structured or unstructured (?) Ordered vs unordered (?) These are just my observations based on a lot of MSDN and OpenGL doc reading. For my library, I'm not interested in exposing every possibility to the user -- just trying to find a good "middle-ground" that can be represented cleanly across API's which is good enough for common scenarios.
Can anyone give a sort of "overview" of the different options, and perhaps compare/contrast the concepts between Direct3D, OpenGL, and Vulkan? I'd also be very interested in hearing how other folks have abstracted these concepts in their libraries.
• By aejt
I recently started getting into graphics programming (2nd try, first try was many years ago) and I'm working on a 3d rendering engine which I hope to be able to make a 3D game with sooner or later. I have plenty of C++ experience, but not a lot when it comes to graphics, and while it's definitely going much better this time, I'm having trouble figuring out how assets are usually handled by engines.
I'm not having trouble with handling the GPU resources, but more so with how the resources should be defined and used in the system (materials, models, etc).
This is my plan now, I've implemented most of it except for the XML parts and factories and those are the ones I'm not sure of at all:
I have these classes:
For GPU resources:
Geometry: holds and manages everything needed to render a geometry: VAO, VBO, EBO. Texture: holds and manages a texture which is loaded into the GPU. Shader: holds and manages a shader which is loaded into the GPU. For assets relying on GPU resources:
Material: holds a shader resource, multiple texture resources, as well as uniform settings. Mesh: holds a geometry and a material. Model: holds multiple meshes, possibly in a tree structure to more easily support skinning later on? For handling GPU resources:
ResourceCache<T>: T can be any resource loaded into the GPU. It owns these resources and only hands out handles to them on request (currently string identifiers are used when requesting handles, but all resources are stored in a vector and each handle only contains resource's index in that vector) Resource<T>: The handles given out from ResourceCache. The handles are reference counted and to get the underlying resource you simply deference like with pointers (*handle).
And my plan is to define everything into these XML documents to abstract away files:
Resources.xml for ref-counted GPU resources (geometry, shaders, textures) Resources are assigned names/ids and resource files, and possibly some attributes (what vertex attributes does this geometry have? what vertex attributes does this shader expect? what uniforms does this shader use? and so on) Are reference counted using ResourceCache<T> Assets.xml for assets using the GPU resources (materials, meshes, models) Assets are not reference counted, but they hold handles to ref-counted resources. References the resources defined in Resources.xml by names/ids. The XMLs are loaded into some structure in memory which is then used for loading the resources/assets using factory classes:
Factory classes for resources:
For example, a texture factory could contain the texture definitions from the XML containing data about textures in the game, as well as a cache containing all loaded textures. This means it has mappings from each name/id to a file and when asked to load a texture with a name/id, it can look up its path and use a "BinaryLoader" to either load the file and create the resource directly, or asynchronously load the file's data into a queue which then can be read from later to create the resources synchronously in the GL context. These factories only return handles.
Factory classes for assets:
Much like for resources, these classes contain the definitions for the assets they can load. For example, with the definition the MaterialFactory will know which shader, textures and possibly uniform a certain material has, and with the help of TextureFactory and ShaderFactory, it can retrieve handles to the resources it needs (Shader + Textures), setup itself from XML data (uniform values), and return a created instance of requested material. These factories return actual instances, not handles (but the instances contain handles).

Is this a good or commonly used approach? Is this going to bite me in the ass later on? Are there other more preferable approaches? Is this outside of the scope of a 3d renderer and should be on the engine side? I'd love to receive and kind of advice or suggestions!
Thanks!
• By nedondev
I 'm learning how to create game by using opengl with c/c++ coding, so here is my fist game. In video description also have game contain in Dropbox. May be I will make it better in future.
Thanks.

• 10
• 9
• 15
• 24
• 11