1// Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qshaderdata.h"
5#include "qshaderdata_p.h"
6
7QT_BEGIN_NAMESPACE
8
9namespace Qt3DRender {
10
11PropertyReaderInterface::~PropertyReaderInterface()
12{
13}
14
15QShaderDataPrivate::QShaderDataPrivate()
16 : QComponentPrivate()
17 , m_propertyReader(PropertyReaderInterfacePtr(new QShaderDataPropertyReader()))
18{
19}
20
21QShaderDataPrivate::QShaderDataPrivate(PropertyReaderInterfacePtr reader)
22 : QComponentPrivate()
23 , m_propertyReader(reader)
24{
25}
26
27/*!
28 * \class Qt3DRender::QShaderData
29 * \inheaderfile Qt3DRender/QShaderData
30 * \inmodule Qt3DRender
31 *
32 * \brief Provides a way of specifying values of a Uniform Block or a shader
33 * structure.
34 *
35 * \note When subclassing and adding properties to QShaderData, note that if
36 * you need to nest an inner Qt3DRender::QShaderData, the data type of the
37 * property should be Qt3DRender::QShaderData* instead of the name of your
38 * subclass.
39 *
40 * \since 5.5
41 */
42
43/*!
44 \fn Qt3DRender::PropertyReaderInterface::readProperty(const QVariant &v)
45 \return the property identified by \a v.
46 */
47
48/*!
49 * Constructs a new QShaderData with the specified \a parent.
50 */
51QShaderData::QShaderData(QNode *parent)
52 : QComponent(*new QShaderDataPrivate, parent)
53{
54}
55
56/*! \internal */
57QShaderData::~QShaderData()
58{
59}
60/*!
61 * \brief QShaderData::propertyReader
62 * Returns the PropertyReaderInterfacePtr for this shader data
63 */
64PropertyReaderInterfacePtr QShaderData::propertyReader() const
65{
66 Q_D(const QShaderData);
67 return d->m_propertyReader;
68}
69
70/*! \internal */
71QShaderData::QShaderData(QShaderDataPrivate &dd, QNode *parent)
72 : QComponent(dd, parent)
73{
74}
75
76/*! \internal */
77bool QShaderData::event(QEvent *event)
78{
79 Q_D(QShaderData);
80
81 if (event->type() == QEvent::DynamicPropertyChange) {
82 auto e = static_cast<QDynamicPropertyChangeEvent*>(event);
83 const auto propertyName = e->propertyName();
84
85 const QVariant data = property(name: propertyName);
86 if (data.canConvert<Qt3DCore::QNode*>()) {
87 const auto node = data.value<Qt3DCore::QNode*>();
88 const auto id = node ? node->id() : Qt3DCore::QNodeId();
89 d->notifyDynamicPropertyChange(name: propertyName, value: QVariant::fromValue(value: id));
90 } else {
91 d->notifyDynamicPropertyChange(name: propertyName, value: data);
92 }
93 }
94
95 return QComponent::event(event);
96}
97
98} // namespace Qt3DRender
99
100QT_END_NAMESPACE
101
102#include "moc_qshaderdata.cpp"
103

source code of qt3d/src/render/materialsystem/qshaderdata.cpp