Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qsgdefaultinternalrectanglenode.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
5
6#include <QtQuick/qsgvertexcolormaterial.h>
7#include <QtQuick/qsgtexturematerial.h>
8
9#include <QtQuick/private/qsgcontext_p.h>
10
11#include <QtCore/qmath.h>
12#include <QtCore/qvarlengtharray.h>
13
15
17{
18public:
19 SmoothColorMaterialRhiShader(int viewCount);
20
21 bool updateUniformData(RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override;
22};
23
25{
26 setShaderFileName(VertexStage, QStringLiteral(":/qt-project.org/scenegraph/shaders_ng/smoothcolor.vert.qsb"), viewCount);
27 setShaderFileName(FragmentStage, QStringLiteral(":/qt-project.org/scenegraph/shaders_ng/smoothcolor.frag.qsb"), viewCount);
28}
29
31{
32 bool changed = false;
33 QByteArray *buf = state.uniformData();
34 const int shaderMatrixCount = newMaterial->viewCount();
35 const int matrixCount = qMin(state.projectionMatrixCount(), shaderMatrixCount);
36
37 for (int viewIndex = 0; viewIndex < matrixCount; ++viewIndex) {
38 if (state.isMatrixDirty()) {
39 const QMatrix4x4 m = state.combinedMatrix(viewIndex);
40 memcpy(buf->data() + 64 * viewIndex, m.constData(), 64);
41 changed = true;
42 }
43 }
44
45 if (oldMaterial == nullptr) {
46 // The viewport is constant, so set the pixel size uniform only once.
47 const QRect r = state.viewportRect();
48 const QVector2D v(2.0f / r.width(), 2.0f / r.height());
49 Q_ASSERT(sizeof(v) == 8);
50 memcpy(buf->data() + 64 * shaderMatrixCount, &v, 8);
51 changed = true;
52 }
53
54 if (state.isOpacityDirty()) {
55 const float opacity = state.opacity();
56 memcpy(buf->data() + 64 * shaderMatrixCount + 8, &opacity, 4);
57 changed = true;
58 }
59
60 return changed;
61}
62
63
69
71{
72 // all state in vertex attributes -> all smoothcolor materials are equal
73 return 0;
74}
75
81
87
92
94{
96 setMaterial(&m_smoothMaterial);
97 else
98 setMaterial(&m_material);
99}
100
102{
103 // smoothed material is always blended, so no change in material state
104 if (material() == &m_material) {
105 bool wasBlending = (m_material.flags() & QSGMaterial::Blending);
106 bool isBlending = (m_gradient_stops.size() > 0 && !m_gradient_is_opaque)
107 || (m_color.alpha() < 255 && m_color.alpha() != 0)
108 || (m_pen_width > 0 && m_border_color.alpha() < 255);
109 if (wasBlending != isBlending) {
110 m_material.setFlag(QSGMaterial::Blending, isBlending);
112 }
113 }
114}
115
\inmodule QtCore
Definition qbytearray.h:57
int alpha() const noexcept
Returns the alpha color component of this color.
Definition qcolor.cpp:1466
qsizetype size() const noexcept
Definition qlist.h:397
The QMatrix4x4 class represents a 4x4 transformation matrix in 3D space.
Definition qmatrix4x4.h:25
\inmodule QtCore\reentrant
Definition qrect.h:30
void updateMaterialBlending(QSGNode::DirtyState *state) override
QSGMaterial * material() const
Returns the material of the QSGGeometryNode.
Definition qsgnode.h:194
void setMaterial(QSGMaterial *material)
Sets the material of this geometry node to material.
Definition qsgnode.cpp:927
Encapsulates the current rendering state during a call to QSGMaterialShader::updateUniformData() and ...
The QSGMaterialShader class represents a graphics API independent shader program.
void setShaderFileName(Stage stage, const QString &filename)
Sets the filename for the shader for the specified stage.
The QSGMaterial class encapsulates rendering state for a shader program.
Definition qsgmaterial.h:15
QSGMaterial::Flags flags() const
Returns the material's flags.
Definition qsgmaterial.h:44
int viewCount() const
void setFlag(Flags flags, bool on=true)
Sets the flags flags on this material if on is true; otherwise clears the attribute.
@ RequiresFullMatrixExceptTranslate
Definition qsgmaterial.h:20
@ DirtyMaterial
Definition qsgnode.h:75
RenderMode
\value RenderMode2D Normal 2D rendering \value RenderMode2DNoDepthBuffer Normal 2D rendering with dep...
QSGMaterialType * type() const override
This function is called by the scene graph to query an identifier that is unique to the QSGMaterialSh...
QSGMaterialShader * createShader(QSGRendererInterface::RenderMode renderMode) const override
This function returns a new instance of a the QSGMaterialShader implementation used to render geometr...
int compare(const QSGMaterial *other) const override
Compares this material to other and returns 0 if they are equal; -1 if this material should sort befo...
The QVector2D class represents a vector or vertex in 2D space.
Definition qvectornd.h:31
bool updateUniformData(RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override
This function is called by the scene graph to get the contents of the shader program's uniform buffer...
else opt state
[0]
Combined button and popup list for selecting options.
constexpr const T & qMin(const T &a, const T &b)
Definition qminmax.h:40
GLsizei const GLfloat * v
[13]
const GLfloat * m
GLboolean r
[2]
GLenum GLuint GLenum GLsizei const GLchar * buf
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
#define QStringLiteral(str)
#define Q_UNUSED(x)
The QSGMaterialType class is used as a unique type token in combination with QSGMaterial.