summaryrefslogtreecommitdiffstats
path: root/src/render/lights/qabstractlight.cpp
diff options
context:
space:
mode:
authorKevin Ottens <kevin.ottens@kdab.com>2016-04-27 12:39:15 +0200
committerSean Harmer <sean.harmer@kdab.com>2016-04-28 11:28:56 +0000
commit42bc3d429a470ec678948a19da1af5a67fe0080c (patch)
treeadf2a31505fc9f45ff0385e24490645fc7b82acc /src/render/lights/qabstractlight.cpp
parent665afce109016328ce3702a9d116e250b250f6ef (diff)
QAbstractLight now inherits directly QComponent
We are turning the relationship between QAbstractLight and QShaderData from a "is-a" to a "has-a". For that we relay all the properties of the light to its internal shader data dynamic properties. Interestingly it also removes a couple of special handling for lights which aren't needed anymore. Change-Id: Ia937b8934f94ce318e02901d90ac340e172cbc75 Task-number: QTBUG-51489 Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'src/render/lights/qabstractlight.cpp')
-rw-r--r--src/render/lights/qabstractlight.cpp42
1 files changed, 26 insertions, 16 deletions
diff --git a/src/render/lights/qabstractlight.cpp b/src/render/lights/qabstractlight.cpp
index 87aa6a633..1b4f3c199 100644
--- a/src/render/lights/qabstractlight.cpp
+++ b/src/render/lights/qabstractlight.cpp
@@ -56,18 +56,26 @@ namespace Qt3DRender
QAbstractLightPrivate::QAbstractLightPrivate(QAbstractLight::Type type)
: m_type(type)
- , m_color(QColor(255, 255, 255))
- , m_intensity(1.0f)
+ , m_shaderData(new QShaderData)
{
+ m_shaderData->setProperty("type", type);
}
void QAbstractLight::copy(const QNode *ref)
{
const QAbstractLight *light = static_cast<const QAbstractLight*>(ref);
d_func()->m_type = light->d_func()->m_type;
- d_func()->m_color = light->d_func()->m_color;
- d_func()->m_intensity = light->d_func()->m_intensity;
- QShaderData::copy(ref);
+ d_func()->m_shaderData = qobject_cast<QShaderData *>(QNode::clone(light->d_func()->m_shaderData));
+ QComponent::copy(ref);
+}
+
+Qt3DCore::QNodeCreatedChangeBasePtr QAbstractLight::createNodeCreationChange() const
+{
+ auto creationChange = Qt3DCore::QNodeCreatedChangePtr<QAbstractLightData>::create(this);
+ auto &data = creationChange->data;
+ Q_D(const QAbstractLight);
+ data.shaderDataId = qIdForNode(d->m_shaderData);
+ return creationChange;
}
/*!
@@ -77,8 +85,10 @@ void QAbstractLight::copy(const QNode *ref)
/*! \internal */
QAbstractLight::QAbstractLight(QAbstractLightPrivate &dd, QNode *parent)
- : QShaderData(dd, parent)
+ : QComponent(dd, parent)
{
+ Q_D(QAbstractLight);
+ d->m_shaderData->setParent(this);
}
QAbstractLight::Type QAbstractLight::type() const
@@ -95,15 +105,15 @@ QAbstractLight::Type QAbstractLight::type() const
QColor QAbstractLight::color() const
{
Q_D(const QAbstractLight);
- return d->m_color;
+ return d->m_shaderData->property("color").value<QColor>();
}
-void QAbstractLight::setColor(const QColor &color)
+void QAbstractLight::setColor(const QColor &c)
{
Q_D(QAbstractLight);
- if (d->m_color != color) {
- d->m_color = color;
- emit colorChanged(color);
+ if (color() != c) {
+ d->m_shaderData->setProperty("color", c);
+ emit colorChanged(c);
}
}
@@ -115,15 +125,15 @@ void QAbstractLight::setColor(const QColor &color)
float QAbstractLight::intensity() const
{
Q_D(const QAbstractLight);
- return d->m_intensity;
+ return d->m_shaderData->property("intensity").toFloat();
}
-void QAbstractLight::setIntensity(float intensity)
+void QAbstractLight::setIntensity(float value)
{
Q_D(QAbstractLight);
- if (d->m_intensity != intensity) {
- d->m_intensity = intensity;
- emit intensityChanged(intensity);
+ if (intensity() != value) {
+ d->m_shaderData->setProperty("intensity", value);
+ emit intensityChanged(value);
}
}