FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to use DerelictGL in Derelict2

 
Post new topic   Reply to topic     Forum Index -> Derelict
View previous topic :: View next topic  
Author Message
aldacron



Joined: 05 May 2004
Posts: 1066
Location: Seoul, South Korea

PostPosted: Wed Mar 25, 2009 1:11 am    Post subject: How to use DerelictGL in Derelict2 Reply with quote

NOTE: DerelictGL should work with D1 Phobos, D1 Tango, and D2 Phobos now. Currently, I have not completely implemented support for platforms other than Windows. That will be rectified shortly, and I'll update this post when it is.

Until I get some proper documentation into the repo, here's a quick guide on using DerelictGL in Derelict2.

Here's some example source to get you started:

Code:

private
{
   import tango.io.Stdout;
   import derelict.opengl.gl;
   import derelict.sdl.sdl;
   import derelict.util.compat;
}

void main()
{
   DerelictSDL.load();
   DerelictGL.load();
   
   // initialize SDL
   if(SDL_Init(SDL_INIT_VIDEO) < 0)
   {
      throw new Exception("Failed to initialize SDL: " ~ toDString(SDL_GetError()));
   }
   scope(exit)
   {
      if(SDL_Quit !is null)
         SDL_Quit();
   }
   
   // set the minimum desired OpenGL parameters
   SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 16);
   SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
   SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 0);
   SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
   
   // create the SDL window
   if(SDL_SetVideoMode(800, 600, 0, SDL_OPENGL) == null)
   {
      throw new Exception("Failed to set video mode: " ~ toDString(SDL_GetError()));
   }
   
        // HERE IS WHERE THINGS ARE DIFFERENT
   // load the maximum avaliable version of OpenGL
   DerelictGL.loadExtendedVersions();
   DerelictGL.loadExtensions();
   
   string[] loaded = DerelictGL.loadedExtensionNames;
   string[] notLoaded = DerelictGL.notLoadedExtensionNames;
   
   Stdout("Loaded extensions:").newline;
   foreach(n; loaded)
      Stdout.formatln("\t{}", n);
   
   Stdout("Not loaded extensions:").newline;
   foreach(n; notLoaded)
      Stdout.formatln("\t{}", n);
}


For the most part, the code here is the same as it would be in Derelict 1. The difference is in how OpenGL versions greater than 1.1 and the extensions are loaded.

The function DerelictGL.loadExtendendVersions(GLVersion min = GLVersion.GL11) takes an optional arg that specifies which version of OpenGL you require. If that version is unsupported by the driver (as reported by glGetString(GL_VERSION), a DerelictException will be thrown. If the driver reports it is supported, but any of the functions from that vesion and lower fail to load, a SymbolLoadException will be thrown. An attempt will be made to load any higher versions the driver supports, but no exceptions will be thrown if they fail to load. The default behavior when no args are passed (as in the example above) is the same as passing GLVersion.GL11, i.e., it will attempt to load the highest version available and no exceptions will be thrown on failure.

To determine the highest version available for you to use after calling loadExtendedVersions, you can call DerelictGL.maxVersion.

The extension loading framework is greatly streamlined from Derelict 1. No longer are there separate modules for each extension. They are now contained within two files only: exttypes.d and extfuncs.d. Both modules are publicly imported in glext.d, so you can import just that to use them. You also don't need to import any of these three modules to load the extensions. Previously, extension loaders were registered with static module constructors. You could import only the extension modules you needed, or import them all, including all of the static constructors, with glext. No more.

To load the extensions, you need just the main derelict.opengl.gl module. A single call to DerelictGL.loadExtensions will load every OpenGL extension that Derelict supports. You can then query two methods to see if a function is supported or loaded: DerelictGL.isExtensionSupported(string extName) tests if the driver supports an extension. DerelictGL.isExtensionLoaded(string extName) will tell you whether or not an extension is currently loaded. If this returns false, you can test the return of isExtensionSupported to determine if the extension is loaded because it is unsupported or because it failed.

There are also two new methods which can be useful for debugging or logging (they've helped me find a couple of bugs in the extension loader itself already). DerelictGL.loadedExtensionNames and DerelictGL.notLoadedExtensionNames both return an array of extension name strings. In the case of the former, it is all loaded extensions. In the case of the latter, it is all extensions which are not loaded, appended with "(Unsupported)" if the driver does not support it, or "(Load Failed") if the driver reports it as supported but it failed to load. Currently, there is no mechanism for determining at runtime if DerelictGL has support for an extension. I don't anticipate that there will be either. The documentation will list all supported extensions.

I encourage you to give this a try and see how it works for you. For me, I've noticed quite a big difference in compile times between this version of DerelictGL and the original, especially when building with DSSS. Granted, I don't have the same number of extensions implemented yet, but once they are I anticipate the compile time to remain shorter. As always, please report any bugs or issues you may find, preferably as a ticket. Thanks!
_________________
The One With D | The One With Aldacron
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> Derelict All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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