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 | |
11 | QSGMaterialType ShadowedBorderRectangleMaterial::staticType; |
12 | |
13 | ShadowedBorderRectangleMaterial::ShadowedBorderRectangleMaterial() |
14 | { |
15 | setFlag(flags: QSGMaterial::Blending, on: true); |
16 | } |
17 | |
18 | QSGMaterialShader *ShadowedBorderRectangleMaterial::createShader(QSGRendererInterface::RenderMode) const |
19 | { |
20 | return new ShadowedBorderRectangleShader{shaderType}; |
21 | } |
22 | |
23 | QSGMaterialType *ShadowedBorderRectangleMaterial::type() const |
24 | { |
25 | return &staticType; |
26 | } |
27 | |
28 | int 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(p1: material->borderWidth, p2: borderWidth)) { /* clang-format on */ |
37 | return 0; |
38 | } |
39 | |
40 | return QSGMaterial::compare(other); |
41 | } |
42 | |
43 | ShadowedBorderRectangleShader::ShadowedBorderRectangleShader(ShadowedRectangleMaterial::ShaderType shaderType) |
44 | : ShadowedRectangleShader(shaderType) |
45 | { |
46 | setShader(shaderType, QStringLiteral("shadowedborderrectangle" )); |
47 | } |
48 | |
49 | bool 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(other: oldMaterial) != 0) { |
56 | const auto material = static_cast<ShadowedBorderRectangleMaterial *>(newMaterial); |
57 | memcpy(dest: buf->data() + 136, src: &material->borderWidth, n: 8); |
58 | float c[4]; |
59 | material->borderColor.getRgbF(r: &c[0], g: &c[1], b: &c[2], a: &c[3]); |
60 | memcpy(dest: buf->data() + 144, src: c, n: 16); |
61 | changed = true; |
62 | } |
63 | |
64 | return changed; |
65 | } |
66 | |