Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qsgflatcolormaterial.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#include <private/qsgmaterialshader_p.h>
6
8
10{
11public:
13
14 bool updateUniformData(RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override;
15
17};
18
20
22{
23 setShaderFileName(VertexStage, QStringLiteral(":/qt-project.org/scenegraph/shaders_ng/flatcolor.vert.qsb"));
24 setShaderFileName(FragmentStage, QStringLiteral(":/qt-project.org/scenegraph/shaders_ng/flatcolor.frag.qsb"));
25}
26
28 QSGMaterial *newMaterial,
29 QSGMaterial *oldMaterial)
30{
31 Q_ASSERT(!oldMaterial || newMaterial->type() == oldMaterial->type());
32 QSGFlatColorMaterial *oldMat = static_cast<QSGFlatColorMaterial *>(oldMaterial);
33 QSGFlatColorMaterial *mat = static_cast<QSGFlatColorMaterial *>(newMaterial);
34 bool changed = false;
35 QByteArray *buf = state.uniformData();
36
37 if (state.isMatrixDirty()) {
38 const QMatrix4x4 m = state.combinedMatrix();
39 memcpy(buf->data(), m.constData(), 64);
40 changed = true;
41 }
42
43 const QColor &c = mat->color();
44 if (!oldMat || c != oldMat->color() || state.isOpacityDirty()) {
45 float r, g, b, a;
46 c.getRgbF(&r, &g, &b, &a);
47 const float opacity = state.opacity() * a;
48 QVector4D v(r * opacity, g * opacity, b * opacity, opacity);
49 Q_ASSERT(sizeof(v) == 16);
50 memcpy(buf->data() + 64, &v, 16);
51 changed = true;
52 }
53
54 return changed;
55}
56
57
90{
91}
92
108{
109 m_color = color;
110 setFlag(Blending, m_color.alpha() != 0xff);
111}
112
113
114
120{
122}
123
124
125
131{
132 Q_UNUSED(renderMode);
134}
135
136
142{
143 const QSGFlatColorMaterial *flat = static_cast<const QSGFlatColorMaterial *>(other);
144 return m_color.rgba() - flat->color().rgba();
145
146}
147
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...
\inmodule QtCore
Definition qbytearray.h:57
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition qcolor.h:31
QRgb rgba() const noexcept
Returns the RGB value of the color, including its alpha.
Definition qcolor.cpp:1376
int alpha() const noexcept
Returns the alpha color component of this color.
Definition qcolor.cpp:1466
The QMatrix4x4 class represents a 4x4 transformation matrix in 3D space.
Definition qmatrix4x4.h:25
The QSGFlatColorMaterial class provides a convenient way of rendering solid colored geometry in the s...
QSGMaterialType * type() const override
void setColor(const QColor &color)
Sets this flat color material's color to color.
QSGFlatColorMaterial()
Constructs a new flat color material.
QSGMaterialShader * createShader(QSGRendererInterface::RenderMode renderMode) const override
int compare(const QSGMaterial *other) const override
const QColor & color() const
Returns this flat color material's color.
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
virtual QSGMaterialType * type() const =0
This function is called by the scene graph to query an identifier that is unique to the QSGMaterialSh...
void setFlag(Flags flags, bool on=true)
Sets the flags flags on this material if on is true; otherwise clears the attribute.
RenderMode
\value RenderMode2D Normal 2D rendering \value RenderMode2DNoDepthBuffer Normal 2D rendering with dep...
The QVector4D class represents a vector or vertex in 4D space.
Definition qvectornd.h:330
else opt state
[0]
Combined button and popup list for selecting options.
GLboolean GLboolean GLboolean b
GLsizei const GLfloat * v
[13]
const GLfloat * m
GLboolean GLboolean GLboolean GLboolean a
[7]
GLboolean r
[2]
GLenum GLuint GLenum GLsizei const GLchar * buf
GLboolean GLboolean g
const GLubyte * c
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
#define QStringLiteral(str)
#define Q_UNUSED(x)
QSharedPointer< T > other(t)
[5]
The QSGMaterialType class is used as a unique type token in combination with QSGMaterial.