Everybody is starting into a new year with good resolutions, so you can now take an advantage of modern OpenGL3+ concepts with OGRE .

Shader storage blocks

The first one is “Uniform Buffer Objects” (UBO) and “Shader Storage Buffer Objects” (SSBO) or simply “shared GPU Parameters” in OGRE speak.
The shared GPU parameters have gained a backing HardwareBuffer which is used for communicating with the GPU.
With OpenGL this can be either a UBO or SSBO which is detected from your shader code and automatically bound if possible.
In case of a SSBO it is possible to read-back the data from the GPU, which is triggered by the new GpuSharedParameters::download() method.
This gives you an easy way to retrieve results from the GPU without rendering to a Texture or Vertex Buffer.

Separate Shader Objects and SPIRV

Traditionally OGRE internally uses monolithic programs for GLSL that explicitly glue vertex and fragment shaders together. Notably, this means the GpuProgramParameters are only valid per combination and not per individual shader.

However, from the API perspective Ogre always exposed the DirectX model without explicit grouping – e.g. in material scripts. This approach is commonly referred to as “mix and match”.

Ogre tries hard to hide this difference for you. For instance one can only retrieve the active uniforms from GLSL once it is linked. This happens on the first render call in OpenGL – instead of at material parsing time when OGRE would need it.
Therefore OGRE goes ahead and parses the GLSL source code itself to figure out the available uniforms. Needless to say, this is quite error prone and does not support more advanced constructs e.g. struct uniforms.

Fortunately, OpenGL provides the DirectX like behaviour via “Separate Shader Objects” (SSO) that allow linking individual shaders and bundling them to pipelines later.
Now we finally take advantage of them and at this also uses ARB_program_interface_query for parsing the uniforms in a standard way and cover all corner cases.
Notably, this allows us to reference uniforms by location only – like in the good old assembly days:

vertex_program Ogre/Compositor/StdQuad_Tex2a_vp spirv
{
    source StdQuad_Tex2a_vp.vert.spv
    default_params
    {
        param_indexed_auto 0 worldviewproj_matrix
    }
}

The corresponding GLSL code for that uniform would be

layout(location = 0) uniform mat4 worldViewProj;

You might wonder why you should care; if you look closely the material snippet above is using SPIRV binary shaders, where the uniform names are stripped away and only the locations are available.

Therefore this is necessary for support of pre-compiled SPIRV shaders, which is now complete.

And while we are at it – why are SPIRV shaders cool? Well, you can compile HLSL to SPIRV and then use it with OpenGL 😉
Also, this is a pre-requisite for the Vulkan back-end and this way you can prepare you shader authoring accordingly.

If you would like to learn more about using SPIRV in OGRE, see here.

Currently (in master) you have to manually enable SSO support via the “Separate Shader Objects” RenderSystem option.
Using OpenGL for shader parsing has some side effects; notably you will now get errors when trying to set an unused (and thus optimized away) uniform. Typically this means your shader is broken – but we traditionally keep your code working during a release support period.