summaryrefslogtreecommitdiffstats
path: root/src/render/lights
diff options
context:
space:
mode:
authorLaszlo Agocs <laszlo.agocs@theqtcompany.com>2015-12-04 15:56:24 +0100
committerLaszlo Agocs <laszlo.agocs@theqtcompany.com>2015-12-07 08:04:14 +0000
commit99779070942cf6ff34f7c558fbd256696a993e5d (patch)
tree2360216bd8e81f69008a3097ea603fa9c3a175af /src/render/lights
parentbd58f31f23711acda2462f1c1d05728307e625ca (diff)
Indicate light type
Having a dedicated type field is required not just to make the shaders cleaner but also to avoid incorrect results when lights get moved around in the scene. Currently the shaders rely on the direction uniform to distinguish directional lights from the others, but this cannot work when the elements in the lights uniform array change, potentially leaving type-specific members like direction set when a point light takes the same index. Change-Id: I170e4b471c8cd9b4a23eca49690239c01944b3e6 Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'src/render/lights')
-rw-r--r--src/render/lights/qdirectionallight.cpp3
-rw-r--r--src/render/lights/qlight.cpp25
-rw-r--r--src/render/lights/qlight.h12
-rw-r--r--src/render/lights/qlight_p.h3
-rw-r--r--src/render/lights/qpointlight.cpp3
-rw-r--r--src/render/lights/qspotlight.cpp3
6 files changed, 41 insertions, 8 deletions
diff --git a/src/render/lights/qdirectionallight.cpp b/src/render/lights/qdirectionallight.cpp
index 3a818add1..206b720b0 100644
--- a/src/render/lights/qdirectionallight.cpp
+++ b/src/render/lights/qdirectionallight.cpp
@@ -66,7 +66,8 @@ namespace Qt3DRender {
\internal
*/
QDirectionalLightPrivate::QDirectionalLightPrivate()
- : m_direction(0.0f, -1.0f, 0.0f)
+ : QLightPrivate(QLight::DirectionalLight)
+ , m_direction(0.0f, -1.0f, 0.0f)
{
}
diff --git a/src/render/lights/qlight.cpp b/src/render/lights/qlight.cpp
index eeb6e7463..55fe1415a 100644
--- a/src/render/lights/qlight.cpp
+++ b/src/render/lights/qlight.cpp
@@ -55,15 +55,17 @@ namespace Qt3DRender
\class Qt3DRender::QLightPrivate
\internal
*/
-QLightPrivate::QLightPrivate()
- : m_color(QColor(255, 255, 255))
- , m_intensity(1.0f)
+QLightPrivate::QLightPrivate(QLight::Type type)
+ : m_type(type)
+ , m_color(QColor(255, 255, 255))
+ , m_intensity(1.0f)
{
}
void QLight::copy(const QNode *ref)
{
const QLight *light = static_cast<const QLight*>(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);
@@ -78,7 +80,7 @@ void QLight::copy(const QNode *ref)
* Constructs a new QLight with the given \a parent.
*/
QLight::QLight(Qt3DCore::QNode *parent) :
- QShaderData(*new QLightPrivate, parent)
+ QShaderData(*new QLightPrivate(PointLight), parent)
{
}
@@ -93,6 +95,21 @@ QLight::~QLight()
cleanup();
}
+QLight::Type QLight::type() const
+{
+ Q_D(const QLight);
+ return d->m_type;
+}
+
+void QLight::setType(Type type)
+{
+ Q_D(QLight);
+ if (d->m_type != type) {
+ d->m_type = type;
+ emit typeChanged();
+ }
+}
+
/*!
* \property Qt3DRender::QLight::color
*
diff --git a/src/render/lights/qlight.h b/src/render/lights/qlight.h
index 4ed279e34..d1ce2e463 100644
--- a/src/render/lights/qlight.h
+++ b/src/render/lights/qlight.h
@@ -52,13 +52,24 @@ class QLightPrivate;
class QT3DRENDERSHARED_EXPORT QLight : public QShaderData
{
Q_OBJECT
+ Q_PROPERTY(Type type READ type WRITE setType NOTIFY typeChanged)
Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
Q_PROPERTY(float intensity READ intensity WRITE setIntensity NOTIFY intensityChanged)
public :
+ enum Type {
+ PointLight = 0,
+ DirectionalLight,
+ SpotLight
+ };
+ Q_ENUM(Type)
+
explicit QLight(Qt3DCore::QNode *parent = 0);
~QLight();
+ Type type() const;
+ void setType(Type type);
+
QColor color() const;
void setColor(const QColor &color);
@@ -70,6 +81,7 @@ protected :
void copy(const Qt3DCore::QNode *ref) Q_DECL_OVERRIDE;
Q_SIGNALS:
+ void typeChanged();
void colorChanged();
void intensityChanged();
diff --git a/src/render/lights/qlight_p.h b/src/render/lights/qlight_p.h
index 6f8229505..a66d0fc57 100644
--- a/src/render/lights/qlight_p.h
+++ b/src/render/lights/qlight_p.h
@@ -59,9 +59,10 @@ class QLight;
class QLightPrivate : public QShaderDataPrivate
{
public:
- QLightPrivate();
+ QLightPrivate(QLight::Type type);
Q_DECLARE_PUBLIC(QLight)
+ QLight::Type m_type;
QColor m_color;
float m_intensity;
};
diff --git a/src/render/lights/qpointlight.cpp b/src/render/lights/qpointlight.cpp
index 58ff5b25e..d795a9914 100644
--- a/src/render/lights/qpointlight.cpp
+++ b/src/render/lights/qpointlight.cpp
@@ -63,7 +63,8 @@ namespace Qt3DRender {
\internal
*/
QPointLightPrivate::QPointLightPrivate()
- : m_attenuation(0.0f, 0.0f, 0.002f)
+ : QLightPrivate(QLight::PointLight)
+ , m_attenuation(0.0f, 0.0f, 0.002f)
{
}
diff --git a/src/render/lights/qspotlight.cpp b/src/render/lights/qspotlight.cpp
index b666ef1e1..6b8bf6906 100644
--- a/src/render/lights/qspotlight.cpp
+++ b/src/render/lights/qspotlight.cpp
@@ -67,7 +67,8 @@ namespace Qt3DRender {
\internal
*/
QSpotLightPrivate::QSpotLightPrivate()
- : m_cutOffAngle(45.0f)
+ : QLightPrivate(QLight::SpotLight)
+ , m_cutOffAngle(45.0f)
{
}