record TGLVertexAttrib

DescriptionHierarchyFieldsMethodsProperties

Unit

Declaration

type TGLVertexAttrib = record

Description

Represents a single vertex attribute in a TGLProgram. These are variables marked with attribute in a vertex shader.

Overview

Methods

procedure Init(const AProgram: TGLProgram; const AAttrName: RawByteString); inline;
procedure Bind(const AProgram: TGLProgram; const ALocation: Cardinal; const AAttrName: RawByteString); inline;
procedure SetConfig(const ADataType: TGLDataType; const ANumValuesPerVertex: Integer; const AStride: NativeInt = 0; const AOffset: NativeInt = 0); overload; inline;
procedure SetConfig<T: record>(const AStride: NativeInt = 0; const AOffset: NativeInt = 0); overload; inline;
procedure SetData(const ADataType: TGLDataType; const ANumValuesPerVertex: Integer; const AData: Pointer; const AStride: NativeInt = 0; const ANormalized: Boolean = False); overload; inline;
procedure SetData<T: record>(const AData: array of T; const AStride: NativeInt = 0; const ANormalized: Boolean = False); overload;
procedure SetData<T: record>(const AData: TArray<T>; const AStride: NativeInt = 0; const ANormalized: Boolean = False); overload; inline;
procedure Enable; inline;
procedure Disable; inline;
function GetBuffer: TGLBuffer; inline;
function IsEnabled: Boolean; inline;
function GetSize: Integer; inline;
function GetStride: Integer; inline;
function GetDataType: TGLDataType; inline;
function IsNormalized: Boolean; inline;
procedure SetValue(const AValue: Single); overload; inline;
procedure SetValue(const AValue0, AValue1: Single); overload; inline;
procedure SetValue(const AValue0, AValue1, AValue2: Single); overload; inline;
procedure SetValue(const AValue0, AValue1, AValue2, AValue3: Single); overload; inline;
procedure SetValue(const AValue: TVector2); overload; inline;
procedure SetValue(const AValue: TVector3); overload; inline;
procedure SetValue(const AValue: TVector4); overload; inline;
procedure SetValue(const AValue: TMatrix2); overload; inline;
procedure SetValue(const AValue: TMatrix3); overload; inline;
procedure SetValue(const AValue: TMatrix4); overload; inline;
function GetValue: TVector4;
function GetOffset: Integer; inline;
function GetData: Pointer; inline;

Properties

property Location: GLint read FLocation;

Description

Methods

procedure Init(const AProgram: TGLProgram; const AAttrName: RawByteString); inline;

Initializes the vertex attribute.

Queries the previously linked program object specified by AProgram for the attribute variable specified by AAttrName and initializes the attribute with the index of the generic vertex attribute that is bound to that attribute variable. If AName is a matrix attribute variable, the index of the first column of the matrix is used.

The association between an attribute variable name and a generic attribute index can be specified at any time by calling Bind. Attribute bindings do not go into effect until TGLProgram.Link is called. After a program object has been linked successfully, the index values for attribute variables remain fixed until the next link command occurs. The attribute values can only be queried after a link if the link was successful.

This method uses the binding that actually went into effect the last time TGLProgram.Link was called for the specified program object. Attribute bindings that have been specified since the last link operation are not used.

Note: in DEBUG mode, a warning will be logged to the debug console of AProgram does not contain an attribute named AAttrName, of AAttrName starts with the reserved prefix "gl_".

OpenGL API: glGetAttribLocation

Parameters
AProgram
the program containing the attribute.
AAttrName
the (case-sensitive) name of the attribute as used in the vertex shader of the program.
Exceptions raised
TGLError.InvalidOperation
if AProgram is not a valid program or has not been successfully linked.
See also
SetConfig
SetData
Enable
Enables this vertex attribute.
Disable
Disables this vertex attribute.
Bind
Initializes the vertex attribute by binding a user-defined attribute name to an attribute location.
procedure Bind(const AProgram: TGLProgram; const ALocation: Cardinal; const AAttrName: RawByteString); inline;

