QRhiVertexInputAttribute Class
Describes a single vertex input element. More...
Header: | #include <QRhiVertexInputAttribute> |
qmake: | QT += rhi |
Public Types
enum | Format { Float4, Float3, Float2, Float, ..., UNormByte } |
Public Functions
QRhiVertexInputAttribute() | |
QRhiVertexInputAttribute(int binding, int location, QRhiVertexInputAttribute::Format format, quint32 offset) | |
int | binding() const |
QRhiVertexInputAttribute::Format | format() const |
int | location() const |
quint32 | offset() const |
void | setBinding(int b) |
void | setFormt(QRhiVertexInputAttribute::Format f) |
void | setLocation(int loc) |
void | setOffset(quint32 ofs) |
Related Non-Members
uint | qHash(const QRhiVertexInputAttribute &v, uint seed = 0) |
bool | operator!=(const QRhiVertexInputAttribute &a, const QRhiVertexInputAttribute &b) |
bool | operator==(const QRhiVertexInputAttribute &a, const QRhiVertexInputAttribute &b) |
Detailed Description
Describes a single vertex input element.
The members specify the binding number, location, format, and offset for a single vertex input element.
Note: For HLSL it is assumed that the vertex shader uses TEXCOORD<location>
as the semantic for each input. Hence no separate semantic name and index.
As an example, assume a vertex shader with the following inputs:
layout(location = 0) in vec4 position; layout(location = 1) in vec2 texcoord;
Now let's assume that we have 3 component vertex positions (x, y, z)
and 2 component texture coordinates (u, v)
are provided in a non-interleaved format in a buffer (or separate buffers even). Once two bindings are defined, the attributes could be specified as:
QRhiVertexInputLayout inputLayout; inputLayout.setBindings({ { 3 * sizeof(float) }, { 2 * sizeof(float) } }); inputLayout.setAttributes({ { 0, 0, QRhiVertexInputAttribute::Float3, 0 }, { 1, 1, QRhiVertexInputAttribute::Float2, 0 } });
Once a graphics pipeline with this vertex input layout is bound, the vertex inputs could be set up like the following for drawing a cube with 36 vertices, assuming we have a single buffer with first the positions and then the texture coordinates:
const QRhiCommandBuffer::VertexInput vbufBindings[] = { { cubeBuf, 0 }, { cubeBuf, 36 * 3 * sizeof(float) } }; cb->setVertexInput(0, 2, vbufBindings);
When working with interleaved data, there will typically be just one binding, with multiple attributes referring to that same buffer binding point:
QRhiVertexInputLayout inputLayout; inputLayout.setBindings({ { 5 * sizeof(float) } }); inputLayout.setAttributes({ { 0, 0, QRhiVertexInputAttribute::Float3, 0 }, { 0, 1, QRhiVertexInputAttribute::Float2, 3 * sizeof(float) } });
and then:
const QRhiCommandBuffer::VertexInput vbufBinding(interleavedCubeBuf, 0); cb->setVertexInput(0, 1, &vbufBinding);
See also QRhiCommandBuffer::setVertexInput().
Member Type Documentation
enum QRhiVertexInputAttribute::Format
Specifies the type of the element data.
Constant | Value | Description |
---|---|---|
QRhiVertexInputAttribute::Float4 | 0 | Four component float vector |
QRhiVertexInputAttribute::Float3 | 1 | Three component float vector |
QRhiVertexInputAttribute::Float2 | 2 | Two component float vector |
QRhiVertexInputAttribute::Float | 3 | Float |
QRhiVertexInputAttribute::UNormByte4 | 4 | Four component normalized unsigned byte vector |
QRhiVertexInputAttribute::UNormByte2 | 5 | Two component normalized unsigned byte vector |
QRhiVertexInputAttribute::UNormByte | 6 | Normalized unsigned byte |
Property Documentation
Member Function Documentation
QRhiVertexInputAttribute::QRhiVertexInputAttribute()
Constructs a default vertex input attribute description.
QRhiVertexInputAttribute::QRhiVertexInputAttribute(int binding, int location, QRhiVertexInputAttribute::Format format, quint32 offset)
Constructs a vertex input attribute description with the specified binding number, location, format, and offset.
int QRhiVertexInputAttribute::binding() const
See also setBinding().
QRhiVertexInputAttribute::Format QRhiVertexInputAttribute::format() const
int QRhiVertexInputAttribute::location() const
See also setLocation().
quint32 QRhiVertexInputAttribute::offset() const
See also setOffset().
void QRhiVertexInputAttribute::setBinding(int b)
See also binding().
void QRhiVertexInputAttribute::setFormt(QRhiVertexInputAttribute::Format f)
void QRhiVertexInputAttribute::setLocation(int loc)
See also location().
void QRhiVertexInputAttribute::setOffset(quint32 ofs)
See also offset().
Member Variable Documentation
Related Non-Members
uint qHash(const QRhiVertexInputAttribute &v, uint seed = 0)
Returns the hash value for v, using seed to seed the calculation.
bool operator!=(const QRhiVertexInputAttribute &a, const QRhiVertexInputAttribute &b)
Returns false
if the values in the two QRhiVertexInputAttribute objects a and b are equal; otherwise returns true
.
bool operator==(const QRhiVertexInputAttribute &a, const QRhiVertexInputAttribute &b)
Returns true
if the values in the two QRhiVertexInputAttribute objects a and b are equal.