#include
<oglplus/uniform.hpp>
template <> class ProgVarLocOps<tag::Uniform> { public: static GLint GetLocation( ProgramName program, StrCRef identifier, bool active_only );};
Finds the location of the uniform variable specified by |
template <typename OpsTag, typename T> class ProgVarGetSetOps<OpsTag, tag::Uniform, T> : public ProgVarCommonOps<tag::Uniform> { public: void Set(T value); void SetValue(T value);void SetValues(std::size_t n, const T* values);
void TrySet(T value);
}; template <typename OpsTag> class ProgVarGetSetOps<OpsTag, tag::Uniform, void> : public ProgVarCommonOps<tag::Uniform> { public: template <typename T> void Set(T value); template <typename T> void SetValue(T value);
template <typename T> void SetValues(std::size_t n, const T* values);
};
Sets uniform value. |
|
Sets multiple consecutive values. |
|
Sets the uniform value if it is active. See |
|
Sets uniform value. |
|
Sets multiple consecutive values. |
template <typename T> using Uniform = ProgVar< tag::ImplicitSel, tag::Uniform, tag::NoTypecheck, T >;typedef Uniform<GLint> UniformSampler;
|
typedef ProgVar< tag::ImplicitSel, tag::Uniform, tag::NoTypecheck, void > UntypedUniform;UntypedUniform operator / (ProgramName program, StrCRef identifier);
|
Context gl; VertexShader vs; vs.Source( "#version 150\n" "in vec3 Position;\n" "void main(void)\n" "{\n" " gl_Position = Position;\n" "}\n" ).Compile(); FragmentShader fs; fs.Source( "#version 130\n" "uniform vec4 Color;\n" "void main(void)\n" "{\n" " gl_FragColor = Color;\n" "}\n" ).Compile(); Program prog; prog.AttachShader(vs).AttachShader(fs).Link(); gl.Use(prog); UniformLoc color_loc1(prog, "Color");assert(color_loc1.IsActive());
assert(color_loc1); UniformLoc color_loc2(prog, "Color", false
);
assert(color_loc1 == color_loc2);
assert(color_loc1.Location() == GetGLLocation(color_loc1));
UniformLoc color_loc3(0);
Uniform<Vec4f> color1(prog, "Color");
Uniform<Vec4f> color2(color_loc2);
Uniform<Vec4f> color3(prog);
color3.BindTo("Color");
color1.Set(Vec4f(1, 0, 0, 1));
Typechecked<Uniform<Vec2f>> color4(prog, "Color");
![]()
Getting the location of a uniform in a GPU program, by its name. Throws if no such uniform is active in the current program. To get the location of a program which is not currently active, ProgramUniform must be used. |
|
Check if the uniform is active. |
|
Don't throw if inactive. |
|
Getting the location of a uniform in a GPU program, by its name. Does not throw if the uniform is not active. |
|
Compare two uniform locations for equality (in both the program name and the location index). |
|
Two ways to get the location index. |
|
Explicitly initializing a uniform location. |
|
Initialize a typed reference to a uniform variable, from a program name and identifier. |
|
Initialize a typed reference to a uniform variable, from a uniform location. |
|
Initialize a uniform from a program name, the location is not obtained in this case and must be bound later. |
|
Late binding of a uniform to an identifier. |
|
Setting the value of a GPU program uniform variable. This will throw if the uniform is not active. |
|
The |
UntypedUniform color5(prog, "Color");color5.Set(Vec4f(0,0,1,1)); (prog/"Color").Set(Vec4f(0,0,1,1));
Optional<Uniform<Vec4f>> color6(prog, "Blah");
color6.TrySet(Vec4f(0,1,0,1));
Lazy<Uniform<Vec4f>> color7(prog, "Color");
try { color7.Init();
} catch(...) { /* ... */ } color7.TryInit();
color7.Set(Vec4f(0,0,0,1));
![]()
Untyped uniforms do not carry the type information on the C++ side and cannot be typechecked during construction. |
|
Syntax sugar operator for constructing untyped uniforms, equivalent
to |
|
The |
|
If the referenced uniform is active, then this sets its value, but
unlike |
|
The |
|
The uniform location can be explicitly queried by calling the |
|
The |
|
If the location is still not initialized yet, then it is queried before setting the uniform value. |