Initializes the vertex attribute by binding a user-defined attribute name to an attribute location.

This method is used to associate a user-defined attribute variable in the program object specified by AProgram with a generic vertex attribute index. The name of the user-defined attribute variable is passed in AAttrName. The generic vertex attribute index to be bound to this variable is specified by ALocation. When AProgram is made part of current state, values provided via the generic vertex attribute index will modify the value of the user-defined attribute variable specified by AAttrName.

If AAttrName refers to a matrix attribute variable, ALocation refers to the first column of the matrix. Other matrix columns are then automatically bound to locations ALocation+1 for a matrix of type TMatrix2; ALocation+1 and ALocation+2 for a matrix of type TMatrix3; and ALocation+1, ALocation+2, and ALocation+3 for a matrix of type TMatrix4.

This method makes it possible for vertex shaders to use descriptive names for attribute variables rather than generic numbered variables. The values sent to each generic attribute index are part of current state, just like standard vertex attributes such as color, normal, and vertex position. If a different program object is made current by calling TGLProgram.Use, the generic vertex attributes are tracked in such a way that the same values will be observed by attributes in the new program object that are also bound to ALocation.

Attribute variable name-to-generic attribute index bindings for a program object can be explicitly assigned at any time by calling Bind. Attribute bindings do not go into effect until TGLProgram.Link is called. After a program object has been linked successfully, the index values for generic attributes remain fixed (and their values can be queried) until the next link command occurs.

Applications are not allowed to bind any of the standard OpenGL vertex attributes using this command, as they are bound automatically when needed. Any attribute binding that occurs after the program object has been linked will not take effect until the next time the program object is linked.

Note: Bind can be called before any vertex shader objects are bound to the specified program object. It is also permissible to bind a generic attribute index to an attribute variable name that is never used in a vertex shader.

Note: if AAttrName was bound previously, that information is lost. Thus you cannot bind one user-defined attribute variable to multiple indices, but you can bind multiple user-defined attribute variables to the same index.

Note: applications are allowed to bind more than one user-defined attribute variable to the same generic vertex attribute index. This is called aliasing, and it is allowed only if just one of the aliased attributes is active in the executable program, or if no path through the shader consumes more than one attribute of a set of attributes aliased to the same location. The compiler and linker are allowed to assume that no aliasing is done and are free to employ optimizations that work only in the absence of aliasing. OpenGL implementations are not required to do error checking to detect aliasing. Because there is no way to bind standard attributes, it is not possible to alias generic attributes with conventional ones (except for generic attribute 0).

Note: active attributes that are not explicitly bound will be bound by the linker when TGLProgram.Link is called. The locations assigned can be queried by calling Init.

OpenGL API: glBindAttribLocation

Parameters
AProgram
the program containing the attribute.
ALocation
the location of the attribute to be bound
AAttrName
the (case-sensitive) name of the vertex shader attribute to which ALocation is to be bound.
Exceptions raised
TGLError.InvalidOperation
if AProgram is not a valid program.
TGLError.InvalidOperation
if AAttrName starts with the reserved prefix "gl_".
TGLError.InvalidValue
is ALocation is greater than or equal to the maximum number of supported vertex attributes.
See also
TGLShader.GetMaxVertexAttribs
Get the maximum number of 4-component generic vertex attributes accessible to a vertex shader.
GetSize
Get the size of the vertex attribute.
GetDataType
Get the data type of the vertex attribute.
Enable
Enables this vertex attribute.
Disable
Disables this vertex attribute.
TGLProgram.Use
Installs the program object as part of current rendering state.
SetValue
Init
Initializes the vertex attribute.
procedure SetConfig(const ADataType: TGLDataType; const ANumValuesPerVertex: Integer; const AStride: NativeInt = 0; const AOffset: NativeInt = 0); overload; inline;
procedure SetConfig<T: record>(const AStride: NativeInt = 0; const AOffset: NativeInt = 0); overload; inline;

