4#ifndef QSGMATERIALSHADER_H
5#define QSGMATERIALSHADER_H
7#include <QtQuick/qtquickglobal.h>
9#include <QtGui/QMatrix4x4>
10#include <QtGui/QColor>
11#include <QtQuick/qsgmaterialtype.h>
16class QSGMaterialShaderPrivate;
18class QRhiResourceUpdateBatch;
25 class Q_QUICK_EXPORT RenderState {
30 DirtyOpacity = 0x0002,
31 DirtyCachedMaterialData = 0x0004,
34 Q_DECLARE_FLAGS(DirtyStates, DirtyState)
36 inline DirtyStates dirtyStates()
const {
return m_dirty; }
38 inline bool isMatrixDirty()
const {
return bool(m_dirty & QSGMaterialShader::RenderState::DirtyMatrix); }
39 inline bool isOpacityDirty()
const {
return bool(m_dirty & QSGMaterialShader::RenderState::DirtyOpacity); }
41 float opacity()
const;
42 QMatrix4x4 combinedMatrix()
const;
43 QMatrix4x4 combinedMatrix(qsizetype index)
const;
44 QMatrix4x4 modelViewMatrix()
const;
45 QMatrix4x4 projectionMatrix()
const;
46 QMatrix4x4 projectionMatrix(qsizetype index)
const;
47 qsizetype projectionMatrixCount()
const;
48 QRect viewportRect()
const;
49 QRect deviceRect()
const;
50 float determinant()
const;
51 float devicePixelRatio()
const;
53 QByteArray *uniformData();
54 QRhiResourceUpdateBatch *resourceUpdateBatch();
58 friend class QSGRenderer;
63 struct GraphicsPipelineState {
76 OneMinusConstantColor,
78 OneMinusConstantAlpha,
94 enum ColorMaskComponent {
100 Q_DECLARE_FLAGS(ColorMask, ColorMaskComponent)
114 BlendFactor srcColor;
115 BlendFactor dstColor;
116 ColorMask colorWrite;
117 QColor blendConstant;
119 PolygonMode polygonMode;
120 bool separateBlendFactors;
121 BlendFactor srcAlpha;
122 BlendFactor dstAlpha;
131 UpdatesGraphicsPipelineState = 0x0001
133 Q_DECLARE_FLAGS(Flags, Flag)
141 virtual ~QSGMaterialShader();
143 virtual bool updateUniformData(RenderState &state,
144 QSGMaterial *newMaterial, QSGMaterial *oldMaterial);
146 virtual void updateSampledImage(RenderState &state,
int binding, QSGTexture **texture,
147 QSGMaterial *newMaterial, QSGMaterial *oldMaterial);
149 virtual bool updateGraphicsPipelineState(RenderState &state, GraphicsPipelineState *ps,
150 QSGMaterial *newMaterial, QSGMaterial *oldMaterial);
153 void setFlag(Flags flags,
bool on =
true);
154 void setFlags(Flags flags);
156 int combinedImageSamplerCount(
int binding)
const;
159 Q_DECLARE_PRIVATE(QSGMaterialShader)
160 QSGMaterialShader(QSGMaterialShaderPrivate &dd);
163 void setShaderFileName(Stage stage,
const QString &filename);
164 void setShaderFileName(Stage stage,
const QString &filename,
int viewCount);
166 void setShader(Stage stage,
const QShader &shader);
169 QScopedPointer<QSGMaterialShaderPrivate> d_ptr;
172Q_DECLARE_OPERATORS_FOR_FLAGS(QSGMaterialShader::RenderState::DirtyStates)
173Q_DECLARE_OPERATORS_FOR_FLAGS(QSGMaterialShader::GraphicsPipelineState::ColorMask)
174Q_DECLARE_OPERATORS_FOR_FLAGS(QSGMaterialShader::Flags)
const Type * at(uint index) const
char data[sizeof(Type) *PageSize]
QVector< AllocatorPage< Type, PageSize > * > pages
void releaseExplicit(uint pageIndex, uint index)
void clearCachedRendererData()
Shader * prepareMaterial(QSGMaterial *material, const QSGGeometry *geometry=nullptr, QSGRendererInterface::RenderMode renderMode=QSGRendererInterface::RenderMode2D, int multiViewCount=0)
QMultiHash< QVector< quint32 >, QRhiShaderResourceBindings * > srbPool
QHash< GraphicsPipelineStateKey, QRhiGraphicsPipeline * > pipelineCache
ShaderManager(QSGDefaultRenderContext *ctx)
QVector< quint32 > srbLayoutDescSerializeWorkspace
Shader * prepareMaterialNoRewrite(QSGMaterial *material, const QSGGeometry *geometry=nullptr, QSGRendererInterface::RenderMode renderMode=QSGRendererInterface::RenderMode2D, int multiViewCount=0)
void updateRootTransforms(Node *n, Node *root, const QMatrix4x4 &combined)
void registerWithParentRoot(QSGNode *subRoot, QSGNode *parentRoot)
void visitClipNode(Node *n)
void updateStates(QSGNode *n) override
void visitOpacityNode(Node *n)
void updateRootTransforms(Node *n)
void visitTransformNode(Node *n)
void visitGeometryNode(Node *n)
virtual void visualize()=0
Visualizer(Renderer *renderer)
void setMode(VisualizeMode mode)
virtual void visualizeChangesPrepare(Node *n, uint parentChanges=0)
virtual void prepareVisualize()=0
VisualizeMode mode() const
virtual void releaseResources()=0
QHash< Node *, uint > m_visualizeChangeSet
VisualizeMode m_visualizeMode
The QSGMaterialShader class represents a graphics API independent shader program.
const int ZORDER_BUFFER_BINDING
static void qsg_wipeBuffer(Buffer *buffer)
static void rendererToMaterialGraphicsState(QSGMaterialShader::GraphicsPipelineState *dst, GraphicsState *src)
size_t qHash(const GraphicsState &s, size_t seed) noexcept
static QRhiVertexInputLayout calculateVertexInputLayout(const QSGMaterialShader *s, const QSGGeometry *geometry, bool batchable)
static void qsg_addBackOrphanedElements(QDataBuffer< Element * > &orphans, QDataBuffer< Element * > &renderList)
bool operator!=(const GraphicsPipelineStateKey &a, const GraphicsPipelineStateKey &b) noexcept
const float VIEWPORT_MIN_DEPTH
QSGMaterial::Flag QSGMaterial_FullMatrix
bool qsg_sort_batch_decreasing_order(Batch *a, Batch *b)
QDebug operator<<(QDebug d, const Pt &p)
QDebug operator<<(QDebug d, const Rect &r)
bool operator==(const ShaderKey &a, const ShaderKey &b) noexcept
bool operator==(const GraphicsPipelineStateKey &a, const GraphicsPipelineStateKey &b) noexcept
bool operator!=(const ShaderKey &a, const ShaderKey &b) noexcept
static void qsg_wipeBatch(Batch *batch)
static QRhiSampler * newSampler(QRhi *rhi, const QSGSamplerDescription &desc)
QRhiVertexInputAttribute::Format qsg_vertexInputFormat(const QSGGeometry::Attribute &a)
QRhiGraphicsPipeline::Topology qsg_topology(int geomDrawMode, QRhi *rhi)
QMatrix4x4 qsg_matrixForRoot(Node *node)
bool qsg_sort_batch_increasing_order(Batch *a, Batch *b)
static void qsg_addOrphanedElements(QDataBuffer< Element * > &orphans, const QDataBuffer< Element * > &renderList)
void qsg_setMultiViewFlagsOnMaterial(QSGMaterial *material, int multiViewCount)
const float VIEWPORT_MAX_DEPTH
int qsg_positionAttribute(QSGGeometry *g)
static int size_of_type(int type)
static bool isTranslate(const QMatrix4x4 &m)
static int qsg_countNodesInBatches(const QDataBuffer< Batch * > &batches)
static float calculateElementZOrder(const Element *e, qreal zRange)
static int qsg_fixIndexCount(int iCount, int drawMode)
bool qsg_sort_element_increasing_order(Element *a, Element *b)
static void materialToRendererGraphicsState(GraphicsState *dst, QSGMaterialShader::GraphicsPipelineState *src)
static bool needsBlendConstant(QRhiGraphicsPipeline::BlendFactor f)
const int VERTEX_BUFFER_BINDING
const uint DYNAMIC_VERTEX_INDEX_BUFFER_THRESHOLD
bool hasMaterialWithBlending(QSGGeometryNode *n)
static int qsg_countNodesInBatch(const Batch *batch)
bool operator==(const GraphicsState &a, const GraphicsState &b) noexcept
QRhiCommandBuffer::IndexFormat qsg_indexFormat(const QSGGeometry *geometry)
bool operator!=(const GraphicsState &a, const GraphicsState &b) noexcept
bool qsg_sort_element_decreasing_order(Element *a, Element *b)
size_t qHash(const ShaderKey &k, size_t seed) noexcept
void qsg_dumpShadowRoots(BatchRootInfo *i, int indent)
void qsg_dumpShadowRoots(Node *n)
static bool isScale(const QMatrix4x4 &m)
static bool is2DSafe(const QMatrix4x4 &m)
size_t qHash(const GraphicsPipelineStateKey &k, size_t seed) noexcept
Int aligned(Int v, Int byteAlign)
const quint32 DEFAULT_BUFFER_POOL_SIZE_LIMIT
Q_CORE_EXPORT QDebug operator<<(QDebug debug, QDir::Filters filters)
Q_DECLARE_TYPEINFO(QObjectPrivate::ConnectionList, Q_RELOCATABLE_TYPE)
#define DECLARE_DEBUG_VAR(variable)
#define QSGNODE_DIRTY_PARENT
QT_BEGIN_NAMESPACE int qt_sg_envInt(const char *name, int defaultValue)
#define SHADOWNODE_TRAVERSE(NODE)
#define QSGNODE_TRAVERSE(NODE)
Q_DECLARE_TYPEINFO(QSGBatchRenderer::DrawSet, Q_PRIMITIVE_TYPE)
Q_DECLARE_TYPEINFO(QSGBatchRenderer::GraphicsState, Q_RELOCATABLE_TYPE)
Q_DECLARE_TYPEINFO(QSGBatchRenderer::GraphicsPipelineStateKey, Q_RELOCATABLE_TYPE)
#define QSG_RENDERER_COORD_LIMIT
Q_DECLARE_TYPEINFO(QSGBatchRenderer::RenderPassState, Q_RELOCATABLE_TYPE)
bool geometryWasChanged(QSGGeometryNode *gn)
bool isSafeToBatch() const
void cleanupRemovedElements()
BatchCompatibility isMaterialCompatible(Element *e) const
bool isTranslateOnlyToRoot() const
StencilClipState stencilClipState
QDataBuffer< DrawSet > drawSets
uint nonDynamicChangeCount
DrawSet(int v, int z, int i)
QRhiGraphicsPipeline * depthPostPassPs
QRhiShaderResourceBindings * srb
QRhiGraphicsPipeline * ps
void setNode(QSGGeometryNode *n)
uint boundsOutsideFloatRange
const ShaderManagerShader * sms
size_t srbLayoutDescriptionHash
size_t renderTargetDescriptionHash
static GraphicsPipelineStateKey create(const GraphicsState &state, const ShaderManagerShader *sms, const QRhiRenderPassDescriptor *rpDesc, const QRhiShaderResourceBindings *srb)
QVector< quint32 > renderTargetDescription
QVector< quint32 > srbLayoutDescription
QSGGeometry::DrawingMode drawMode
QSGNode::NodeType type() const
BatchRootInfo * rootInfo() const
QSGNode::DirtyState dirtyState
ClipBatchRootInfo * clipInfo() const
Node * firstChild() const
RenderNodeElement * renderNodeElement() const
Element * element() const
bool hasChild(Node *child) const
void map(const QMatrix4x4 &mat)
void set(float nx, float ny)
void operator|=(const Pt &pt)
void set(float left, float top, float right, float bottom)
void map(const QMatrix4x4 &m)
bool isOutsideFloatRange() const
bool intersects(const Rect &r)
void operator|=(const Rect &r)
RenderNodeElement(QSGRenderNode *rn)
QSGRenderNode * renderNode
bool stencilEnabled() const override
QRect scissorRect() const override
const QMatrix4x4 * projectionMatrix() const override
const QRegion * clipRegion() const override
bool scissorEnabled() const override
int stencilValue() const override
const QMatrix4x4 * m_projectionMatrix
QRhiDepthStencilClearValue dsClear
QSGRendererInterface::RenderMode renderMode
QSGMaterialShader * materialShader
QRhiVertexInputLayout inputLayout
QVarLengthArray< QRhiShaderStage, 2 > stages
QRhiCommandBuffer::IndexFormat indexFormat
QRhiShaderResourceBindings * srb
QDataBuffer< StencilDrawCall > drawCalls