When writing a shader for one of my projects, I encountered a need to define an OpenGL version and whether GLSL is supported on the used machine. Assume, I have some geometry and there are two ways to render it: simplified version and fancy version. The simplified version uses some default primitive, e.g.,
GL_LINE_STRIP_ADJACENCY. The fancy version requires certain minimal OpenGL version so that to use the shaders I just wrote.
Since in OpenSceneGraph we normally do not deal with OpenGL commands directly, I had to find a way how to define the supported OpenGL versions through the OSG library.
Tester class for supported OpenGL version
The OSG examples already have an example that provides an idea how to request certain OpenGL constants. For instance, OsgShaderTerrain example. I took the derived class from
osg::GraphicsOperation and modified it so that it returned the OpenGL version. Below is an example of how such tester class is implemented:
Now, when using the
TestSupportOperation class we can easily obtain the OpenGL version by refering to the class’ public variable:
A very simplified case usage (empty scene) is presented below: