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(flags: QSGMaterial::Blending, on: true); |
17 | } |
18 | |
19 | QSGMaterialShader *ShadowedTextureMaterial::createShader(QSGRendererInterface::RenderMode) const |
20 | { |
21 | return new ShadowedTextureShader{shaderType}; |
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 | if (material->textureSource == textureSource) { |
36 | return 0; |
37 | } else { |
38 | return (material->textureSource < textureSource) ? 1 : -1; |
39 | } |
40 | } |
41 | |
42 | return QSGMaterial::compare(other); |
43 | } |
44 | |
45 | ShadowedTextureShader::ShadowedTextureShader(ShadowedRectangleMaterial::ShaderType shaderType) |
46 | : ShadowedRectangleShader(shaderType) |
47 | { |
48 | setShader(shaderType, QStringLiteral("shadowedtexture")); |
49 | } |
50 | |
51 | void ShadowedTextureShader::updateSampledImage(QSGMaterialShader::RenderState &state, |
52 | int binding, |
53 | QSGTexture **texture, |
54 | QSGMaterial *newMaterial, |
55 | QSGMaterial *oldMaterial) |
56 | { |
57 | Q_UNUSED(state); |
58 | Q_UNUSED(oldMaterial); |
59 | if (binding == 1) { |
60 | *texture = static_cast<ShadowedTextureMaterial *>(newMaterial)->textureSource; |
61 | } |
62 | } |
63 |