Changeset View
Changeset View
Standalone View
Standalone View
src/scenegraph/shadowedborderrectanglematerial.cpp
- This file was added.
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(QSGMaterial::Blending, true); | ||||
16 | } | ||||
17 | | ||||
18 | QSGMaterialShader* ShadowedBorderRectangleMaterial::createShader() const | ||||
19 | { | ||||
20 | return new ShadowedBorderRectangleShader{}; | ||||
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 | if (result == 0 | ||||
34 | && material->borderColor == borderColor | ||||
35 | && qFuzzyCompare(material->borderWidth, borderWidth) | ||||
36 | ) { | ||||
37 | return 0; | ||||
38 | } | ||||
39 | | ||||
40 | return result; | ||||
41 | } | ||||
42 | | ||||
43 | ShadowedBorderRectangleShader::ShadowedBorderRectangleShader() | ||||
44 | { | ||||
45 | auto header = QOpenGLContext::currentContext()->isOpenGLES() ? QStringLiteral("header_es.glsl") : QStringLiteral("header_desktop.glsl"); | ||||
46 | | ||||
47 | auto shaderRoot = QStringLiteral(":/org/kde/kirigami/shaders/"); | ||||
48 | | ||||
49 | setShaderSourceFiles(QOpenGLShader::Fragment, { | ||||
50 | shaderRoot + header, | ||||
51 | shaderRoot + QStringLiteral("shadowedborderrectangle.frag") | ||||
52 | }); | ||||
53 | } | ||||
54 | | ||||
55 | void ShadowedBorderRectangleShader::initialize() | ||||
56 | { | ||||
57 | ShadowedRectangleShader::initialize(); | ||||
58 | m_borderWidthLocation = program()->uniformLocation("borderWidth"); | ||||
59 | m_borderColorLocation = program()->uniformLocation("borderColor"); | ||||
60 | } | ||||
61 | | ||||
62 | void ShadowedBorderRectangleShader::updateState(const QSGMaterialShader::RenderState& state, QSGMaterial* newMaterial, QSGMaterial* oldMaterial) | ||||
63 | { | ||||
64 | ShadowedRectangleShader::updateState(state, newMaterial, oldMaterial); | ||||
65 | | ||||
66 | auto p = program(); | ||||
67 | | ||||
68 | if (!oldMaterial || newMaterial->compare(oldMaterial) != 0 || state.isCachedMaterialDataDirty()) { | ||||
69 | auto material = static_cast<ShadowedBorderRectangleMaterial *>(newMaterial); | ||||
70 | p->setUniformValue(m_borderWidthLocation, material->borderWidth); | ||||
71 | p->setUniformValue(m_borderColorLocation, material->borderColor); | ||||
72 | } | ||||
73 | } |