Changeset View
Changeset View
Standalone View
Standalone View
src/scenegraph/shadowedtexturematerial.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 "shadowedtexturematerial.h" | ||||
8 | | ||||
9 | #include <QOpenGLContext> | ||||
10 | | ||||
11 | QSGMaterialType ShadowedTextureMaterial::staticType; | ||||
12 | | ||||
13 | ShadowedTextureMaterial::ShadowedTextureMaterial() | ||||
14 | : ShadowedRectangleMaterial() | ||||
15 | { | ||||
16 | setFlag(QSGMaterial::Blending, true); | ||||
17 | } | ||||
18 | | ||||
19 | QSGMaterialShader* ShadowedTextureMaterial::createShader() const | ||||
20 | { | ||||
21 | return new ShadowedTextureShader{}; | ||||
22 | } | ||||
23 | | ||||
24 | QSGMaterialType* ShadowedTextureMaterial::type() const | ||||
25 | { | ||||
26 | return &staticType; | ||||
27 | } | ||||
28 | | ||||
29 | int ShadowedTextureMaterial::compare(const QSGMaterial *other) const | ||||
30 | { | ||||
31 | auto material = static_cast<const ShadowedTextureMaterial *>(other); | ||||
32 | | ||||
33 | auto result = ShadowedRectangleMaterial::compare(other); | ||||
34 | if (result == 0 | ||||
35 | && material->textureSource == textureSource) { | ||||
36 | return 0; | ||||
37 | } | ||||
38 | | ||||
39 | return result; | ||||
40 | } | ||||
41 | | ||||
42 | ShadowedTextureShader::ShadowedTextureShader() | ||||
43 | { | ||||
44 | auto header = QOpenGLContext::currentContext()->isOpenGLES() ? QStringLiteral("header_es.glsl") : QStringLiteral("header_desktop.glsl"); | ||||
45 | | ||||
46 | auto shaderRoot = QStringLiteral(":/org/kde/kirigami/shaders/"); | ||||
47 | | ||||
48 | setShaderSourceFiles(QOpenGLShader::Vertex, { | ||||
49 | shaderRoot + header, | ||||
50 | shaderRoot + QStringLiteral("shadowedrectangle.vert") | ||||
51 | }); | ||||
52 | | ||||
53 | setShaderSourceFiles(QOpenGLShader::Fragment, { | ||||
54 | shaderRoot + header, | ||||
55 | shaderRoot + QStringLiteral("sdf.glsl"), | ||||
56 | shaderRoot + QStringLiteral("shadowedtexture.frag") | ||||
57 | }); | ||||
58 | } | ||||
59 | | ||||
60 | void ShadowedTextureShader::initialize() | ||||
61 | { | ||||
62 | ShadowedRectangleShader::initialize(); | ||||
63 | program()->setUniformValue("textureSource", 0); | ||||
64 | } | ||||
65 | | ||||
66 | void ShadowedTextureShader::updateState(const QSGMaterialShader::RenderState& state, QSGMaterial* newMaterial, QSGMaterial* oldMaterial) | ||||
67 | { | ||||
68 | ShadowedRectangleShader::updateState(state, newMaterial, oldMaterial); | ||||
69 | | ||||
70 | auto texture = static_cast<ShadowedTextureMaterial*>(newMaterial)->textureSource; | ||||
71 | if (texture) { | ||||
72 | texture->bind(); | ||||
73 | } | ||||
74 | } |