QSGMaterialRhiShader Class

The QSGMaterialRhiShader class represents a graphics API independent shader program. 更多...

头: #include <QSGMaterialRhiShader>
qmake: QT += quick
Since: Qt 5.14
继承: QSGMaterialShader

该类在 Qt 5.14 引入。

公共类型

struct GraphicsPipelineState
class RenderState
enum Flag { UpdatesGraphicsPipelineState }
flags Flags

公共函数

QSGMaterialRhiShader ()
QSGMaterialRhiShader::Flags flags () const
void setFlag (QSGMaterialRhiShader::Flags flags , bool on = true)
virtual bool updateGraphicsPipelineState (QSGMaterialRhiShader::RenderState & state , QSGMaterialRhiShader::GraphicsPipelineState * ps , QSGMaterial * newMaterial , QSGMaterial * oldMaterial )
virtual void updateSampledImage (QSGMaterialRhiShader::RenderState & state , int binding , QSGTexture ** texture , QSGMaterial * newMaterial , QSGMaterial * oldMaterial )
virtual bool updateUniformData (QSGMaterialRhiShader::RenderState & state , QSGMaterial * newMaterial , QSGMaterial * oldMaterial )

保护函数

void setShader (QSGMaterialRhiShader::Stage stage , const QShader & shader )
void setShaderFileName (QSGMaterialRhiShader::Stage stage , const QString & filename )

详细描述

QSGMaterialRhiShader is a modern, cross-platform alternative to QSGMaterialShader . The latter is tied to OpenGL and GLSL by design, whereas QSGMaterialRhiShader is based on QShader, a container for multiple versions of a graphics shader together with reflection information.

注意: 所有带有 QSG 前缀的类只应用于场景图形渲染线程。见 场景图形和渲染 了解更多信息。

成员类型文档编制

enum QSGMaterialRhiShader:: Flag
flags QSGMaterialRhiShader:: Flags

Flag values to indicate special material properties.

常量 描述
QSGMaterialRhiShader::UpdatesGraphicsPipelineState 0x0001 Setting this flag enables calling updateGraphicsPipelineState ().

Flags 类型是 typedef 对于 QFlags <Flag>。它存储 Flag 值的 OR 组合。

成员函数文档编制

QSGMaterialRhiShader:: QSGMaterialRhiShader ()

Constructs a new QSGMaterialRhiShader.

QSGMaterialRhiShader::Flags QSGMaterialRhiShader:: flags () const

Returns the currently set flags for this material shader.

void QSGMaterialRhiShader:: setFlag ( QSGMaterialRhiShader::Flags flags , bool on = true)

设置 flags on this material shader if on is true; otherwise clears the specified flags.

[protected] void QSGMaterialRhiShader:: setShader ( QSGMaterialRhiShader::Stage stage , const QShader & shader )

设置 shader 为指定 stage .

[protected] void QSGMaterialRhiShader:: setShaderFileName ( QSGMaterialRhiShader::Stage stage , const QString & filename )

设置 filename for the shader for the specified stage .

The file is expected to contain a serialized QRhiShader.

[virtual] bool QSGMaterialRhiShader:: updateGraphicsPipelineState ( QSGMaterialRhiShader::RenderState & state , QSGMaterialRhiShader::GraphicsPipelineState * ps , QSGMaterial * newMaterial , QSGMaterial * oldMaterial )

This function is called by the scene graph to enable the material to provide a custom set of graphics state. The set of states that are customizable by material is limited to blending and related settings.

注意: This function is only called when the UpdatesGraphicsPipelineState flag was enabled via setFlags(). By default it is not set, and so this function is never called.

The return value must be true whenever a change was made to any of the members in ps .

注意: The contents of ps is not persistent between invocations of this function.

The current rendering state is passed from the scene graph.

The subclass specific state can be extracted from newMaterial 。当 oldMaterial is null, this shader was just activated.

[virtual] void QSGMaterialRhiShader:: updateSampledImage ( QSGMaterialRhiShader::RenderState & state , int binding , QSGTexture ** texture , QSGMaterial * newMaterial , QSGMaterial * oldMaterial )

This function is called by the scene graph to prepare using a sampled image in the shader, typically in form of a combined image sampler.

binding is the binding number of the sampler. The function is called for each variable in the material's shaders' QShaderDescription::combinedImageSamplers ().

When * texture is null, it must be set to a QSGTexture pointer before returning. When non-null, it is up to the material to decide if a new QSGTexture * is stored to it, or if it updates some parameters on the already known QSGTexture . The ownership of the QSGTexture is not transferred.

The current rendering state is passed from the scene graph. It is up to the material to enqueue the texture data uploads to the QRhiResourceUpdateBatch retriveable via RenderState::resourceUpdateBatch ().

The subclass specific state can be extracted from newMaterial .

oldMaterial can be used to minimize changes. When oldMaterial is null, this shader was just activated.

[virtual] bool QSGMaterialRhiShader:: updateUniformData ( QSGMaterialRhiShader::RenderState & state , QSGMaterial * newMaterial , QSGMaterial * oldMaterial )

This function is called by the scene graph to get the contents of the shader program's uniform buffer updated. The implementation is not expected to perform any real graphics operations, it is merely responsible for copying data to the QByteArray returned from RenderState::uniformData (). The scene graph takes care of making that buffer visible in the shaders.

The current rendering state is passed from the scene graph. If the state indicates that any relevant state is dirty, the implementation must update the appropriate region in the buffer data that is accessible via RenderState::uniformData (). When a state, such as, matrix or opacity, is not dirty, there is no need to touch the corresponding region since the data is persistent.

The return value must be true whenever any change was made to the uniform data.

The subclass specific state, such as the color of a flat color material, should be extracted from newMaterial to update the relevant regions in the buffer accordingly.

oldMaterial can be used to minimize buffer changes (which are typically memcpy calls) when updating material states. When oldMaterial is null, this shader was just activated.