Kirigami2

shadowedtexturematerial.cpp
1 /*
2  * SPDX-FileCopyrightText: 2020 Arjen Hiemstra <[email protected]>
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()
15 {
17 }
18 
19 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
21 #else
22 QSGMaterialShader *ShadowedTextureMaterial::createShader(QSGRendererInterface::RenderMode) const
23 #endif
24 {
25  return new ShadowedTextureShader{shaderType};
26 }
27 
28 QSGMaterialType *ShadowedTextureMaterial::type() const
29 {
30  return &staticType;
31 }
32 
33 int ShadowedTextureMaterial::compare(const QSGMaterial *other) const
34 {
35  auto material = static_cast<const ShadowedTextureMaterial *>(other);
36 
37  auto result = ShadowedRectangleMaterial::compare(other);
38  if (result == 0) {
39  if (material->textureSource == textureSource) {
40  return 0;
41  } else {
42  return (material->textureSource < textureSource) ? 1 : -1;
43  }
44  }
45 
46  return result;
47 }
48 
49 ShadowedTextureShader::ShadowedTextureShader(ShadowedRectangleMaterial::ShaderType shaderType)
50  : ShadowedRectangleShader(shaderType)
51 {
52  setShader(shaderType, QStringLiteral("shadowedtexture"));
53 }
54 
55 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
57 {
59  program()->setUniformValue("textureSource", 0);
60 }
61 
63 {
64  ShadowedRectangleShader::updateState(state, newMaterial, oldMaterial);
65 
66  auto texture = static_cast<ShadowedTextureMaterial *>(newMaterial)->textureSource;
67  if (texture) {
68  texture->bind();
69  }
70 }
71 #else
72 void ShadowedTextureShader::updateSampledImage(QSGMaterialShader::RenderState &state,
73  int binding,
74  QSGTexture **texture,
75  QSGMaterial *newMaterial,
76  QSGMaterial *oldMaterial)
77 {
78  Q_UNUSED(state);
79  Q_UNUSED(oldMaterial);
80  if (binding == 1) {
81  *texture = static_cast<ShadowedTextureMaterial *>(newMaterial)->textureSource;
82  }
83 }
84 #endif
void setFlag(QQuickItem::Flag flag, bool enabled)
virtual void initialize()
A material rendering a rectangle with a shadow.
virtual QSGMaterialShader * createShader() const const=0
virtual void updateState(const QSGMaterialShader::RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial)
A material rendering a rectangle with a shadow.
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Sun Jan 29 2023 04:11:03 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.