Sets up the attribute for use with a TGLBuffer (of type TGLBufferType.Vertex). That is, this attribute will be part of a VBO (Vertex Buffer Object). When this attribute is not part of a VBO, then you should use SetData instead.

There is an overloaded version that has a type parameter T instead of the ADataType and ANumValuesPerVertex parameters. In that case T must be of an integral or floating-point type, or of type TVector2, TVector3 or TVector4.

Note: in DEBUG mode with assertions enabled, an error will be logged to the debug console if no TGLBuffer of type TGLBufferType.Vertex is bound.

OpenGL API: glVertexAttribPointer

Parameters
ADataType
the data type of the each component of the vertex attribute. For example, an attribute of type vec3 contains components of type TGLDataType.Float.
ANumValuesPerVertex
the number of values (components) of the vertex attribute. For example, an attribute of type vec3 contains 3 values. Valid values are 1, 2, 3 and 4.
AStride
(optional) byte offset between consecutive vertex attributes. If stride is 0 (the default), the generic vertex attributes are understood to be tightly packed in the array.
AOffset
(optional) byte offset into the buffer object's data store. Defaults to 0.
Exceptions raised
TGLError.InvalidValue
if ANumValuesPerVertex is not 1, 2, 3 or 4.
TGLError.InvalidValue
if AStride is negative.
See also
Enable
Enables this vertex attribute.
Disable
Disables this vertex attribute.
IsEnabled
Get whether the vertex attribute is enabled or not.
GetDataType
Get the data type of the vertex attribute.
GetSize
Get the size of the vertex attribute.
IsNormalized
Get whether data for the vertex attribute is normalized when converted to floating-point.
GetStride
Get the array stride for (number of bytes between successive elements in) the vertex attribute.
TGLBuffer.Bind
Binds the buffer.
gl.DrawArrays
gl.DrawElements
Render primitives from array data, using indices from a bound index buffer.
SetData
procedure SetData(const ADataType: TGLDataType; const ANumValuesPerVertex: Integer; const AData: Pointer; const AStride: NativeInt = 0; const ANormalized: Boolean = False); overload; inline;
procedure SetData<T: record>(const AData: array of T; const AStride: NativeInt = 0; const ANormalized: Boolean = False); overload;
procedure SetData<T: record>(const AData: TArray<T>; const AStride: NativeInt = 0; const ANormalized: Boolean = False); overload; inline;

Sets up the attribute for use with client data. When this attribute is part of a VBO, then you should use SetConfig instead (which is more efficient than using client data).

There are overloaded versions of this method where AData is an array of values of generic type T. In that case, there are no ADataType and ANumValuesPerVertex parameters, since those are implied from T. Also, T must be of an integral or floating-point type, or of type TVector2, TVector3 or TVector 4. These overloads are less efficient though.

OpenGL API: glVertexAttribPointer

Parameters
ADataType
the data type of the each component of the vertex attribute. For example, an attribute of type vec3 contains components of type TGLDataType.Float.
ANumValuesPerVertex
the number of values (components) of the vertex attribute. For example, an attribute of type vec3 contains 3 values. Valid values are 1, 2, 3 and 4.
AData
pointer to the client data containing the vertices.
AStride
(optional) byte offset between consecutive vertex attributes. If stride is 0 (the default), the generic vertex attributes are understood to be tightly packed in the array.
ANormalized
(optional) flag that specifies whether integer values will be normalized. If set to True, integer values are be mapped to the range [-1,1] (for signed values) or [0,1] (for unsigned values) when they are accessed and converted to floating point. Otherwise (default), values will be converted to floats directly without normalization.
Exceptions raised
TGLError.InvalidValue
if ANumValuesPerVertex is not 1, 2, 3 or 4.
TGLError.InvalidValue
if AStride is negative.
See also
Enable
Enables this vertex attribute.
Disable
Disables this vertex attribute.
IsEnabled
Get whether the vertex attribute is enabled or not.
GetDataType
Get the data type of the vertex attribute.
GetSize
Get the size of the vertex attribute.
IsNormalized
Get whether data for the vertex attribute is normalized when converted to floating-point.
GetStride
Get the array stride for (number of bytes between successive elements in) the vertex attribute.
gl.DrawArrays
gl.DrawElements
Render primitives from array data, using indices from a bound index buffer.
SetConfig
procedure Enable; inline;

