Kirigami2

shadowedtexturenode.cpp
1/*
2 * SPDX-FileCopyrightText: 2020 Arjen Hiemstra <ahiemstra@heimr.nl>
3 *
4 * SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6
7#include "shadowedtexturenode.h"
8
9#include "shadowedbordertexturematerial.h"
10
11template<typename T>
12inline void preprocessTexture(QSGMaterial *material, QSGTextureProvider *provider)
13{
14 auto m = static_cast<T *>(material);
15 // Since we handle texture coordinates differently in the shader, we
16 // need to remove the texture from the atlas for now.
17 if (provider->texture()->isAtlasTexture()) {
18 // Blegh, I have no idea why "removedFromAtlas" doesn't just return
19 // the texture when it's not an atlas.
20 m->textureSource = provider->texture()->removedFromAtlas();
21 } else {
22 m->textureSource = provider->texture();
23 }
24 if (QSGDynamicTexture *dynamic_texture = qobject_cast<QSGDynamicTexture *>(m->textureSource)) {
25 dynamic_texture->updateTexture();
26 }
27}
28
29ShadowedTextureNode::ShadowedTextureNode()
31{
33}
34
35ShadowedTextureNode::~ShadowedTextureNode()
36{
37 QObject::disconnect(m_textureChangeConnectionHandle);
38}
39
40void ShadowedTextureNode::setTextureSource(QSGTextureProvider *source)
41{
42 if (m_textureSource == source) {
43 return;
44 }
45
46 if (m_textureSource) {
47 m_textureSource->disconnect();
48 }
49
50 m_textureSource = source;
51 m_textureChangeConnectionHandle = QObject::connect(m_textureSource.data(), &QSGTextureProvider::textureChanged, [this] {
52 markDirty(QSGNode::DirtyMaterial);
53 });
55}
56
57void ShadowedTextureNode::preprocess()
58{
59 if (m_textureSource && m_material && m_textureSource->texture()) {
60 if (m_material->type() == borderlessMaterialType()) {
61 preprocessTexture<ShadowedTextureMaterial>(m_material, m_textureSource);
62 } else {
63 preprocessTexture<ShadowedBorderTextureMaterial>(m_material, m_textureSource);
64 }
65 }
66}
67
68ShadowedRectangleMaterial *ShadowedTextureNode::createBorderlessMaterial()
69{
70 return new ShadowedTextureMaterial{};
71}
72
73ShadowedBorderRectangleMaterial *ShadowedTextureNode::createBorderMaterial()
74{
75 return new ShadowedBorderTextureMaterial{};
76}
77
78QSGMaterialType *ShadowedTextureNode::borderlessMaterialType()
79{
80 return &ShadowedTextureMaterial::staticType;
81}
82
83QSGMaterialType *ShadowedTextureNode::borderMaterialType()
84{
85 return &ShadowedBorderTextureMaterial::staticType;
86}
A material rendering a rectangle with a shadow and a border.
A material rendering a rectangle with a shadow.
Scene graph node for a shadowed rectangle.
A material rendering a rectangle with a shadow.
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
bool disconnect(const QMetaObject::Connection &connection)
T * data() const const
void markDirty(DirtyState bits)
virtual bool isAtlasTexture() const const
virtual QSGTexture * removedFromAtlas(QRhiResourceUpdateBatch *resourceUpdates) const const
virtual QSGTexture * texture() const const=0
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Dec 27 2024 11:50:16 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.