#include
<oglplus/prog_var/location.hpp>
The program variable tag types allow to differentiate between objects wrapping references to GLSL variables (uniforms, uniform blocks, vertex attributes, etc.) at compile time.
namespace tag { struct VertexAttrib; struct Uniform; struct UniformBlock; struct ShaderStorageBlock; struct Subroutine; struct SubroutineUniform; struct FragData;
See VertexAttrib |
|
See Uniform and ProgramUniform |
|
See UniformBlock |
|
See Subroutine |
|
See FragData |
The typechecking tags allow to enable or disable program variable typechecking at compile time.
struct Typecheck; struct NoTypecheck; } // namespace tag
#include
<oglplus/prog_var/location.hpp>
The ProgVarLoc
template
wraps the raw GLuint
program identifier and GLint
location of a GLSL variable (vertex attribute, uniform, fragment shader
output, etc.). Since all types of GLSL variables share the same namespace
(the domain of the GLint
type) it is easy to confuse variables of different types.
In order to avoid such mismatches, the VarTag
template parameter of ProgVarLoc
conveys information about the actual variable type and prevents for example
passing an uniform location to a function requiring a vertex attribute,
etc.
template <typename VarTag> class ProgVarLoc : public ProgVarLocOps<VarTag> { public: ProgVarLoc(void) noexcept; ProgVarLoc(ProgramName program) noexcept; explicit ProgVarLoc(GLint location) noexcept; ProgVarLoc(ProgramName program, GLint location) noexcept; ProgVarLoc(ProgramName program, StrCRef identifier); ProgVarLoc(ProgramName program, StrCRef identifier, bool active_only); ProgVarLoc& BindTo(StrCRef identifier, bool is_active = true); ProgramName Program(void) const noexcept; GLint Location(void) const noexcept; bool IsActive(void) const noexcept; explicit operator bool (void) const noexcept; friend bool operator == (ProgVarLoc a, ProgVarLoc b) noexcept; friend bool operator != (ProgVarLoc a, ProgVarLoc b) noexcept; friend bool operator < (ProgVarLoc a, ProgVarLoc b) noexcept; }; /// Returns the GL location/index of the specified @p variable template <typename VarTag> GLint GetGLLocation(ProgVarLoc<VarTag> variable);
Creates variable without specific location in the specified |
|
Creates variable with specified |
|
Creates variable with the specified |
|
Creates variable with the specified |
|
Creates variable with the specified |
|
Late initialization of the variable location from its identifier. The program name must already be specified. |
|
The |
|
The location of |
|
Returns |
|
Returns |
typedef ProgVarLoc<tag::VertexAttrib> VertexAttribLoc; typedef ProgVarLoc<tag::Uniform> UniformLoc; typedef ProgVarLoc<tag::UniformBlock> UniformBlockLoc; typedef ProgVarLoc<tag::Subroutine> SubroutineLoc; typedef ProgVarLoc<tag::SubroutineUniform> SubroutineUniformLoc; typedef ProgVarLoc<tag::FragData> FragDataLoc; typedef ProgVarLoc<tag::ShaderStorageBlock> ShaderStorageBlockLoc;
#include
<oglplus/prog_var/wrapper.hpp>
Specializations of the ProgVarLocOps
template implement
basic operations working on the locations of various types of GPU program
variables, most notably finding the location of a variable by their identifiers
or in some cases binding the variables to a particular location.
template <typename VarTag> class ProgVarLocOps { public: };
Specializations of ProgVarCommonOps
implement operations
specific to particular types of GPU program variables, but independent
of their data type, type-checking or state access rules.
template <typename VarTag> class ProgVarCommonOps : public ProgVarLoc<VarTag> { public: };
Specializations of ProgVarGetSetOps
implement the
functionality of retrieving or setting of values of GPU program variables
for which such operations do make sense.
template <typename OpsTag, typename VarTag, typename T> class ProgVarGetSetOps : public ProgVarCommonOps<VarTag> { public: };
Specializations of ProgVarTypecheck
implement the
typechecking functionality for those GPU program variables where it makes
sense (for example Uniform
can check if the type used as the template argument matches the type
declared in the GLSL shader).
template <typename ChkTag, typename VarTag> class ProgVarTypecheck { public: void CheckType( ProgramName program, GLint location, StrCRef identifier ) const; };
ProgVar
Depending on the VarTag
and the rest of the template arguments ProgVar
(directly
or indirectly) inherits from ProgVarLoc
and from various specializations of ProgVarCommonOps,
ProgVarGetSetOps
and ProgVarTypecheck.
ProgVar
is directly used as the definition of most
of the GPU program variable wrappers like VertexAttrib,
Uniform, UniformBlock,
Subroutine,
SubroutineUniform,
ShaderStorageBlock
and FragData.
template <typename OpsTag, typename VarTag, typename ChkTag, typename T> class ProgVar : public ProgVarGetSetOps<OpsTag, VarTag, T> , public ProgVarTypecheck<ChkTag, VarTag> { public: ProgVar(void); ProgVar(const ProgVar&); ProgVar(ProgVarLoc<VarTag> pvloc); ProgVar(ProgramName program, GLuint location); ProgVar(ProgramName program, StrCRef identifier); ProgVar(ProgramName program, StrCRef identifier, bool active_only); ProgVar(ProgramName program, StrCRef identifier, std::nothrow_t); ProgVar& operator = (const ProgVar& var); ProgVar& operator = (ProgVarLoc<VarTag> pvloc); ProgVar& BindTo(StrCRef identifier); ProgVar operator[](std::size_t offset) const; }; // TODO
Constructs a |
|
Constructs a |
|
Constructs a |
|
Constructs a |
|
Constructs a |
|
Allows to access elements in array GPU program variables. |
#include
<oglplus/prog_var/typechecked.hpp>
By default the GPU program variable wrappers like Uniform
or ProgramUniform
are are not typechecked. The Typechecked
modifier
template inherits from a particular specialization of ProgVar
but uses tag::Typecheck
as template argument which enables the type-checking.
template <typename ProgVar> class Typechecked : public ProgVar { public: using ProgVar::ProgVar; };
Inherits constructors from ProgVar, but also enables typechecking for those program variable types where it does make sense. |
#include
<oglplus/prog_var/optional.hpp>
The Optional
modifier template inherits from ProgVar and
provides a new set of constructors which do not throw ProgVarError
if the requested GPU program variable cannot be located.
template <typename ProgVar> class Optional : public ProgVar { public: OptionalImpl(ProgramName program, StrCRef identifier); };
Tries to locate the variable identified by |
#include
<oglplus/prog_var/lazy.hpp>
By default the GPU program variable wrappers implemented by ProgVar are eagerly initialized in the constructor. This means that the ProgramName passed as the argument to the constructor must be compiled, linked and current when the location of a variable is queried by its identifier.
However, in some situations it is desirable to postpone the initialization
to a later time. The Lazy
modifier template inherits
from ProgVar
and changes the behavior of its constructors. It just internally stores
the identifier string and postpones the search for the variable in the
GPU program until it is actually required or requested by the user.
template <typename ProgVar> class Lazy : public ProgVar { public: Lazy(ProgramName program, String&& identifier); Lazy& Init(void); Lazy& TryInit(void); ProgVar operator[](std::size_t offset); template <typename T> void Set(T&& value); };
Internally stores the program name and the identifier of the program variable but does not search for the location. |
|
If the location has not been found yet, |
|
Similar to |
|
Wrapper around |
|
Wrapper around |