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
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:
12 FlatColorMaterialRhiShader(int viewCount);
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"), viewCount);
24 setShaderFileName(FragmentStage, QStringLiteral(":/qt-project.org/scenegraph/shaders_ng/flatcolor.frag.qsb"), viewCount);
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 const int shaderMatrixCount = newMaterial->viewCount();
37 const int matrixCount = qMin(state.projectionMatrixCount(), shaderMatrixCount);
38
39 for (int viewIndex = 0; viewIndex < matrixCount; ++viewIndex) {
40 if (state.isMatrixDirty()) {
41 const QMatrix4x4 m = state.combinedMatrix(viewIndex);
42 memcpy(buf->data() + 64 * viewIndex, m.constData(), 64);
43 changed = true;
44 }
45 }
46
47 const QColor &c = mat->color();
48 if (!oldMat || c != oldMat->color() || state.isOpacityDirty()) {
49 float r, g, b, a;
50 c.getRgbF(&r, &g, &b, &a);
51 const float opacity = state.opacity() * a;
52 QVector4D v(r * opacity, g * opacity, b * opacity, opacity);
53 Q_ASSERT(sizeof(v) == 16);
54 memcpy(buf->data() + 64 * shaderMatrixCount, &v, 16);
55 changed = true;
56 }
57
58 return changed;
59}
60
61
94{
95}
96
112{
113 m_color = color;
114 setFlag(Blending, m_color.alpha() != 0xff);
115}
116
117
118
127
128
129
139
140
146{
147 const QSGFlatColorMaterial *flat = static_cast<const QSGFlatColorMaterial *>(other);
148 return m_color.rgba() - flat->color().rgba();
149
150}
151
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
void getRgbF(float *r, float *g, float *b, float *a=nullptr) const
Sets the contents pointed to by r, g, b, and a, to the red, green, blue, and alpha-channel (transpare...
Definition qcolor.cpp:1252
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
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.
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.
constexpr const T & qMin(const T &a, const T &b)
Definition qminmax.h:40
GLboolean GLboolean GLboolean b
GLsizei const GLfloat * v
[13]
const GLfloat * m
GLboolean GLboolean GLboolean GLboolean a
[7]
GLboolean r
[2]
GLuint color
[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.