template<UnsignedInt location, class T>
Magnum::GL::Attribute class

Base class for specifying shader attributes.

Meant to be used mainly through a typedef in AbstractShaderProgram subclasses. Shader consumers are then supposed to use the typedef, or in case of builtin attributes the definitions from Shaders::GenericGL and other classes from the Shaders namespace.

The location template parameter is a vertex attribute location, a number between 0 and AbstractShaderProgram::maxVertexAttributes(). To ensure compatibility, you should always have a vertex attribute with location 0.

The T template parameter is the type that matches the shader attribute declaration, e.g. Vector4i for ivec4. DataType is the type of passed data when adding vertex buffers to mesh. By default it is the same as type used in shader (e.g. DataType::Int for Vector4i). It's also possible to pass integer data to floating-point shader inputs. In this case you may want to normalize the values (e.g. color components from 0255 to 0.0f1.0f) — see DataOption::Normalized.

See AbstractShaderProgram subclassing workflow for example usage in shaders and Mesh configuration for example usage when adding vertex buffers to a mesh. DynamicAttribute is a variant with runtime-specified location and type, and is convertible from VertexFormat.

Public types

enum (anonymous): UnsignedInt { Location = location, Vectors = Implementation::Attribute<T>::Vectors new in 2020.06, VectorCount = Vectors deprecated in 2020.06 }
enum class Components: GLint { One = 1, Two = 2, Three = 3, Four = 4, BGRA = GL_BGRA }
Component count.
enum class DataType: GLenum { UnsignedByte = GL_UNSIGNED_BYTE, Byte = GL_BYTE, UnsignedShort = GL_UNSIGNED_SHORT, Short = GL_SHORT, UnsignedInt = GL_UNSIGNED_INT, Int = GL_INT, Half = GL_HALF_FLOAT new in 2020.06, HalfFloat deprecated in 2020.06, Float = GL_FLOAT, Double = GL_DOUBLE, UnsignedInt10f11f11fRev = GL_UNSIGNED_INT_10F_11F_11F_REV, UnsignedInt2101010Rev = GL_UNSIGNED_INT_2_10_10_10_REV, Int2101010Rev = GL_INT_2_10_10_10_REV }
Data type.
enum class DataOption: UnsignedByte { Normalized = 1 << 0 }
Data option.
using Type = T
Type.
using ScalarType = Implementation::Attribute<T>::ScalarType
Scalar type.
using DataOptions = Containers::EnumSet<DataOption>
Data options.

Constructors, destructors, conversion operators

Attribute(DataOptions dataOptions = DataOptions()) constexpr
Constructor.
Attribute(DataType dataType, DataOptions dataOptions = DataOptions())
Constructor.
Attribute(Components components, DataType dataType = Implementation::Attribute<T>::DefaultDataType, DataOptions dataOptions = DataOptions())
Constructor.
Attribute(UnsignedInt vectorStride, DataType dataType = Implementation::Attribute<T>::DefaultDataType, DataOptions dataOptions = DataOptions()) constexpr new in 2020.06
Construct with a custom vector stride.
Attribute(Components components, UnsignedInt vectorStride, DataType dataType = Implementation::Attribute<T>::DefaultDataType, DataOptions dataOptions = DataOptions()) constexpr new in 2020.06
Construct with a custom vector stride.

Public functions

auto components() const -> Components constexpr
Component count of passed data.
auto dataType() const -> DataType constexpr
Type of passed data.
auto vectorStride() const -> UnsignedInt constexpr new in 2020.06
Stride between consecutive vector elements.
auto vectorSize() const -> UnsignedInt deprecated in 2020.06 constexpr
Size of each vector in passed data.
auto dataOptions() const -> DataOptions constexpr
Data options.

Enum documentation

template<UnsignedInt location, class T>
enum Magnum::GL::Attribute<location, T>::(anonymous): UnsignedInt

Enumerators
Location

Location to which the attribute is bound.

Vectors new in 2020.06

Count of vectors in this type.

Is 1 for non-matrix attributes.

VectorCount

Count of vectors in this type,

template<UnsignedInt location, class T>
enum class Magnum::GL::Attribute<location, T>::Components: GLint

Component count.

Count of components passed to the shader. If passing smaller count of components than corresponding type has, unspecified components are set to default values (second and third to 0, fourth to 1).

Enumerators
One

Only first component is specified. Second, third and fourth component are set to 0, 0, 1, respectively. Only for scalar and vector types, not matrices.

Two

First two components are specified. Third and fourth component are set to 0, 1, respectively. Only for two, three and four-component vector types and 2x2, 3x2 and 4x2 matrix types.

Three

First three components are specified. Fourth component is set to 1. Only for three and four-component vector types, 2x3, 3x3 and 4x3 matrix types.

Four

All four components are specified. Only for four-component vector types and 2x4, 3x4 and 4x4 matrix types.

BGRA

