Ogre3d really deserves some attention to deliver its full potential. A good example is the management of different version of shaders in a single program. In the image here above, the graphical cards are very different: the laptop has a low-end integrated intel chipset, the workstation is working with a GTX 980. The supported opengl version: glsl120 max for the laptop, vp40 for the gtx.

This information is dumped in terminal when the application starts, search for something like this:

Supported Shader Profiles: arbfp1 arbvp1 fp20 fp30 fp40 glsl glsl100 glsl110 glsl120 gp4fp gp4gp gp4vp gpu_fp gpu_gp gpu_vp nvgp4 vp30 vp40

Once identified, we can now prepare a program script to select shaders automatically.

In the .material:

material shader_tester
{
  technique{
    pass
    {
      fragment_program_ref tester_pix
      {
      }
    }
  }
}

In the .program:

fragment_program tester_pix_glsl glsl
{
  source tester_pix_120.glsl
}

fragment_program tester_pix_glsl_330 glsl
{
  source tester_pix_330.glsl
  syntax fp40
}

fragment_program tester_pix unified
{
  delegate tester_pix_glsl
  delegate tester_pix_glsl_330
}

The crucial instruction here is the syntax definition in fragment_program tester_pix_glsl_330. The available flags are listed here: Declaring Vertex/Geometry/Fragment Programs. The fragment_program tester_pix_glsl has no syntax flag, it will be used as the default one.

Shaders are stupidly simple in this case.

tester_pix_120.glsl

void main() {
  gl_FragColor = vec4( 0,1,0,1 );
}

tester_pix_330.glsl

#version 330
void main() {
  gl_FragColor = vec4( 1,0,0,1 );
}

And that’s it for the automatic selection of shaders in ogre.