QRhiShaderStage Class

Specifies the type and the shader code for a shader stage in the pipeline. 更多...

頭: #include <rhi/qrhi.h>
CMake: find_package(Qt6 REQUIRED COMPONENTS GuiPrivate)
target_link_libraries(mytarget PRIVATE Qt6::GuiPrivate)
qmake: QT += gui-private
Since: Qt 6.6

公共類型

enum Type { Vertex, TessellationControl, TessellationEvaluation, Fragment, Compute, Geometry }

公共函數

QRhiShaderStage ()
QRhiShaderStage (QRhiShaderStage::Type type , const QShader & shader , QShader::Variant v = QShader::StandardShader)
void setShader (const QShader & s )
void setShaderVariant (QShader::Variant v )
void setType (QRhiShaderStage::Type t )
QShader shader () const
QShader::Variant shaderVariant () const
QRhiShaderStage::Type type () const
size_t qHash (const QRhiShaderStage & key , size_t seed = 0)
bool operator!= (const QRhiShaderStage & a , const QRhiShaderStage & b )
bool operator== (const QRhiShaderStage & a , const QRhiShaderStage & b )

詳細描述

When setting up a QRhiGraphicsPipeline , a collection of shader stages are specified. The QRhiShaderStage contains a QShader and some associated metadata, such as the graphics pipeline stage, and the shader variant to select. There is no need to specify the shader language or version because the QRhi backend in use at runtime will take care of choosing the appropriate shader version from the collection within the QShader .

The typical usage is in combination with QRhiGraphicsPipeline::setShaderStages (), shown here with a simple approach to load the QShader from .qsb files generated offline or at build time:

QShader getShader(const QString &name)
{
    QFile f(name);
    return f.open(QIODevice::ReadOnly) ? QShader::fromSerialized(f.readAll()) : QShader();
}
QShader vs = getShader("material.vert.qsb");
QShader fs = getShader("material.frag.qsb");
pipeline->setShaderStages({
    { QRhiShaderStage::Vertex, vs },
    { QRhiShaderStage::Fragment, fs }
});
					

注意: This is a RHI API with limited compatibility guarantees, see QRhi 瞭解細節。

成員類型文檔編製

enum QRhiShaderStage:: Type

Specifies the type of the shader stage.

常量 描述
QRhiShaderStage::Vertex 0 Vertex stage
QRhiShaderStage::TessellationControl 1 Tessellation control (hull shader) stage. Must be used only when the QRhi::Tessellation feature is supported.
QRhiShaderStage::TessellationEvaluation 2 Tessellation evaluation (domain shader) stage. Must be used only when the QRhi::Tessellation feature is supported.
QRhiShaderStage::Fragment 4 Fragment (pixel shader) stage
QRhiShaderStage::Compute 5 Compute stage. Must be used only when the QRhi::Compute feature is supported.
QRhiShaderStage::Geometry 3 Geometry stage. Must be used only when the QRhi::GeometryShader feature is supported.

成員函數文檔編製

[noexcept] QRhiShaderStage:: QRhiShaderStage ()

Constructs a shader stage description for the vertex stage with an empty QShader .

QRhiShaderStage:: QRhiShaderStage ( QRhiShaderStage::Type type , const QShader & shader , QShader::Variant v = QShader::StandardShader)

Constructs a shader stage description with the type of the stage and the shader .

The shader variant v 默認為 QShader::StandardShader QShader contains multiple source and binary versions of a shader. In addition, it can also contain variants of the shader with slightly modified code. v can then be used to select the desired variant.

void QRhiShaderStage:: setShader (const QShader & s )

Sets the shader collection s .

另請參閱 shader ().

void QRhiShaderStage:: setShaderVariant ( QShader::Variant v )

Sets the requested shader variant v .

另請參閱 shaderVariant ().

void QRhiShaderStage:: setType ( QRhiShaderStage::Type t )

Sets the type of the stage to t . Setters should rarely be needed in pratice. Most applications will likely use the QRhiShaderStage constructor in most cases.

另請參閱 type ().

QShader QRhiShaderStage:: shader () const

返迴 QShader to be used for this stage in the graphics pipeline.

另請參閱 setShader ().

QShader::Variant QRhiShaderStage:: shaderVariant () const

Returns the requested shader variant.

另請參閱 setShaderVariant ().

QRhiShaderStage::Type QRhiShaderStage:: type () const

Returns the type of the stage.

另請參閱 setType ().

相關非成員

[noexcept] size_t qHash (const QRhiShaderStage & key , size_t seed = 0)

返迴哈希值為 key ,使用 seed 做計算種子。

[noexcept] bool operator!= (const QRhiShaderStage & a , const QRhiShaderStage & b )

返迴 false if the values in the two QRhiShaderStage 對象 a and b 相等;否則返迴 true .

[noexcept] bool operator== (const QRhiShaderStage & a , const QRhiShaderStage & b )

返迴 true if the values in the two QRhiShaderStage 對象 a and b 相等。