RenderState Class

class QSGMaterialShader::RenderState

Encapsulates the current rendering state during a call to QSGMaterialShader::updateUniformData() and the other update type of functions. More...

Public Types

enum DirtyState { DirtyMatrix, DirtyOpacity, DirtyCachedMaterialData, DirtyAll }
flags DirtyStates

Public Functions

QMatrix4x4 combinedMatrix() const
float determinant() const
float devicePixelRatio() const
QRect deviceRect() const
RenderState::DirtyStates dirtyStates() const
bool isMatrixDirty() const
bool isOpacityDirty() const
QMatrix4x4 modelViewMatrix() const
float opacity() const
QMatrix4x4 projectionMatrix() const
QRhiResourceUpdateBatch *resourceUpdateBatch()
QRhi *rhi()
QByteArray *uniformData()
QRect viewportRect() const

Detailed Description

The render state contains a number of accessors that the shader needs to respect in order to conform to the current state of the scene graph.

Member Type Documentation

enum RenderState::DirtyState
flags RenderState::DirtyStates

ConstantValueDescription
QSGMaterialShader::RenderState::DirtyMatrix0x0001Used to indicate that the matrix has changed and must be updated.
QSGMaterialShader::RenderState::DirtyOpacity0x0002Used to indicate that the opacity has changed and must be updated.
QSGMaterialShader::RenderState::DirtyCachedMaterialData0x0004Used to indicate that the cached material state has changed and must be updated.
QSGMaterialShader::RenderState::DirtyAll0xFFFFUsed to indicate that everything needs to be updated.

The DirtyStates type is a typedef for QFlags<DirtyState>. It stores an OR combination of DirtyState values.

Member Function Documentation

QMatrix4x4 RenderState::combinedMatrix() const

Returns the matrix combined of modelview matrix and project matrix.

float RenderState::determinant() const

Returns the modelview determinant to be used for rendering.

float RenderState::devicePixelRatio() const

Returns the ratio between physical pixels and device-independent pixels to be used for rendering.

QRect RenderState::deviceRect() const

Returns the device rect of the surface being rendered to

RenderState::DirtyStates RenderState::dirtyStates() const

Returns which rendering states that have changed and needs to be updated for geometry rendered with this material to conform to the current rendering state.

bool RenderState::isMatrixDirty() const

Returns true if the dirtyStates() contain the dirty matrix state, otherwise returns false.

bool RenderState::isOpacityDirty() const

Returns true if the dirtyStates() contains the dirty opacity state, otherwise returns false.

QMatrix4x4 RenderState::modelViewMatrix() const

Returns the model view matrix.

If the material has the RequiresFullMatrix flag set, this is guaranteed to be the complete transform matrix calculated from the scenegraph.

However, if this flag is not set, the renderer may choose to alter this matrix. For example, it may pre-transform vertices on the CPU and set this matrix to identity.

In a situation such as the above, it is still possible to retrieve the actual matrix determinant by setting the RequiresDeterminant flag in the material and calling the determinant() accessor.

float RenderState::opacity() const

Returns the accumulated opacity to be used for rendering.

QMatrix4x4 RenderState::projectionMatrix() const

Returns the projection matrix.

QRhiResourceUpdateBatch *RenderState::resourceUpdateBatch()

Returns a resource update batch to which upload and copy operatoins can be queued. This is typically used by QSGMaterialShader::updateSampledImage() to enqueue texture image content updates.

QRhi *RenderState::rhi()

Returns the current QRhi.

QByteArray *RenderState::uniformData()

Returns a pointer to the data for the uniform (constant) buffer in the shader. Uniform data must only be updated from QSGMaterialShader::updateUniformData(). The return value is null in the other reimplementable functions, such as, QSGMaterialShader::updateSampledImage().

Note: It is strongly recommended to declare the uniform block with std140 in the shader, and to carefully study the standard uniform block layout as described in section 7.6.2.2 of the OpenGL specification. It is up to the QSGMaterialShader implementation to ensure data gets placed at the right location in this QByteArray, taking alignment requirements into account. Shader code translated to other shading languages is expected to use the same offsets for block members, even when the target language uses different packing rules by default.

Note: Avoid copying from C++ POD types, such as, structs, in order to update multiple members at once, unless it has been verified that the layouts of the C++ struct and the GLSL uniform block match.

QRect RenderState::viewportRect() const

Returns the viewport rect of the surface being rendered to.

© 2023 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.