File indexing completed on 2024-05-12 15:42:39
0001 /* 0002 * SPDX-FileCopyrightText: 2020 Arjen Hiemstra <ahiemstra@heimr.nl> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "shadowedbordertexturematerial.h" 0008 0009 #include <QOpenGLContext> 0010 0011 QSGMaterialType ShadowedBorderTextureMaterial::staticType; 0012 0013 ShadowedBorderTextureMaterial::ShadowedBorderTextureMaterial() 0014 : ShadowedBorderRectangleMaterial() 0015 { 0016 setFlag(QSGMaterial::Blending, true); 0017 } 0018 0019 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) 0020 QSGMaterialShader *ShadowedBorderTextureMaterial::createShader() const 0021 #else 0022 QSGMaterialShader *ShadowedBorderTextureMaterial::createShader(QSGRendererInterface::RenderMode) const 0023 #endif 0024 { 0025 return new ShadowedBorderTextureShader{shaderType}; 0026 } 0027 0028 QSGMaterialType *ShadowedBorderTextureMaterial::type() const 0029 { 0030 return &staticType; 0031 } 0032 0033 int ShadowedBorderTextureMaterial::compare(const QSGMaterial *other) const 0034 { 0035 auto material = static_cast<const ShadowedBorderTextureMaterial *>(other); 0036 0037 auto result = ShadowedBorderRectangleMaterial::compare(other); 0038 if (result == 0) { 0039 if (material->textureSource == textureSource) { 0040 return 0; 0041 } else { 0042 return (material->textureSource < textureSource) ? 1 : -1; 0043 } 0044 } 0045 0046 return QSGMaterial::compare(other); 0047 } 0048 0049 ShadowedBorderTextureShader::ShadowedBorderTextureShader(ShadowedRectangleMaterial::ShaderType shaderType) 0050 : ShadowedBorderRectangleShader(shaderType) 0051 { 0052 setShader(shaderType, QStringLiteral("shadowedbordertexture")); 0053 } 0054 0055 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) 0056 void ShadowedBorderTextureShader::initialize() 0057 { 0058 ShadowedBorderRectangleShader::initialize(); 0059 program()->setUniformValue("textureSource", 0); 0060 } 0061 0062 void ShadowedBorderTextureShader::updateState(const QSGMaterialShader::RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) 0063 { 0064 ShadowedBorderRectangleShader::updateState(state, newMaterial, oldMaterial); 0065 0066 auto texture = static_cast<ShadowedBorderTextureMaterial *>(newMaterial)->textureSource; 0067 if (texture) { 0068 texture->bind(); 0069 } 0070 } 0071 #else 0072 void ShadowedBorderTextureShader::updateSampledImage(QSGMaterialShader::RenderState &state, 0073 int binding, 0074 QSGTexture **texture, 0075 QSGMaterial *newMaterial, 0076 QSGMaterial *oldMaterial) 0077 { 0078 Q_UNUSED(state); 0079 Q_UNUSED(oldMaterial); 0080 if (binding == 1) { 0081 *texture = static_cast<ShadowedBorderTextureMaterial *>(newMaterial)->textureSource; 0082 } 0083 } 0084 #endif