View previous topic :: View next topic |
Author |
Message |
aldacron
Joined: 05 May 2004 Posts: 1322 Location: Seoul, South Korea
|
Posted: Fri May 14, 2004 12:56 pm Post subject: Load time |
|
|
When loading OpenGL extensions, I first check the extension string for each case using std.string.find. This worked well when I was only loading the GL_ARB extensions. Once I added GL_EXT, the increase in load time was noticeable. Right now, all of the GL_NV extensions are prototyped but before I implement the loading code I need to make a decision. The load time just is not acceptable.
Currently, all extensions are loaded with a call to dglLoadExtensions. This also loads all core version-specific open gl functions above 1.1. I'm going to change this. First, I'll implement a dglLoadCore. This will load the version-specific functions above 1.1 (1.1 will still be loaded in dglLoad, since the shared lib must be loaded and a context created first anyway). Each extension line will have its own load function: dglLoadARB, dglLoadEXT, dglLoadNV, and so on. This will eliminate the need to load all extensions all the time. If the user still desires to load all extensions, the current functionality will be retained in dglLoadExtensions.
Now, to improve the case where all extensions are loaded I need to either replace the calls to finc with something else (perhaps using c-style strings with strcmp?) OR just say bugger with checking the extension string and just attempt to load each extension. If the extension is not present, the getProc call will return null and life goes on. Either case will require a signficant rewrite (ugh ). A third option would be to leave it as is. I'm not too keen on doing that though. For some apps a slow startup would be noticeable.
I'd really like some opinions on this. Although this project is primarily for me, I have put it out here for the world to make use of. So whatever potential users might think will have a huge impact on how I handle this.
Thanks |
|
Back to top |
|
|
andy
Joined: 15 Mar 2004 Posts: 71
|
Posted: Fri May 14, 2004 3:19 pm Post subject: |
|
|
You could make proxy functions that search for the extension and replace themselves on call.
Code: | void _glThingieEXTproxy() {
function() proc = wglGetProcAddress(...);
if (proc) {
glThingieEXT = proc;
proc();
} else {
throw ...
}
}
function() glThingieEXT = &_glThingieEXTproxy; |
This way, everything initializes itself the first time it's used. The first call would obviously be the slowest, but after that, it should scream along at full speed.
You'd probably need to do some template magic and/or code-generating-script-writing, though. _________________ "Complacency is a far more dangerous attitude than outrage." - Naomi Littlebear |
|
Back to top |
|
|
aldacron
Joined: 05 May 2004 Posts: 1322 Location: Seoul, South Korea
|
Posted: Fri May 14, 2004 4:52 pm Post subject: |
|
|
Proxies are great for known states, such as during lazy instatiation when you are instancing a class which you know exists, or when you know the function you are calling exists in the shared lib you are loading (such as with the core GL functions). In those cases, a failure to instantiate the object or load the function really would be an exceptional case.
I just see it as a different story with OpenGL extensions. The absence of one extension or another is not exceptional. Also, one extension may have several functions associated with it. By loading all of the available extensions up front, Derelict can ensure that if one of the functions is not loaded for some reason, then that extension will be marked as not available (which the code in its current state does not account for, ahem). So when the user queries for a specific extension, they can be sure that all of the functions for that extension were successfully loaded. A proxy would take that burden out of the library and put it in the user's hands. |
|
Back to top |
|
|
aldacron
Joined: 05 May 2004 Posts: 1322 Location: Seoul, South Korea
|
Posted: Sat May 15, 2004 1:27 am Post subject: Re: Load time |
|
|
aldacron wrote: |
just say bugger with checking the extension string and just attempt to load each extension
|
FYI, ^^ is what I'm going with. It's a simple matter of having the wrapped extension proc address getter throw an exception on failure and catching it in the loader. If an exception is thrown for any of the functions belonging to an extension, that extension isn't flagged as supported. Also, it doesn't require too much to rewrite the existing code.
As such, this bit...
aldacron wrote: |
First, I'll implement a dglLoadCore. This will load the version-specific functions above 1.1 (1.1 will still be loaded in dglLoad, since the shared lib must be loaded and a context created first anyway). Each extension line will have its own load function: dglLoadARB, dglLoadEXT, dglLoadNV, and so on.
|
... just isn't needed. So externally nothing changes. |
|
Back to top |
|
|
andy
Joined: 15 Mar 2004 Posts: 71
|
Posted: Sat May 15, 2004 10:03 am Post subject: |
|
|
You have a point.
What you could do, though, is have the proxy function assert that an extention has been checked before its first use. This would prevent people from making apps that instantly explode when used on different hardware.
(they would instantly explode on *all* hardware) _________________ "Complacency is a far more dangerous attitude than outrage." - Naomi Littlebear |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|