Four components with BGRA ordering. Only for four-component float vector type. Must be used along with DataType::UnsignedByte and DataOption::Normalized.

template<UnsignedInt location, class T>
enum class Magnum::GL::Attribute<location, T>::DataType: GLenum

Data type.

Type of data passed to shader.

Enumerators
UnsignedByte

Unsigned byte

Byte

Byte

UnsignedShort

Unsigned short

Short

Short

UnsignedInt

Unsigned int

Int

Int

Half new in 2020.06

Half float. Only for float attribute types.

HalfFloat

Half float.

Float

Float. Only for float attribute types.

Double

Double. Only for float and double attribute types.

UnsignedInt10f11f11fRev

Unsigned 10.11.11 packed float. Only for three-component float vector attribute type.

UnsignedInt2101010Rev

Unsigned 2.10.10.10 packed integer. Only for four-component float vector attribute type.

Int2101010Rev

Signed 2.10.10.10 packed integer. Only for four-component float vector attribute type.

template<UnsignedInt location, class T>
enum class Magnum::GL::Attribute<location, T>::DataOption: UnsignedByte

Data option.

Enumerators
Normalized

Normalize integer components. Only for float attribute types. Default is to not normalize.

Typedef documentation

template<UnsignedInt location, class T>
typedef T Magnum::GL::Attribute<location, T>::Type

Type.

Type used in shader code.

template<UnsignedInt location, class T>
typedef Implementation::Attribute<T>::ScalarType Magnum::GL::Attribute<location, T>::ScalarType

Scalar type.

The underlying scalar type of the attribute.

template<UnsignedInt location, class T>
typedef Containers::EnumSet<DataOption> Magnum::GL::Attribute<location, T>::DataOptions

Data options.

Function documentation

template<UnsignedInt location, class T>
Magnum::GL::Attribute<location, T>::Attribute(DataOptions dataOptions = DataOptions()) constexpr

Constructor.

Parameters
dataOptions Data options. Default is no options.

Data type is the same as type used in shader (e.g. DataType::Int for Vector4i). Component count is set to the same value as in type used in shader (e.g. Components::Three for Vector3).

template<UnsignedInt location, class T>
Magnum::GL::Attribute<location, T>::Attribute(DataType dataType, DataOptions dataOptions = DataOptions())

Constructor.

Parameters
dataType Type of passed data
dataOptions Data options. Default is no options.

Component count is set to the same value as in type used in shader (e.g. Components::Three for Vector3).

template<UnsignedInt location, class T>
Magnum::GL::Attribute<location, T>::Attribute(Components components, DataType dataType = Implementation::Attribute<T>::DefaultDataType, DataOptions dataOptions = DataOptions())

Constructor.

Parameters
components Component count
dataType Type of passed data. Default is the same as type used in shader (e.g. DataType::Int for Vector4i).
dataOptions Data options. Default is no options.

Vector stride is set to the size of the vector type (e.g. 12 for a Matrix3).

template<UnsignedInt location, class T>
Magnum::GL::Attribute<location, T>::Attribute(UnsignedInt vectorStride, DataType dataType = Implementation::Attribute<T>::DefaultDataType, DataOptions dataOptions = DataOptions()) constexpr new in 2020.06

Construct with a custom vector stride.

Parameters
vectorStride Stride between consecutive matrix column vectors
dataType Type of passed data. Default is the same as type used in shader (e.g. DataType::Int for Vector4i).
dataOptions Data options. Default is no options.

Component count is set to the same value as in type used in shader (e.g. Components::Three for Vector3).

template<UnsignedInt location, class T>
Magnum::GL::Attribute<location, T>::Attribute(Components components, UnsignedInt vectorStride, DataType dataType = Implementation::Attribute<T>::DefaultDataType, DataOptions dataOptions = DataOptions()) constexpr new in 2020.06

Construct with a custom vector stride.

Parameters
components Component count
vectorStride Stride between consecutive matrix column vectors
dataType Type of passed data. Default is the same as type used in shader (e.g. DataType::Int for Vector4i).
dataOptions Data options. Default is no options.

template<UnsignedInt location, class T>
UnsignedInt Magnum::GL::Attribute<location, T>::vectorStride() const constexpr new in 2020.06

Stride between consecutive vector elements.

Used for describing matrix attributes. Implicitly the same as size of given vector type (e.g. 9 for a Matrix3), but can be overridden for example to ensure four-byte column alignment with 1- and 2-byte data types.

template<UnsignedInt location, class T>
UnsignedInt Magnum::GL::Attribute<location, T>::vectorSize() const constexpr

Size of each vector in passed data.

template<UnsignedInt location, class T> template<UnsignedInt location, class T>
Debug& operator<<(Debug& debug, Attribute<location, T>::Components)

Debug output operator.

template<UnsignedInt location, class T> template<UnsignedInt location, class T>
Debug& operator<<(Debug& debug, Attribute<location, T>::DataType)

Debug output operator.