summaryrefslogtreecommitdiffstats
path: root/src/render/lights
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
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')
-rw-r--r--src/render/lights/light.cpp23
-rw-r--r--src/render/lights/light_p.h11
-rw-r--r--src/render/lights/qabstractlight.cpp42
-rw-r--r--src/render/lights/qabstractlight.h5
-rw-r--r--src/render/lights/qabstractlight_p.h13
-rw-r--r--src/render/lights/qdirectionallight.cpp16
-rw-r--r--src/render/lights/qdirectionallight_p.h1
-rw-r--r--src/render/lights/qpointlight.cpp28
-rw-r--r--src/render/lights/qpointlight_p.h6
-rw-r--r--src/render/lights/qspotlight.cpp51
-rw-r--r--src/render/lights/qspotlight_p.h7
11 files changed, 113 insertions, 90 deletions
diff --git a/src/render/lights/light.cpp b/src/render/lights/light.cpp
index 8485ad48e..87a0553bb 100644
--- a/src/render/lights/light.cpp
+++ b/src/render/lights/light.cpp
@@ -39,6 +39,7 @@
#include "light_p.h"
#include "qabstractlight.h"
+#include "qabstractlight_p.h"
#include <Qt3DCore/qnodepropertychange.h>
#include <private/abstractrenderer_p.h>
#include <private/nodemanagers_p.h>
@@ -52,6 +53,26 @@ using namespace Qt3DCore;
namespace Qt3DRender {
namespace Render {
+void Light::updateFromPeer(QNode *node)
+{
+ QAbstractLight *light = static_cast<QAbstractLight *>(node);
+ QShaderData *shaderData = light->findChild<QShaderData *>();
+ if (shaderData != Q_NULLPTR)
+ m_shaderDataId = shaderData->id();
+}
+
+QNodeId Light::shaderData() const
+{
+ return m_shaderDataId;
+}
+
+void Light::initializeFromPeer(const QNodeCreatedChangeBasePtr &change)
+{
+ const auto typedChange = qSharedPointerCast<Qt3DCore::QNodeCreatedChange<QAbstractLightData>>(change);
+ const auto &data = typedChange->data;
+ m_shaderDataId = data.shaderDataId;
+}
+
RenderLightFunctor::RenderLightFunctor(AbstractRenderer *renderer, NodeManagers *managers)
: m_managers(managers)
, m_renderer(renderer)
@@ -61,7 +82,6 @@ RenderLightFunctor::RenderLightFunctor(AbstractRenderer *renderer, NodeManagers
Qt3DCore::QBackendNode *RenderLightFunctor::create(Qt3DCore::QNode *frontend) const
{
Light *backend = m_managers->lightManager()->getOrCreateResource(frontend->id());
- backend->setManagers(m_managers);
backend->setPeer(frontend);
backend->setRenderer(m_renderer);
return backend;
@@ -70,7 +90,6 @@ Qt3DCore::QBackendNode *RenderLightFunctor::create(Qt3DCore::QNode *frontend) co
Qt3DCore::QBackendNode *RenderLightFunctor::create(const Qt3DCore::QNodeCreatedChangeBasePtr &change) const
{
Light *backend = m_managers->lightManager()->getOrCreateResource(change->subjectId());
- backend->setManagers(m_managers);
backend->setRenderer(m_renderer);
return backend;
}
diff --git a/src/render/lights/light_p.h b/src/render/lights/light_p.h
index 3a3789079..05c94c2dc 100644
--- a/src/render/lights/light_p.h
+++ b/src/render/lights/light_p.h
@@ -51,7 +51,7 @@
// We mean it.
//
-#include <Qt3DRender/private/shaderdata_p.h>
+#include <Qt3DRender/private/backendnode_p.h>
QT_BEGIN_NAMESPACE
@@ -61,10 +61,17 @@ namespace Render {
class NodeManagers;
-class Q_AUTOTEST_EXPORT Light : public ShaderData
+class Q_AUTOTEST_EXPORT Light : public BackendNode
{
public:
+ void updateFromPeer(Qt3DCore::QNode *node) Q_DECL_OVERRIDE;
+ Qt3DCore::QNodeId shaderData() const;
+
+private:
+ void initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change) Q_DECL_FINAL;
+
+ Qt3DCore::QNodeId m_shaderDataId;
};
class RenderLightFunctor : public Qt3DCore::QBackendNodeMapper
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);
}
}
diff --git a/src/render/lights/qabstractlight.h b/src/render/lights/qabstractlight.h
index c94ce0af7..0a8593066 100644
--- a/src/render/lights/qabstractlight.h
+++ b/src/render/lights/qabstractlight.h
@@ -41,7 +41,7 @@
#define QT3DRENDER_QABSTRACTLIGHT_H
#include <Qt3DRender/qt3drender_global.h>
-#include <Qt3DRender/qshaderdata.h>
+#include <Qt3DCore/qcomponent.h>
#include <QVector3D>
#include <QColor>
@@ -52,7 +52,7 @@ namespace Qt3DRender {
class QAbstractLightPrivate;
-class QT3DRENDERSHARED_EXPORT QAbstractLight : public QShaderData
+class QT3DRENDERSHARED_EXPORT QAbstractLight : public Qt3DCore::QComponent
{
Q_OBJECT
Q_PROPERTY(Type type READ type)
@@ -85,6 +85,7 @@ Q_SIGNALS:
private:
Q_DECLARE_PRIVATE(QAbstractLight)
+ Qt3DCore::QNodeCreatedChangeBasePtr createNodeCreationChange() const Q_DECL_OVERRIDE;
};
} // namespace Qt3DRender
diff --git a/src/render/lights/qabstractlight_p.h b/src/render/lights/qabstractlight_p.h
index d605951ac..a903f43f6 100644
--- a/src/render/lights/qabstractlight_p.h
+++ b/src/render/lights/qabstractlight_p.h
@@ -51,7 +51,8 @@
// We mean it.
//
-#include <private/qshaderdata_p.h>
+#include <private/qcomponent_p.h>
+#include <qshaderdata.h>
QT_BEGIN_NAMESPACE
@@ -59,15 +60,19 @@ namespace Qt3DRender {
class QAbstractLight;
-class Q_AUTOTEST_EXPORT QAbstractLightPrivate : public QShaderDataPrivate
+class Q_AUTOTEST_EXPORT QAbstractLightPrivate : public Qt3DCore::QComponentPrivate
{
public:
QAbstractLightPrivate(QAbstractLight::Type type);
Q_DECLARE_PUBLIC(QAbstractLight)
QAbstractLight::Type m_type;
- QColor m_color;
- float m_intensity;
+ QShaderData *m_shaderData;
+};
+
+struct QAbstractLightData
+{
+ Qt3DCore::QNodeId shaderDataId;
};
}
diff --git a/src/render/lights/qdirectionallight.cpp b/src/render/lights/qdirectionallight.cpp
index ff1ca1a8d..0d7dcbcfb 100644
--- a/src/render/lights/qdirectionallight.cpp
+++ b/src/render/lights/qdirectionallight.cpp
@@ -66,16 +66,12 @@ namespace Qt3DRender {
QDirectionalLightPrivate::QDirectionalLightPrivate()
: QAbstractLightPrivate(QAbstractLight::DirectionalLight)
- , m_worldDirection(0.0f, -1.0f, 0.0f)
{
+ m_shaderData->setProperty("worldDirection", QVector3D(0.0f, -1.0f, 0.0f));
}
void QDirectionalLight::copy(const QNode *ref)
{
- const QDirectionalLight *light = static_cast<const QDirectionalLight*>(ref);
- d_func()->m_worldDirection = light->d_func()->m_worldDirection;
- // This needs to be last otherwise, properties value won't be copied
- // as we use shader introspection in QShaderData::copy
QAbstractLight::copy(ref);
}
@@ -90,19 +86,19 @@ QDirectionalLight::QDirectionalLight(QDirectionalLightPrivate &dd, QNode *parent
{
}
-void QDirectionalLight::setWorldDirection(const QVector3D &worldDirection)
+void QDirectionalLight::setWorldDirection(const QVector3D &direction)
{
Q_D(QDirectionalLight);
- if (worldDirection != d->m_worldDirection) {
- d->m_worldDirection = worldDirection;
- emit worldDirectionChanged(worldDirection);
+ if (worldDirection() != direction) {
+ d->m_shaderData->setProperty("worldDirection", direction);
+ emit worldDirectionChanged(direction);
}
}
QVector3D QDirectionalLight::worldDirection() const
{
Q_D(const QDirectionalLight);
- return d->m_worldDirection;
+ return d->m_shaderData->property("worldDirection").value<QVector3D>();
}
} // namespace Qt3DRender
diff --git a/src/render/lights/qdirectionallight_p.h b/src/render/lights/qdirectionallight_p.h
index b560e4348..bc815ce30 100644
--- a/src/render/lights/qdirectionallight_p.h
+++ b/src/render/lights/qdirectionallight_p.h
@@ -65,7 +65,6 @@ public:
QDirectionalLightPrivate();
Q_DECLARE_PUBLIC(QDirectionalLight)
- QVector3D m_worldDirection;
};
} // namespace Qt3DRender
diff --git a/src/render/lights/qpointlight.cpp b/src/render/lights/qpointlight.cpp
index 86455be84..b62980d34 100644
--- a/src/render/lights/qpointlight.cpp
+++ b/src/render/lights/qpointlight.cpp
@@ -61,12 +61,12 @@ namespace Qt3DRender {
\endcode
*/
-QPointLightPrivate::QPointLightPrivate(QAbstractLight::Type type)
- : QAbstractLightPrivate(type)
- , m_constantAttenuation(0.0f)
- , m_linearAttenuation(0.0f)
- , m_quadraticAttenuation(0.0f)
+QPointLightPrivate::QPointLightPrivate()
+ : QAbstractLightPrivate(QAbstractLight::PointLight)
{
+ m_shaderData->setProperty("constantAttenuation", 0.0f);
+ m_shaderData->setProperty("linearAttenuation", 0.0f);
+ m_shaderData->setProperty("quadraticAttenuation", 0.0f);
}
/*!
@@ -103,14 +103,14 @@ QPointLight::QPointLight(QPointLightPrivate &dd, QNode *parent)
float QPointLight::constantAttenuation() const
{
Q_D(const QPointLight);
- return d->m_constantAttenuation;
+ return d->m_shaderData->property("constantAttenuation").toFloat();
}
void QPointLight::setConstantAttenuation(float value)
{
Q_D(QPointLight);
- if (d->m_constantAttenuation != value) {
- d->m_constantAttenuation = value;
+ if (constantAttenuation() != value) {
+ d->m_shaderData->setProperty("constantAttenuation", value);
emit constantAttenuationChanged(value);
}
}
@@ -118,14 +118,14 @@ void QPointLight::setConstantAttenuation(float value)
float QPointLight::linearAttenuation() const
{
Q_D(const QPointLight);
- return d->m_linearAttenuation;
+ return d->m_shaderData->property("linearAttenuation").toFloat();
}
void QPointLight::setLinearAttenuation(float value)
{
Q_D(QPointLight);
- if (d->m_linearAttenuation != value) {
- d->m_linearAttenuation = value;
+ if (linearAttenuation() != value) {
+ d->m_shaderData->setProperty("linearAttenuation", value);
emit linearAttenuationChanged(value);
}
}
@@ -133,14 +133,14 @@ void QPointLight::setLinearAttenuation(float value)
float QPointLight::quadraticAttenuation() const
{
Q_D(const QPointLight);
- return d->m_quadraticAttenuation;
+ return d->m_shaderData->property("quadraticAttenuation").toFloat();
}
void QPointLight::setQuadraticAttenuation(float value)
{
Q_D(QPointLight);
- if (d->m_quadraticAttenuation != value) {
- d->m_quadraticAttenuation = value;
+ if (quadraticAttenuation() != value) {
+ d->m_shaderData->setProperty("quadraticAttenuation", value);
emit quadraticAttenuationChanged(value);
}
}
diff --git a/src/render/lights/qpointlight_p.h b/src/render/lights/qpointlight_p.h
index 1a08b1d0c..978627fb7 100644
--- a/src/render/lights/qpointlight_p.h
+++ b/src/render/lights/qpointlight_p.h
@@ -62,11 +62,7 @@ class QPointLight;
class QPointLightPrivate : public QAbstractLightPrivate
{
public:
- QPointLightPrivate(QAbstractLight::Type type = QAbstractLight::PointLight);
-
- float m_constantAttenuation;
- float m_linearAttenuation;
- float m_quadraticAttenuation;
+ QPointLightPrivate();
Q_DECLARE_PUBLIC(QPointLight)
};
diff --git a/src/render/lights/qspotlight.cpp b/src/render/lights/qspotlight.cpp
index b62e81a55..b70edfb18 100644
--- a/src/render/lights/qspotlight.cpp
+++ b/src/render/lights/qspotlight.cpp
@@ -67,12 +67,12 @@ namespace Qt3DRender {
QSpotLightPrivate::QSpotLightPrivate()
: QAbstractLightPrivate(QAbstractLight::SpotLight)
- , m_constantAttenuation(0.0f)
- , m_linearAttenuation(0.0f)
- , m_quadraticAttenuation(0.0f)
- , m_localDirection(0.0f, -1.0f, 0.0f)
- , m_cutOffAngle(45.0f)
{
+ m_shaderData->setProperty("constantAttenuation", 0.0f);
+ m_shaderData->setProperty("linearAttenuation", 0.0f);
+ m_shaderData->setProperty("quadraticAttenuation", 0.0f);
+ m_shaderData->setProperty("localDirection", QVector3D(0.0f, -1.0f, 0.0f));
+ m_shaderData->setProperty("cutOffAngle", 45.0f);
}
/*!
@@ -97,9 +97,6 @@ QSpotLightPrivate::QSpotLightPrivate()
void QSpotLight::copy(const QNode *ref)
{
- const QSpotLight *light = static_cast<const QSpotLight*>(ref);
- d_func()->m_localDirection = light->d_func()->m_localDirection;
- d_func()->m_cutOffAngle = light->d_func()->m_cutOffAngle;
QAbstractLight::copy(ref);
}
@@ -132,14 +129,14 @@ QSpotLight::QSpotLight(QSpotLightPrivate &dd, QNode *parent)
float QSpotLight::constantAttenuation() const
{
Q_D(const QSpotLight);
- return d->m_constantAttenuation;
+ return d->m_shaderData->property("constantAttenuation").toFloat();
}
void QSpotLight::setConstantAttenuation(float value)
{
Q_D(QSpotLight);
- if (d->m_constantAttenuation != value) {
- d->m_constantAttenuation = value;
+ if (constantAttenuation() != value) {
+ d->m_shaderData->setProperty("constantAttenuation", value);
emit constantAttenuationChanged(value);
}
}
@@ -147,14 +144,14 @@ void QSpotLight::setConstantAttenuation(float value)
float QSpotLight::linearAttenuation() const
{
Q_D(const QSpotLight);
- return d->m_linearAttenuation;
+ return d->m_shaderData->property("linearAttenuation").toFloat();
}
void QSpotLight::setLinearAttenuation(float value)
{
Q_D(QSpotLight);
- if (d->m_linearAttenuation != value) {
- d->m_linearAttenuation = value;
+ if (linearAttenuation() != value) {
+ d->m_shaderData->setProperty("linearAttenuation", value);
emit linearAttenuationChanged(value);
}
}
@@ -162,14 +159,14 @@ void QSpotLight::setLinearAttenuation(float value)
float QSpotLight::quadraticAttenuation() const
{
Q_D(const QSpotLight);
- return d->m_quadraticAttenuation;
+ return d->m_shaderData->property("quadraticAttenuation").toFloat();
}
void QSpotLight::setQuadraticAttenuation(float value)
{
Q_D(QSpotLight);
- if (d->m_quadraticAttenuation != value) {
- d->m_quadraticAttenuation = value;
+ if (quadraticAttenuation() != value) {
+ d->m_shaderData->setProperty("quadraticAttenuation", value);
emit quadraticAttenuationChanged(value);
}
}
@@ -177,7 +174,7 @@ void QSpotLight::setQuadraticAttenuation(float value)
QVector3D QSpotLight::localDirection() const
{
Q_D(const QSpotLight);
- return d->m_localDirection;
+ return d->m_shaderData->property("localDirection").value<QVector3D>();
}
@@ -193,24 +190,24 @@ QVector3D QSpotLight::localDirection() const
float QSpotLight::cutOffAngle() const
{
Q_D(const QSpotLight);
- return d->m_cutOffAngle;
+ return d->m_shaderData->property("cutOffAngle").toFloat();
}
-void QSpotLight::setLocalDirection(const QVector3D &localDirection)
+void QSpotLight::setLocalDirection(const QVector3D &direction)
{
Q_D(QSpotLight);
- if (localDirection != d->m_localDirection) {
- d->m_localDirection = localDirection;
- emit localDirectionChanged(localDirection);
+ if (localDirection() != direction) {
+ d->m_shaderData->setProperty("localDirection", direction);
+ emit localDirectionChanged(direction);
}
}
-void QSpotLight::setCutOffAngle(float cutOffAngle)
+void QSpotLight::setCutOffAngle(float value)
{
Q_D(QSpotLight);
- if (d->m_cutOffAngle != cutOffAngle) {
- d->m_cutOffAngle = cutOffAngle;
- emit cutOffAngleChanged(cutOffAngle);
+ if (cutOffAngle() != value) {
+ d->m_shaderData->setProperty("cutOffAngle", value);
+ emit cutOffAngleChanged(value);
}
}
diff --git a/src/render/lights/qspotlight_p.h b/src/render/lights/qspotlight_p.h
index 19a132b34..0bb0cb80f 100644
--- a/src/render/lights/qspotlight_p.h
+++ b/src/render/lights/qspotlight_p.h
@@ -64,14 +64,7 @@ class QSpotLightPrivate : public QAbstractLightPrivate
public:
QSpotLightPrivate();
- float m_constantAttenuation;
- float m_linearAttenuation;
- float m_quadraticAttenuation;
- QVector3D m_localDirection;
- float m_cutOffAngle;
-
Q_DECLARE_PUBLIC(QSpotLight)
-
};
} // namespace Qt3DRender