OGLplus defines many enumeration types grouping together GL constants that
logically belong together. The strong typing on the enumerations also prevents
in many cases errors like passing invalid constant to a GL function since
the OGLplus function wrappers use appropriate enumeration types for parameters
instead of the generic GLenum
type.
![]() |
Note |
---|---|
Many of the GL constant values used in the enumerations are only available in specific GL versions or with certain GL extensions. If the underlying GL constant is not defined when the enumeration definition is processed then the corresponding value is not present in the enumeration. |
For (almost) all enumeration types the following functions are overloaded.
template <typename Enumeration> Range<Enumeration> EnumValueRange(void);template <typename Enumeration> StrCRef EnumValueName(Enumeration enum_value);
![]()
Returns a Range
of values in a OGLplus enum value. This template function is overloaded
for the enumerated types defined by OGLplus and returns a Range
which allows to traverse all values of a particular |
|
Returns the name of the GL enumerated value for an OGLplus enum value.
This function is overloaded for the enumerated types defined by OGLplus
and returns the GL constant name (without the "GL_" prefix)
as managed const string reference. The result of this function is influenced
by the |
For example:
Context gl; Bitfield<ContextProfileBit> cpm = gl.ProfileMask();for(auto r=EnumValueRange<ContextProfileBit>(); !r.Empty(); r.Next())
{ auto bit = r.Front();
std::cout << EnumValueName(bit).c_str() << ": ";
std::cout << (cpm.Has(bit)?"true":"false") << std::endl;
}
Query the profile mask for the current GL context. |
|
Get a range enumerating all individual bits in the ContextProfileBit enumeration. |
|
For each individual bit in the enumeration. |
|
Prints the bit's name. |
|
Print whether the bit is set in the mask. |
The EnumArray
template class is used by several functions
as the parameter type and allows to pass an array of multiple enumerated
values to be passed as an argument.
![]() |
Note |
---|---|
The lifetime of an instance of |
template <typename Enum> class EnumArray { public: template <std::size_t N> EnumArray(const Enum (&enums)[N]); EnumArray(const std::vector<Enum>& enums); EnumArray(size_t count, const Enum* enums); };
The OneOf
template class is used to merge several enumeration
types into a single type. Instances of OneOf
can be
implicitly constructed from a value from any of the merged enumeration
types. OneOf
is mostly used as the parameter type in
functions that can accept values from multiple different enumerations.
![]() |
Note |
---|---|
The following definition is just a pseudo-code used for documentation
purposes and differs from the actual implementation of |
template <typename ... Enum> class OneOf { public: OneOf(Enum)...;};
(Pseudocode) - |
For example:
typedef OneOf< FramebufferAttachment, FramebufferColorAttachment > Attachment; Attachment a1 = FramebufferAttachment::Depth; Attachment a2 = FramebufferColorAttachment::_0;
Specializations of the EnumToClass
template for various
enumerations can be used to create classes which have member variables
with the same names as are the names of the values in the enumeration.
The type of the member variables is defined by the Transform
template which takes values of the specified Enumeration
as an argument.
namespace enums { template < typename Base, typename Enumeration, template <Enumeration> class Transform > class EnumToClass { public: EnumToClass(void); EnumToClass(const EnumToClass&); /* ... */ }; } // namespace enums
For example for a SomeEnum
enumeration:
enum class SomeEnum { ValueA, ValueB, ValueC, ValueD };
with the following transformation template:
template <SomeEnum Value> class SomeEnumTransform { public: SomeEnumTransform(void);SomeEnumTransform(Base&); };
the following instantiation of EnumToClass
typedef EnumToClass<Base, SomeEnum, SomeEnumTransform> EnumToClassSomeEnumTransform;
results in a class which is equivalent to:
class EnumToClassSomeEnumTransform : public Base { public: SomeEnumTransform<SomeEnum::ValueA> ValueA; SomeEnumTransform<SomeEnum::ValueB> ValueB; SomeEnumTransform<SomeEnum::ValueC> ValueC; SomeEnumTransform<SomeEnum::ValueD> ValueD; };