Enables this vertex attribute.

If enabled, the values in the generic vertex attribute array will be accessed and used for rendering when calls are made to vertex array commands such as gl.DrawArrays or gl.DrawElements.

OpenGL API: glEnableVertexAttribArray

See also
Disable
Disables this vertex attribute.
IsEnabled
Get whether the vertex attribute is enabled or not.
SetConfig
SetData
gl.DrawArrays
gl.DrawElements
Render primitives from array data, using indices from a bound index buffer.
procedure Disable; inline;

Disables this vertex attribute.

OpenGL API: glDisableVertexAttribArray

See also
Enable
Enables this vertex attribute.
IsEnabled
Get whether the vertex attribute is enabled or not.
SetConfig
SetData
gl.DrawArrays
gl.DrawElements
Render primitives from array data, using indices from a bound index buffer.
function GetBuffer: TGLBuffer; inline;

Get the buffer object currently bound to the binding point corresponding to the generic vertex attribute. If no buffer object is bound, the Handle of the returned value is 0.

OpenGL API: glGetVertexAttribiv(GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING)

See also
Bind
Initializes the vertex attribute by binding a user-defined attribute name to an attribute location.
SetConfig
function IsEnabled: Boolean; inline;

Get whether the vertex attribute is enabled or not.

OpenGL API: glGetVertexAttribiv(GL_VERTEX_ATTRIB_ARRAY_ENABLED)

Returns

True if the vertex attribute is enabled. False otherwise.

See also
Enable
Enables this vertex attribute.
Disable
Disables this vertex attribute.
function GetSize: Integer; inline;

Get the size of the vertex attribute. The size is the number of values for each element of the vertex attribute array, and it will be 1, 2, 3, or 4. The initial value is 4.

OpenGL API: glGetVertexAttribiv(GL_VERTEX_ATTRIB_ARRAY_SIZE)

See also
SetConfig
SetData
GetStride
Get the array stride for (number of bytes between successive elements in) the vertex attribute.
GetDataType
Get the data type of the vertex attribute.
IsNormalized
Get whether data for the vertex attribute is normalized when converted to floating-point.
function GetStride: Integer; inline;

Get the array stride for (number of bytes between successive elements in) the vertex attribute. A value of 0 indicates that the array elements are stored sequentially in memory. The initial value is 0.

OpenGL API: glGetVertexAttribiv(GL_VERTEX_ATTRIB_ARRAY_STRIDE)

See also
SetConfig
SetData
GetSize
Get the size of the vertex attribute.
GetDataType
Get the data type of the vertex attribute.
IsNormalized
Get whether data for the vertex attribute is normalized when converted to floating-point.
function GetDataType: TGLDataType; inline;

Get the data type of the vertex attribute.

OpenGL API: glGetVertexAttribiv(GL_VERTEX_ATTRIB_ARRAY_TYPE)

See also
SetConfig
SetData
GetSize
Get the size of the vertex attribute.
GetStride
Get the array stride for (number of bytes between successive elements in) the vertex attribute.
IsNormalized
Get whether data for the vertex attribute is normalized when converted to floating-point.
function IsNormalized: Boolean; inline;

Get whether data for the vertex attribute is normalized when converted to floating-point.

OpenGL API: glGetVertexAttribiv(GL_VERTEX_ATTRIB_ARRAY_NORMALIZED)

Returns

True if vertex data will be normalized. False otherwise.

