Qt 6.x
The Qt SDK
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:
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"));
27 setShaderFileName(FragmentStage, QStringLiteral(":/qt-project.org/scenegraph/shaders_ng/smoothcolor.frag.qsb"));
28}
29
31{
32 bool changed = false;
33 QByteArray *buf = state.uniformData();
34
35 if (state.isMatrixDirty()) {
36 const QMatrix4x4 m = state.combinedMatrix();
37 memcpy(buf->data(), m.constData(), 64);
38 changed = true;
39 }
40
41 if (oldMaterial == nullptr) {
42 // The viewport is constant, so set the pixel size uniform only once.
43 const QRect r = state.viewportRect();
44 const QVector2D v(2.0f / r.width(), 2.0f / r.height());
45 Q_ASSERT(sizeof(v) == 8);
46 memcpy(buf->data() + 64, &v, 8);
47 changed = true;
48 }
49
50 if (state.isOpacityDirty()) {
51 const float opacity = state.opacity();
52 memcpy(buf->data() + 72, &opacity, 4);
53 changed = true;
54 }
55
56 return changed;
57}
58
59
61{
63 setFlag(Blending, true);
64}
65
67{
68 // all state in vertex attributes -> all smoothcolor materials are equal
69 return 0;
70}
71
73{
74 static QSGMaterialType type;
75 return &type;
76}
77
79{
80 Q_UNUSED(renderMode);
82}
83
85{
86 setMaterial(&m_material);
87}
88
90{
92 setMaterial(&m_smoothMaterial);
93 else
94 setMaterial(&m_material);
95}
96
98{
99 // smoothed material is always blended, so no change in material state
100 if (material() == &m_material) {
101 bool wasBlending = (m_material.flags() & QSGMaterial::Blending);
102 bool isBlending = (m_gradient_stops.size() > 0 && !m_gradient_is_opaque)
103 || (m_color.alpha() < 255 && m_color.alpha() != 0)
104 || (m_pen_width > 0 && m_border_color.alpha() < 255);
105 if (wasBlending != isBlending) {
106 m_material.setFlag(QSGMaterial::Blending, isBlending);
108 }
109 }
110}
111
\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:386
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:197
void setMaterial(QSGMaterial *material)
Sets the material of this geometry node to material.
Definition qsgnode.cpp:925
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:40
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.
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.