File indexing completed on 2024-04-28 03:56:00
0001 /* 0002 * SPDX-FileCopyrightText: 2020 Arjen Hiemstra <ahiemstra@heimr.nl> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "shadowedtexturematerial.h" 0008 0009 #include <QOpenGLContext> 0010 0011 QSGMaterialType ShadowedTextureMaterial::staticType; 0012 0013 ShadowedTextureMaterial::ShadowedTextureMaterial() 0014 : ShadowedRectangleMaterial() 0015 { 0016 setFlag(QSGMaterial::Blending, true); 0017 } 0018 0019 QSGMaterialShader *ShadowedTextureMaterial::createShader(QSGRendererInterface::RenderMode) const 0020 { 0021 return new ShadowedTextureShader{shaderType}; 0022 } 0023 0024 QSGMaterialType *ShadowedTextureMaterial::type() const 0025 { 0026 return &staticType; 0027 } 0028 0029 int ShadowedTextureMaterial::compare(const QSGMaterial *other) const 0030 { 0031 auto material = static_cast<const ShadowedTextureMaterial *>(other); 0032 0033 auto result = ShadowedRectangleMaterial::compare(other); 0034 if (result == 0) { 0035 if (material->textureSource == textureSource) { 0036 return 0; 0037 } else { 0038 return (material->textureSource < textureSource) ? 1 : -1; 0039 } 0040 } 0041 0042 return QSGMaterial::compare(other); 0043 } 0044 0045 ShadowedTextureShader::ShadowedTextureShader(ShadowedRectangleMaterial::ShaderType shaderType) 0046 : ShadowedRectangleShader(shaderType) 0047 { 0048 setShader(shaderType, QStringLiteral("shadowedtexture")); 0049 } 0050 0051 void ShadowedTextureShader::updateSampledImage(QSGMaterialShader::RenderState &state, 0052 int binding, 0053 QSGTexture **texture, 0054 QSGMaterial *newMaterial, 0055 QSGMaterial *oldMaterial) 0056 { 0057 Q_UNUSED(state); 0058 Q_UNUSED(oldMaterial); 0059 if (binding == 1) { 0060 *texture = static_cast<ShadowedTextureMaterial *>(newMaterial)->textureSource; 0061 } 0062 }