See also
SetConfig
SetData
GetSize
Get the size of the vertex attribute.
GetStride
Get the array stride for (number of bytes between successive elements in) the vertex attribute.
GetDataType
Get the data type of the vertex attribute.
procedure SetValue(const AValue: Single); overload; inline;
procedure SetValue(const AValue0, AValue1: Single); overload; inline;
procedure SetValue(const AValue0, AValue1, AValue2: Single); overload; inline;
procedure SetValue(const AValue0, AValue1, AValue2, AValue3: Single); overload; inline;
procedure SetValue(const AValue: TVector2); overload; inline;
procedure SetValue(const AValue: TVector3); overload; inline;
procedure SetValue(const AValue: TVector4); overload; inline;
procedure SetValue(const AValue: TMatrix2); overload; inline;
procedure SetValue(const AValue: TMatrix3); overload; inline;
procedure SetValue(const AValue: TMatrix4); overload; inline;

Specify the value of a generic vertex attribute

There are many overloaded versions for the different data types of the vertex attribute.

When the vertex attribute is a vector, you can set its value by either passing 2, 3 or 4 values, or by passing a single value of type TVector2, TVector3 or TVector4.

Generic attributes are defined as four-component values that are organized into an array. The first entry of this array is numbered 0, and the size of the array is implementation-dependent and can be queried with TGLShader.GetMaxVertexAttribs.

When less than 4 Single-type values are passed, the remaining components will be set to 0, except for the 4th component, which will be set to 1.

A user-defined attribute variable declared in a vertex shader can be bound to a generic attribute index by calling Bind. This allows an application to use descriptive variable names in a vertex shader. A subsequent change to the specified generic vertex attribute will be immediately reflected as a change to the corresponding attribute variable in the vertex shader.

The binding between a generic vertex attribute index and a user-defined attribute variable in a vertex shader is part of the state of a program object, but the current value of the generic vertex attribute is not. The value of each generic vertex attribute is part of current state and it is maintained even if a different program object is used.

An application may freely modify generic vertex attributes that are not bound to a named vertex shader attribute variable. These values are simply maintained as part of current state and will not be accessed by the vertex shader. If a generic vertex attribute bound to an attribute variable in a vertex shader is not updated while the vertex shader is executing, the vertex shader will repeatedly use the current value for the generic vertex attribute.

Note: it is possible for an application to bind more than one attribute name to the same generic vertex attribute index. This is referred to as aliasing, and it is allowed only if just one of the aliased attribute variables is active in the vertex shader, or if no path through the vertex shader consumes more than one of the attributes aliased to the same location. OpenGL implementations are not required to do error checking to detect aliasing, they are allowed to assume that aliasing will not occur, and they are allowed to employ optimizations that work only in the absence of aliasing.

OpenGL API: glVertexAttrib*

See also
Bind
Initializes the vertex attribute by binding a user-defined attribute name to an attribute location.
SetConfig
SetData
function GetValue: TVector4;

Get the current value for the generic vertex attribute.

OpenGL API: glGetVertexAttribfv(GL_CURRENT_VERTEX_ATTRIB)

function GetOffset: Integer; inline;

When the vertex attribute is used with a TGLBuffer (that is, when SetConfig is used), then this method returns the byte offset into the buffer objects's data store for this vertex attribute. This equals the AOffset parameter passed to SetConfig.

When the vertex attribute is used with client data (that is, when SetData is used), then the returned value is undefined.

OpenGL API: glGetVertexAttribPointerv

See also
SetConfig
SetData
GetData
When the vertex attribute is used with client data (that is, when SetData is used), then this method returns a pointer to the client data.
function GetData: Pointer; inline;

When the vertex attribute is used with client data (that is, when SetData is used), then this method returns a pointer to the client data. This equals the AData parameter passed to SetData.

When the vertex attribute is used with a TGLBuffer (that is, when SetConfig is used), then the returned value is undefined.

OpenGL API: glGetVertexAttribPointerv

See also
SetConfig
SetData
GetOffset
When the vertex attribute is used with a TGLBuffer (that is, when SetConfig is used), then this method returns the byte offset into the buffer objects's data store for this vertex attribute.

Properties

property Location: GLint read FLocation;

The location of this attribute in the vertex shader of the program.


Generated by PasDocEx, based on PasDoc 0.14.0.