[osg-users] openGL extensions

Jean-Sébastien Guay jean-sebastien.guay at cm-labs.com
Mon Sep 22 17:12:25 PDT 2008

Hi Ben,

> I would like to detect if the user has the appropriate openGL extensions 
> in order to do shadowing.  However, when I do:
> glGetString(GL_VERSION)
> glGetString(GL_EXTENSIONS)
> They return null.  How can I get a list of the available extensions?  Is 
> there an easy way to get this info from OSG?

For the first part of your question, they return NULL if they were 
called from a thread that does not have a graphics context. The safest 
way to do this is to create a camera predraw/postdraw/finaldraw callback 
or a node cull callback or a drawable draw callback. In each of these 
points you will have a graphics context.

What I generally do is assume support is present and start the viewer 
with a detection callback attached (camera predraw callback on the main 
camera) which will check extensions and then remove itself from the 
camera. Then after the first frame, if I see that some feature is not 
supported, I disable the relevant options.

There are other valid strategies of course.

As for detecting actual extensions, instead of calling 
glGetString(GL_EXTENSIONS) and parsing it yourself, you can use

#include <osg/GLExtensions>
#include <osg/GL2Extensions>

osg::isGLExtensionSupported(contextID, extensionName)

> Also, how do I know which extensions I need for the different shadow 
> techniques?

I'm personally not sure which extensions are required for all of them, 
perhaps someone else will know (it might be good to add that info to the 
osgShadow page on the wiki). I can tell you what I test for in the case 
of osgShadow::ShadowMap:

_shadowsSupported =
     "GL_EXT_framebuffer_object") &&
     "GL_ARB_fragment_program") ||
     "GL_EXT_fragment_program")) &&
     "GL_ARB_fragment_program_shadow") ||

Not sure if that's totally correct, but in most cases where shadow maps 
were not supported (they fell back to software and so were extremely 
slow) it was the first (GL_EXT_framebuffer_object) which was not supported.

Hope this helps,

Jean-Sebastien Guay    jean-sebastien.guay at cm-labs.com

More information about the osg-users mailing list