Kirigami2

shadowedborderrectanglematerial.cpp
1/*
2 * SPDX-FileCopyrightText: 2020 Arjen Hiemstra <ahiemstra@heimr.nl>
3 *
4 * SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6
7#include "shadowedborderrectanglematerial.h"
8
9#include <QOpenGLContext>
10
11QSGMaterialType ShadowedBorderRectangleMaterial::staticType;
12
13ShadowedBorderRectangleMaterial::ShadowedBorderRectangleMaterial()
14{
16}
17
18QSGMaterialShader *ShadowedBorderRectangleMaterial::createShader(QSGRendererInterface::RenderMode) const
19{
20 return new ShadowedBorderRectangleShader{shaderType};
21}
22
23QSGMaterialType *ShadowedBorderRectangleMaterial::type() const
24{
25 return &staticType;
26}
27
28int ShadowedBorderRectangleMaterial::compare(const QSGMaterial *other) const
29{
30 auto material = static_cast<const ShadowedBorderRectangleMaterial *>(other);
31
32 auto result = ShadowedRectangleMaterial::compare(other);
33 /* clang-format off */
34 if (result == 0
35 && material->borderColor == borderColor
36 && qFuzzyCompare(material->borderWidth, borderWidth)) { /* clang-format on */
37 return 0;
38 }
39
40 return QSGMaterial::compare(other);
41}
42
43ShadowedBorderRectangleShader::ShadowedBorderRectangleShader(ShadowedRectangleMaterial::ShaderType shaderType)
44 : ShadowedRectangleShader(shaderType)
45{
46 setShader(shaderType, QStringLiteral("shadowedborderrectangle"));
47}
48
49bool ShadowedBorderRectangleShader::updateUniformData(QSGMaterialShader::RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial)
50{
51 bool changed = ShadowedRectangleShader::updateUniformData(state, newMaterial, oldMaterial);
52 QByteArray *buf = state.uniformData();
53 Q_ASSERT(buf->size() >= 160);
54
55 if (!oldMaterial || newMaterial->compare(oldMaterial) != 0) {
56 const auto material = static_cast<ShadowedBorderRectangleMaterial *>(newMaterial);
57 memcpy(buf->data() + 136, &material->borderWidth, 8);
58 float c[4];
59 material->borderColor.getRgbF(&c[0], &c[1], &c[2], &c[3]);
60 memcpy(buf->data() + 144, c, 16);
61 changed = true;
62 }
63
64 return changed;
65}
A material rendering a rectangle with a shadow and a border.
char * data()
qsizetype size() const const
virtual int compare(const QSGMaterial *other) const const
void setFlag(Flags flags, bool on)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:16:21 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.