Construct GLUniforms to access uniforms in a GLProgram.
We have a vertex shader with source such as this:
#version 130 uniform mat4 projection; uniform mat4 modelView; in vec3 position; void main() { gl_Position = projection * modelView * vec4(position, 1.0); }
We have the following uniforms specification struct:
struct Uniforms { import gl3n.linalg; mat4 projection; mat4 modelView; }
NOTE: Array uniforms are not supported at the moment, but will be supported in future.
The vertex shader above is used by a GLProgram program.
The following code builds a GLUniforms struct:
try { auto uniforms = GLUniforms!Uniforms(program); } catch(OpenGLException e) { writeln("ERROR: uniforms in a program have unexpected types: ", e); return; }
The GLUniforms constructor enforces that types of uniforms in program match types in Uniforms - the uniforms specification struct. Note that if program is missing any uniform, there is no error, only a logged warning, and a dummy uniform is created. This is because some GPU drivers agressively optimize and remove uniforms, and we don't want to trigger an error just because a user is running our program on a GPU we didn't test.
Finally, the following code sets the uniforms through uniforms.
// mat4 projectionMatrix, modelViewMatrix uniforms.projection = projectionMatrix; uniforms.modelView = modelViewMatrix;
A type-safe API for manipulating GLSL uniform variables.
'Uniforms specification' struct Spec specifies types and names of uniforms in a program. GLUniforms!Spec has properties with names matching fields of Spec. Uniforms in a program can be set by setting these properties.