LLGL 0.05 Beta
Loading...
Searching...
No Matches
LLGL::VertexAttribute Struct Reference

Vertex input/output attribute structure. More...

#include <VertexAttribute.h>

Public Member Functions

 VertexAttribute ()=default
 VertexAttribute (StringLiteral name, const Format format, std::uint32_t location=0, std::uint32_t instanceDivisor=0, const SystemValue systemValue=SystemValue::Undefined)
 Constructor for minimal vertex attribute information and system value semantics, e.g. SV_VertexID (HLSL) or gl_VertexID (GLSL).
 VertexAttribute (StringLiteral semanticName, std::uint32_t semanticIndex, const Format format, std::uint32_t location=0, std::uint32_t instanceDivisor=0)
 Constructor for basic vertex attribute information.
 VertexAttribute (StringLiteral name, const Format format, std::uint32_t location, std::uint32_t offset, std::uint32_t stride, std::uint32_t slot=0, std::uint32_t instanceDivisor=0)
 Constructor for common vertex attribute information.
 VertexAttribute (StringLiteral semanticName, std::uint32_t semanticIndex, const Format format, std::uint32_t location, std::uint32_t offset, std::uint32_t stride, std::uint32_t slot=0, std::uint32_t instanceDivisor=0)
 Constructor for the most vertex attribute information, including semantic index.
std::uint32_t GetSize () const
 Returns the size (in bytes) which is required for this vertex attribute, or zero if the format is not a valid vertex format.

Public Attributes

StringLiteral name
 Vertex attribute name (for GLSL) or semantic name (for HLSL).
Format format = Format::RGBA32Float
 Vertex attribute format. By default Format::RGBA32Float.
std::uint32_t location = 0
 Vertex attribute location (only for OpenGL, Vulkan, Metal) or stream-output number (only for Direct3D).
std::uint32_t semanticIndex = 0
 Semantic index for HLSL.
SystemValue systemValue = SystemValue::Undefined
 Specifies the system value type for this vertex attribute or SystemValue::Undefined if this attribute is not a system value. By default SystemValue::Undefined.
std::uint32_t slot = 0
 Vertex buffer binding slot. By default 0.
std::uint32_t offset = 0
 Byte offset within each vertex and each buffer for input attributes, or component offset for output attributes. By default 0.
std::uint32_t stride = 0
 Specifies the vertex data stride which describes the byte offset between consecutive vertices.
std::uint32_t instanceDivisor = 0
 Instance data divisor (or instance data step rate).

Detailed Description

Vertex input/output attribute structure.

Remarks
For attributes within the same vertex buffer, the following members must have the same value:
  • slot
  • stride
  • instanceDivisor
See also
VertexShaderAttributes::inputAttribs
VertexShaderAttributes::outputAttribs
BufferDescriptor::vertexAttribs
VertexFormat::attributes
FragmentAttribute

Constructor & Destructor Documentation

◆ VertexAttribute() [1/5]

LLGL::VertexAttribute::VertexAttribute ( )
default

◆ VertexAttribute() [2/5]

LLGL::VertexAttribute::VertexAttribute ( StringLiteral name,
const Format format,
std::uint32_t location = 0,
std::uint32_t instanceDivisor = 0,
const SystemValue systemValue = SystemValue::Undefined )

Constructor for minimal vertex attribute information and system value semantics, e.g. SV_VertexID (HLSL) or gl_VertexID (GLSL).

◆ VertexAttribute() [3/5]

LLGL::VertexAttribute::VertexAttribute ( StringLiteral semanticName,
std::uint32_t semanticIndex,
const Format format,
std::uint32_t location = 0,
std::uint32_t instanceDivisor = 0 )

Constructor for basic vertex attribute information.

◆ VertexAttribute() [4/5]

LLGL::VertexAttribute::VertexAttribute ( StringLiteral name,
const Format format,
std::uint32_t location,
std::uint32_t offset,
std::uint32_t stride,
std::uint32_t slot = 0,
std::uint32_t instanceDivisor = 0 )

Constructor for common vertex attribute information.

◆ VertexAttribute() [5/5]

LLGL::VertexAttribute::VertexAttribute ( StringLiteral semanticName,
std::uint32_t semanticIndex,
const Format format,
std::uint32_t location,
std::uint32_t offset,
std::uint32_t stride,
std::uint32_t slot = 0,
std::uint32_t instanceDivisor = 0 )

Constructor for the most vertex attribute information, including semantic index.

Member Function Documentation

◆ GetSize()

std::uint32_t LLGL::VertexAttribute::GetSize ( ) const

Returns the size (in bytes) which is required for this vertex attribute, or zero if the format is not a valid vertex format.

See also
FormatAttributes::bitSize
FormatFlags::SupportsVertex
Format

Member Data Documentation

◆ format

Format LLGL::VertexAttribute::format = Format::RGBA32Float

Vertex attribute format. By default Format::RGBA32Float.

