PrevUpHomeNext

OGLplus program variables

Tags
Location
Wrapper
Typechecking modifier
Optional modifier
Lazy modifier

#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; 1
struct Uniform; 2
struct UniformBlock; 3
struct ShaderStorageBlock; 4
struct Subroutine; 5
struct SubroutineUniform; 6
struct FragData; 7
Type-checking tags

The typechecking tags allow to enable or disable program variable typechecking at compile time.

struct Typecheck; 1
struct NoTypecheck; 2

} // namespace tag

1

Enables GPU program variable typechecking if possible.

2

Disables GPU program variable typechecking.

#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; 1

	explicit
	ProgVarLoc(GLint location)
	noexcept; 2

	ProgVarLoc(ProgramName program, GLint location)
	noexcept; 3

	ProgVarLoc(ProgramName program, StrCRef identifier); 4

	ProgVarLoc(ProgramName program, StrCRef identifier, bool active_only); 5

	ProgVarLoc& BindTo(StrCRef identifier, bool is_active = true); 6

	ProgramName Program(void) const
	noexcept; 7

	GLint Location(void) const
	noexcept; 8

	bool IsActive(void) const
	noexcept; 9

	explicit
	operator bool (void) const
	noexcept; 10

	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);

1

Creates variable without specific location in the specified program. The location can be specified later.

2

Creates variable with specified location without a reference to a specific program. The program can be specified later.

3

Creates variable with the specified location in the specified program.

4

Creates variable with the specified identifier in the specified program.

5

Creates variable with the specified identifier in the specified program. This overload allows to specify whether the constructor should throw if no such variable is active in the program. If active_only is true then the constructor throws.

6

Late initialization of the variable location from its identifier. The program name must already be specified.

7

The program that this variable belongs to.

8

The location of this variable.

9

Returns true if the variable is active, false otherwise.

10

Returns true if the variable is active, false otherwise. Synonym for Active.

Typedefs
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>

Basic program variable location operations

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:
};
Common program variable operations

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.

Get/set program variable operations
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).

Program variable typechecking
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); 1

	ProgVar(ProgramName program, GLuint location); 2

	ProgVar(ProgramName program, StrCRef identifier); 3

	ProgVar(ProgramName program, StrCRef identifier, bool active_only); 4

	ProgVar(ProgramName program, StrCRef identifier, std::nothrow_t); 5

	ProgVar& operator = (const ProgVar& var);
	ProgVar& operator = (ProgVarLoc<VarTag> pvloc);

	ProgVar& BindTo(StrCRef identifier);

	ProgVar operator[](std::size_t offset) const; 6
};
// TODO

1

Constructs a ProgVar from the specified location.

2

Constructs a ProgVar from a reference to a program and a location.

3

Constructs a ProgVar from a reference to a program and an identifier of the variable. If no such variable is active, then this constructor throws ProgVarError.

4

Constructs a ProgVar from a reference to a program and an identifier of the variable. If no such variable is active and active_only is true then this constructor throws ProgVarError.

5

Constructs a ProgVar from a reference to a program and an identifier of the variable. Does not throw if no such variable is active.

6

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; 1
};

1

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); 1
};

1

Tries to locate the variable identified by identifier in the specified program, but does not throw if the variable is not active. The actual status can be determined by calling ProgVarLoc::IsActive().

#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); 1

	Lazy& Init(void); 2

	Lazy& TryInit(void); 3

	ProgVar operator[](std::size_t offset); 4

	template <typename T>
	void Set(T&& value); 5
};

1

Internally stores the program name and the identifier of the program variable but does not search for the location.

2

If the location has not been found yet, Init tries to find it in the referenced GPU program by the stored identifier. If no such variable exists in the program or if it is not active then this function throws ProgVarError.

3

Similar to Init tries to find the location of a variable in a GPU program, but does not throw if the variable is not active. The location just remains uninitialized. The state can be queried by using the ProgVarLoc::IsActive member function.

4

Wrapper around ProgVar::operator []. Allows to access the elements of an array GPU program variable. Calls Init before actually trying to access the program variable.

5

Wrapper around ProgVar::Set. Calls Init before actually trying to access the program variable.


PrevUpHomeNext