diff options
author | Sean Harmer <sean.harmer@kdab.com> | 2015-09-18 16:03:24 +0100 |
---|---|---|
committer | Paul Lemire <paul.lemire@kdab.com> | 2015-10-13 12:13:01 +0000 |
commit | c65de5cc688e09c50a470bc9d303734fd8b9858a (patch) | |
tree | 9145f1d657740dff863629abc66e0a95bdcef80b /src/render/lights | |
parent | 9ecf6ab9f8a59058a1171df47e837f5d2a1a9c1b (diff) |
Move lights into their own directory
Change-Id: I4caecd5072dfc2c0ad11ec2a76f1e6be44d3ce8f
Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
Diffstat (limited to 'src/render/lights')
-rw-r--r-- | src/render/lights/lights.pri | 18 | ||||
-rw-r--r-- | src/render/lights/qabstractlight.cpp | 160 | ||||
-rw-r--r-- | src/render/lights/qabstractlight.h | 91 | ||||
-rw-r--r-- | src/render/lights/qabstractlight_p.h | 64 | ||||
-rw-r--r-- | src/render/lights/qdirectionallight.cpp | 110 | ||||
-rw-r--r-- | src/render/lights/qdirectionallight.h | 75 | ||||
-rw-r--r-- | src/render/lights/qdirectionallight_p.h | 61 | ||||
-rw-r--r-- | src/render/lights/qpointlight.cpp | 103 | ||||
-rw-r--r-- | src/render/lights/qpointlight.h | 65 | ||||
-rw-r--r-- | src/render/lights/qpointlight_p.h | 60 | ||||
-rw-r--r-- | src/render/lights/qspotlight.cpp | 173 | ||||
-rw-r--r-- | src/render/lights/qspotlight.h | 80 | ||||
-rw-r--r-- | src/render/lights/qspotlight_p.h | 60 |
13 files changed, 1120 insertions, 0 deletions
diff --git a/src/render/lights/lights.pri b/src/render/lights/lights.pri new file mode 100644 index 000000000..e12428e9d --- /dev/null +++ b/src/render/lights/lights.pri @@ -0,0 +1,18 @@ +INCLUDEPATH += $$PWD + +HEADERS += \ + $$PWD/qabstractlight.h \ + $$PWD/qabstractlight_p.h \ + $$PWD/qdirectionallight.h \ + $$PWD/qdirectionallight_p.h \ + $$PWD/qpointlight.h \ + $$PWD/qpointlight_p.h \ + $$PWD/qspotlight.h \ + $$PWD/qspotlight_p.h + + +SOURCES += \ + $$PWD/qabstractlight.cpp \ + $$PWD/qdirectionallight.cpp \ + $$PWD/qpointlight.cpp \ + $$PWD/qspotlight.cpp diff --git a/src/render/lights/qabstractlight.cpp b/src/render/lights/qabstractlight.cpp new file mode 100644 index 000000000..82e1826be --- /dev/null +++ b/src/render/lights/qabstractlight.cpp @@ -0,0 +1,160 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qabstractlight.h" +#include "qabstractlight_p.h" + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender +{ + +/*! + * \qmltype QAbstractLight + * \instantiates QAbstractLight + * \brief Encapsulate a QAbstractLight object in a Qt3D scene. + * \since 5.3 + */ + + +/*! + \class Qt3D::QAbstractLightPrivate + \internal +*/ +QAbstractLightPrivate::QAbstractLightPrivate() + : QShaderDataPrivate() + , m_color(QColor(255, 255, 255)) + , m_intensity(1.0f) +{} + +void QAbstractLight::copy(const QNode *ref) +{ + const QAbstractLight *light = static_cast<const QAbstractLight*>(ref); + d_func()->m_color = light->d_func()->m_color; + d_func()->m_intensity = light->d_func()->m_intensity; + // This needs to be last otherwise, properties value won't be copied + // as we use shader introspection in QShaderData::copy + QShaderData::copy(ref); +} + +/*! + \class Qt3D::QAbstractLight + \inmodule Qt3DRender +*/ + +/*! + * Constructs a new QAbstractLight with the given \a parent. + */ +QAbstractLight::QAbstractLight(Qt3D::QNode *parent) : + QShaderData(*new QAbstractLightPrivate, parent) +{ +} + +/*! \internal */ +QAbstractLight::QAbstractLight(QAbstractLightPrivate &dd, QNode *parent) + : QShaderData(dd, parent) +{ +} + + +/*! + * \property Qt3D::QAbstractLight::color + * + * Holds the current QAbstractLight color. + */ +QColor QAbstractLight::color() const +{ + Q_D(const QAbstractLight); + return d->m_color; +} + +void QAbstractLight::setColor(const QColor &color) +{ + Q_D(QAbstractLight); + if (d->m_color != color) { + d->m_color = color; + emit colorChanged(); + } +} + +/*! + \property Qt3D::QAbstractLight::intensity + + Holds the current QAbstractLight intensity. +*/ +float QAbstractLight::intensity() const +{ + Q_D(const QAbstractLight); + return d->m_intensity; +} + +void QAbstractLight::setIntensity(float intensity) +{ + Q_D(QAbstractLight); + if (d->m_intensity != intensity) { + d->m_intensity = intensity; + emit intensityChanged(); + } +} + +/*! + \property Qt3D::QAbstractLight::position + + Holds the current QAbstractLight position. +*/ +void QAbstractLight::setPosition(const QVector3D &position) +{ + Q_D(QAbstractLight); + if (d->m_position != position) { + d->m_position = position; + emit positionChanged(); + } +} + +QVector3D QAbstractLight::position() const +{ + Q_D(const QAbstractLight); + return d->m_position; +} + +QShaderData::TransformType QAbstractLight::positionTransformed() const +{ + return QShaderData::ModelToEye; +} + +} // namespace Qt3DRender + +QT_END_NAMESPACE diff --git a/src/render/lights/qabstractlight.h b/src/render/lights/qabstractlight.h new file mode 100644 index 000000000..6f30fe955 --- /dev/null +++ b/src/render/lights/qabstractlight.h @@ -0,0 +1,91 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QT3DRENDER_QABSTRACTLIGHT_H +#define QT3DRENDER_QABSTRACTLIGHT_H + +#include <Qt3DRenderer/qshaderdata.h> +#include <Qt3DRenderer/qt3drenderer_global.h> + +#include <QVector3D> +#include <QColor> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class QAbstractLightPrivate; + +class QT3DRENDERERSHARED_EXPORT QAbstractLight : public QShaderData +{ + Q_OBJECT + Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) + Q_PROPERTY(float intensity READ intensity WRITE setIntensity NOTIFY intensityChanged) + Q_PROPERTY(QVector3D position READ position WRITE setPosition NOTIFY positionChanged) + Q_PROPERTY(TransformType positionTransformed READ positionTransformed CONSTANT) + +public : + explicit QAbstractLight(Qt3D::QNode *parent = 0); + + QColor color() const; + void setColor(const QColor &color); + + float intensity() const; + void setIntensity(float intensity); + + void setPosition(const QVector3D &position); + QVector3D position() const; + + TransformType positionTransformed() const; + +protected : + QAbstractLight(QAbstractLightPrivate &dd, Qt3D::QNode *parent = 0); + void copy(const Qt3D::QNode *ref) Q_DECL_OVERRIDE; + +Q_SIGNALS: + void colorChanged(); + void intensityChanged(); + void positionChanged(); + +private: + Q_DECLARE_PRIVATE(QAbstractLight) +}; + +} // namespace Qt3DRender + +QT_END_NAMESPACE + +#endif // QT3DRENDER_LIGHT_H diff --git a/src/render/lights/qabstractlight_p.h b/src/render/lights/qabstractlight_p.h new file mode 100644 index 000000000..9d70d4bb9 --- /dev/null +++ b/src/render/lights/qabstractlight_p.h @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QT3DRENDER_QABSTRACTLIGHT_P_H +#define QT3DRENDER_QABSTRACTLIGHT_P_H + +#include <Qt3DRenderer/qt3drenderer_global.h> +#include <private/qshaderdata_p.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class QAbstractLight; + +class QT3DRENDERERSHARED_EXPORT QAbstractLightPrivate : public QShaderDataPrivate +{ +public: + QAbstractLightPrivate(); + + Q_DECLARE_PUBLIC(QAbstractLight) + QColor m_color; + float m_intensity; + QVector3D m_position; +}; + +} + +QT_END_NAMESPACE + +#endif // QT3DRENDER_QABSTRACTLIGHT_P_H diff --git a/src/render/lights/qdirectionallight.cpp b/src/render/lights/qdirectionallight.cpp new file mode 100644 index 000000000..ebdc1e170 --- /dev/null +++ b/src/render/lights/qdirectionallight.cpp @@ -0,0 +1,110 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qdirectionallight.h" +#include "qdirectionallight_p.h" +#include <Qt3DCore/qscenepropertychange.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +/*! + * + * Expected Shader struct + * + * \code + * + * struct DirectionalLight + * { + * vec3 position; + * vec3 direction; + * vec4 color; + * float intensity; + * }; + * + * uniform DirectionalLight directionalLights[10]; + * + * \endcode + */ + +/*! + \class Qt3D::QDirectionalLightPrivate + \internal +*/ +QDirectionalLightPrivate::QDirectionalLightPrivate() + : QAbstractLightPrivate() +{ +} + +void QDirectionalLight::copy(const QNode *ref) +{ + const QDirectionalLight *light = static_cast<const QDirectionalLight*>(ref); + d_func()->m_direction = light->d_func()->m_direction; + // This needs to be last otherwise, properties value won't be copied + // as we use shader introspection in QShaderData::copy + QAbstractLight::copy(ref); +} + +QDirectionalLight::QDirectionalLight(QNode *parent) + : QAbstractLight(*new QDirectionalLightPrivate, parent) +{ +} + +/*! \internal */ +QDirectionalLight::QDirectionalLight(QDirectionalLightPrivate &dd, QNode *parent) + : QAbstractLight(dd, parent) +{ +} + +void QDirectionalLight::setDirection(const QVector3D &direction) +{ + Q_D(QDirectionalLight); + if (direction != d->m_direction) { + d->m_direction = direction; + emit directionChanged(); + } +} + +QVector3D QDirectionalLight::direction() const +{ + Q_D(const QDirectionalLight); + return d->m_direction; +} + +} // namespace Qt3DRender + +QT_END_NAMESPACE diff --git a/src/render/lights/qdirectionallight.h b/src/render/lights/qdirectionallight.h new file mode 100644 index 000000000..f626d4f6a --- /dev/null +++ b/src/render/lights/qdirectionallight.h @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QT3DRENDER_QDIRECTIONALLIGHT_H +#define QT3DRENDER_QDIRECTIONALLIGHT_H + +#include <Qt3DRenderer/qabstractlight.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class QDirectionalLightPrivate; + +class QT3DRENDERERSHARED_EXPORT QDirectionalLight : public QAbstractLight +{ + Q_OBJECT + Q_PROPERTY(QVector3D direction READ direction WRITE setDirection NOTIFY directionChanged) + +public: + explicit QDirectionalLight(Qt3D::QNode *parent = 0); + + void setDirection(const QVector3D &direction); + QVector3D direction() const; + +Q_SIGNALS: + void directionChanged(); + +protected: + QDirectionalLight(QDirectionalLightPrivate &dd, Qt3D::QNode *parent = 0); + void copy(const Qt3D::QNode *ref) Q_DECL_OVERRIDE; + +private: + Q_DECLARE_PRIVATE(QDirectionalLight) + QT3D_CLONEABLE(QDirectionalLight) +}; + +} // namespace Qt3DRender + +QT_END_NAMESPACE + +#endif // QT3DRENDER_QDIRECTIONALLIGHT_H diff --git a/src/render/lights/qdirectionallight_p.h b/src/render/lights/qdirectionallight_p.h new file mode 100644 index 000000000..4cff5e192 --- /dev/null +++ b/src/render/lights/qdirectionallight_p.h @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QT3DRENDER_QDIRECTIONALLIGHT_P_H +#define QT3DRENDER_QDIRECTIONALLIGHT_P_H + +#include <private/qabstractlight_p.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class QDirectionalLight; + +class QT3DRENDERERSHARED_EXPORT QDirectionalLightPrivate : QAbstractLightPrivate +{ +public: + QDirectionalLightPrivate(); + + Q_DECLARE_PUBLIC(QDirectionalLight) + QVector3D m_direction; +}; + +} // namespace Qt3DRender + +QT_END_NAMESPACE + +#endif // QT3DRENDER_QDIRECTIONALLIGHT_P_H diff --git a/src/render/lights/qpointlight.cpp b/src/render/lights/qpointlight.cpp new file mode 100644 index 000000000..94653ee41 --- /dev/null +++ b/src/render/lights/qpointlight.cpp @@ -0,0 +1,103 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qpointlight.h" +#include "qpointlight_p.h" + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +/* + Expected Shader struct + + \code + + struct PointLight + { + vec3 position; + vec4 color; + float intensity; + }; + + uniform PointLight pointLights[10]; + + \endcode + */ + +/*! + \class Qt3DRender::QPointLightPrivate + \internal +*/ +QPointLightPrivate::QPointLightPrivate() + : QAbstractLightPrivate() +{ +} + +/*! + \class QPointLight + \inmodule Qt3DRenderer + \since 5.5 + + */ + +/*! + \qmltype PointLight + \instantiates Qt3DRender::QPointLight + \inherits AbstractLight + \inqmlmodule Qt3D.Renderer + \since 5.5 + \brief For OpenGL ... +*/ + +/*! + \fn Qt3DRender::QPointLight::QPointLight(QNode *parent) + Constructs a new QPointLight with the specified \a parent. + */ +QPointLight::QPointLight(QNode *parent) + : QAbstractLight(*new QPointLightPrivate, parent) +{ +} + +/*! \internal */ +QPointLight::QPointLight(QPointLightPrivate &dd, QNode *parent) + : QAbstractLight(dd, parent) +{ +} + +} // namespace Qt3DRender + +QT_END_NAMESPACE diff --git a/src/render/lights/qpointlight.h b/src/render/lights/qpointlight.h new file mode 100644 index 000000000..076f8b3cd --- /dev/null +++ b/src/render/lights/qpointlight.h @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QT3DRENDER_QPOINTLIGHT_H +#define QT3DRENDER_QPOINTLIGHT_H + +#include <Qt3DRenderer/qabstractlight.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class QPointLightPrivate; + +class QT3DRENDERERSHARED_EXPORT QPointLight : public QAbstractLight +{ + Q_OBJECT + +public: + explicit QPointLight(Qt3D::QNode *parent = 0); + +protected: + Q_DECLARE_PRIVATE(QPointLight) + QPointLight(QPointLightPrivate &dd, Qt3D::QNode *parent); + QT3D_CLONEABLE(QPointLight) +}; + +} // namespace Qt3DRender + +QT_END_NAMESPACE + +#endif // QT3DRENDER_QPOINTLIGHT_H diff --git a/src/render/lights/qpointlight_p.h b/src/render/lights/qpointlight_p.h new file mode 100644 index 000000000..f39daabee --- /dev/null +++ b/src/render/lights/qpointlight_p.h @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QT3DRENDER_QPOINTLIGHT_P_H +#define QT3DRENDER_QPOINTLIGHT_P_H + +#include <private/qabstractlight_p.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class QPointLight; + +class QT3DRENDERERSHARED_EXPORT QPointLightPrivate : public QAbstractLightPrivate +{ +public: + QPointLightPrivate(); + + Q_DECLARE_PUBLIC(QPointLight) +}; + +} // namespace Qt3DRender + +QT_END_NAMESPACE + +#endif // QPOINTLIGHT_P_H diff --git a/src/render/lights/qspotlight.cpp b/src/render/lights/qspotlight.cpp new file mode 100644 index 000000000..191be0e62 --- /dev/null +++ b/src/render/lights/qspotlight.cpp @@ -0,0 +1,173 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qspotlight.h" +#include "qspotlight_p.h" +#include <Qt3DCore/qscenepropertychange.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + + +/* + Expected Shader struct + + \code + + struct SpotLight + { + vec3 position; + vec3 direction; + vec4 color; + float intensity; + float cutOffAngle; + }; + + uniform SpotLight spotLights[10]; + + \endcode + */ + +/*! + \class Qt3D::QSpotLightPrivate + \internal +*/ +QSpotLightPrivate::QSpotLightPrivate() + : QAbstractLightPrivate() + , m_cutOffAngle(45.0f) +{ +} + +/*! + \class QSpotLight + \inmodule Qt3DRenderer + \since 5.5 + + */ + +/*! + \qmltype SpotLight + \instantiates Qt3D::QSpotLight + \inherits AbstractLight + \inqmlmodule Qt3D.Renderer + \since 5.5 + \brief For OpenGL ... +*/ + +/*! \fn void Qt3D::QSpotLight::copy(const QNode *ref) + Copies the \a ref instance into this one. + */ + +void QSpotLight::copy(const QNode *ref) +{ + const QSpotLight *light = static_cast<const QSpotLight*>(ref); + d_func()->m_direction = light->d_func()->m_direction; + d_func()->m_cutOffAngle = light->d_func()->m_cutOffAngle; + // This needs to be last otherwise, properties value won't be copied + // as we use shader introspection in QShaderData::copy + QAbstractLight::copy(ref); +} + + +/*! + \fn Qt3D::QSpotLight::QSpotLight(QNode *parent) + Constructs a new QSpotLight with the specified \a parent. + */ +QSpotLight::QSpotLight(QNode *parent) + : QAbstractLight(*new QSpotLightPrivate, parent) +{ +} + +/*! \internal */ +QSpotLight::QSpotLight(QSpotLightPrivate &dd, QNode *parent) + : QAbstractLight(dd, parent) +{ +} + +/*! + \qmlproperty vector3d Qt3D.Renderer::SpotLight::direction + +*/ + +/*! + \property Qt3D::QSpotLight::direction + + */ + + QVector3D QSpotLight::direction() const +{ + Q_D(const QSpotLight); + return d->m_direction; +} + + +/*! + \qmlproperty float Qt3D.Renderer::SpotLight::cutOffAngle + +*/ + +/*! + \property Qt3D::QSpotLight::cutOffAngle + + */ +float QSpotLight::cutOffAngle() const +{ + Q_D(const QSpotLight); + return d->m_cutOffAngle; +} + +void QSpotLight::setDirection(const QVector3D &direction) +{ + Q_D(QSpotLight); + if (direction != d->m_direction) { + d->m_direction = direction; + emit directionChanged(); + } +} + +void QSpotLight::setCutOffAngle(float cutOffAngle) +{ + Q_D(QSpotLight); + if (d->m_cutOffAngle != cutOffAngle) { + d->m_cutOffAngle = cutOffAngle; + emit cutOffAngleChanged(); + } +} + +} // namespace Qt3DRender + +QT_END_NAMESPACE diff --git a/src/render/lights/qspotlight.h b/src/render/lights/qspotlight.h new file mode 100644 index 000000000..c22ef62e5 --- /dev/null +++ b/src/render/lights/qspotlight.h @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QT3DRENDER_QSPOTLIGHT_H +#define QT3DRENDER_QSPOTLIGHT_H + +#include <Qt3DRenderer/qabstractlight.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class QSpotLightPrivate; + +class QT3DRENDERERSHARED_EXPORT QSpotLight : public QAbstractLight +{ + Q_OBJECT + Q_PROPERTY(QVector3D direction READ direction WRITE setDirection NOTIFY directionChanged) + Q_PROPERTY(float cutOffAngle READ cutOffAngle WRITE setCutOffAngle NOTIFY cutOffAngleChanged) + +public: + explicit QSpotLight(Qt3D::QNode *parent = 0); + + QVector3D direction() const; + float cutOffAngle() const; + + void setDirection(const QVector3D &direction); + void setCutOffAngle(float cutOffAngle); + +Q_SIGNALS: + void directionChanged(); + void cutOffAngleChanged(); + +protected: + QSpotLight(QSpotLightPrivate &dd, Qt3D::QNode *parent = 0); + void copy(const Qt3D::QNode *ref) Q_DECL_OVERRIDE; + +private: + Q_DECLARE_PRIVATE(QSpotLight) + QT3D_CLONEABLE(QSpotLight) +}; + +} // namespace Qt3DRender + +QT_END_NAMESPACE + +#endif // QT3DRENDER_QSPOTLIGHT_H diff --git a/src/render/lights/qspotlight_p.h b/src/render/lights/qspotlight_p.h new file mode 100644 index 000000000..673438a33 --- /dev/null +++ b/src/render/lights/qspotlight_p.h @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QT3DRENDER_QSPOTLIGHT_P_H +#define QT3DRENDER_QSPOTLIGHT_P_H + +#include <private/qabstractlight_p.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class QT3DRENDERERSHARED_EXPORT QSpotLightPrivate : public QAbstractLightPrivate +{ +public: + QSpotLightPrivate(); + + Q_DECLARE_PUBLIC(QSpotLight) + float m_cutOffAngle; + QVector3D m_direction; +}; + +} // namespace Qt3DRender + +QT_END_NAMESPACE + +#endif // QT3DRENDER_QSPOTLIGHT_P_H |