Remarks
Not all hardware formats are allowed for vertex attributes. In particular, depth-stencil formats and compressed formats are not allowed. To specify a vertex attribute of a matrix type, multiple attributes with ascending semantic indices must be used. Here is an example of a 4x4 matrix:
myVertexFormat.AppendAttribute({ "myMatrix4x4", 0, LLGL::Format::RGBA32Float });
myVertexFormat.AppendAttribute({ "myMatrix4x4", 1, LLGL::Format::RGBA32Float });
myVertexFormat.AppendAttribute({ "myMatrix4x4", 2, LLGL::Format::RGBA32Float });
myVertexFormat.AppendAttribute({ "myMatrix4x4", 3, LLGL::Format::RGBA32Float });
@ RGBA32Float
Ordinary color format: red, green, blue, alpha 32-bit floating point components.
Definition Format.h:193
Here is an example of a 2x2 matrix:
myVertexFormat.AppendAttribute({ "myMatrix2x2", 0, LLGL::Format::RG32Float });
myVertexFormat.AppendAttribute({ "myMatrix2x2", 1, LLGL::Format::RG32Float });
@ RG32Float
Ordinary color format: red, green 32-bit floating point components.
Definition Format.h:155

◆ instanceDivisor

std::uint32_t LLGL::VertexAttribute::instanceDivisor = 0

Instance data divisor (or instance data step rate).

Remarks
If this is 0, this attribute is considered to be stored per vertex. If this is greater than 0, this attribute is considered to be stored per every instanceDivisor's instance.
Vertex attributes that share the same input slot must have the same instance divisor. For example, in order to stream vertex and instance data from the same buffer, this buffer must be bound at two separate binding slots.
Note
For Vulkan, this must only be 0 or 1.

◆ location

std::uint32_t LLGL::VertexAttribute::location = 0

Vertex attribute location (only for OpenGL, Vulkan, Metal) or stream-output number (only for Direct3D).

Remarks
This is only required for OpenGL, Vulkan, and Metal. For Direct3D, this is ignored and instead semanticIndex is used.
The following example shows GLSL attribute locations from 0 to 4 inclusive:
layout(location = 0) in vec4 vertexPosition; // location 0
layout(location = 1) in mat4 projectionMatrix; // location 1...4
std::uint32_t location
Vertex attribute location (only for OpenGL, Vulkan, Metal) or stream-output number (only for Direct3D...
Definition VertexAttribute.h:133
The following example shows Metal attribute locations from 0 to 4 inclusive:
struct MyVertexInput
{
float4 vertexPosition [[attribute(0)]];
float4 projectionMatrix0 [[attribute(1)]];
float4 projectionMatrix1 [[attribute(2)]];
float4 projectionMatrix2 [[attribute(3)]];
float4 projectionMatrix3 [[attribute(4)]];
};

◆ name

StringLiteral LLGL::VertexAttribute::name

Vertex attribute name (for GLSL) or semantic name (for HLSL).

◆ offset

std::uint32_t LLGL::VertexAttribute::offset = 0

Byte offset within each vertex and each buffer for input attributes, or component offset for output attributes. By default 0.

Remarks
For vertex input attributes, this offset specifies the byte aligned offset within each vertex buffer.
For stream-output attributes, this offset specifies the first component that is to be written and must be either 0, 1, 2, or 3.

◆ semanticIndex

std::uint32_t LLGL::VertexAttribute::semanticIndex = 0

Semantic index for HLSL.

Remarks
This is only required for Direct3D when a semantic name is used multiple times. This happens when a matrix type is distributed over multiple vector attributes.
The following example uses semantic names POS0, MATRIX0, MATRIX1, MATRIX2, MATRIX3:
struct MyVertexInput
{
float4 vertexPosition : POS;
float4x4 projectionMatrix : MATRIX;
};

◆ slot

std::uint32_t LLGL::VertexAttribute::slot = 0

Vertex buffer binding slot. By default 0.

Remarks
This is used when multiple vertex buffers are bound simultaneously. This binding slot refers either to the input buffer indices (determined by SetVertexBufferArray), or stream-output buffer indices (determined by BeginStreamOutput).
See also
CommandBuffer::SetVertexBuffers
CommandBuffer::SetVertexBufferArray
CommandBuffer::BeginStreamOutput

◆ stride

std::uint32_t LLGL::VertexAttribute::stride = 0

Specifies the vertex data stride which describes the byte offset between consecutive vertices.

◆ systemValue

SystemValue LLGL::VertexAttribute::systemValue = SystemValue::Undefined

Specifies the system value type for this vertex attribute or SystemValue::Undefined if this attribute is not a system value. By default SystemValue::Undefined.

Remarks
System value semantics are only used for shader code reflection. Examples of system value semantics are:
  • Vertex ID: SV_VertexID (HLSL), gl_VertexID (GLSL), gl_VertexIndex (SPIR-V), [[vertex_id]] (Metal).
  • Instance ID: SV_InstanceID (HLSL), gl_InstanceID (GLSL), gl_InstanceIndex (SPIR-V), [[instance_id]] (Metal).
See also
Shader::Reflect

The documentation for this struct was generated from the following file: