summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Lemire <paul.lemire@kdab.com>2015-05-01 23:54:18 +0200
committerSean Harmer <sean.harmer@kdab.com>2015-05-10 15:27:13 +0000
commit325e0323aefa0b45400a58e8a6883126ecdc4722 (patch)
treeed4d4dc9ca81bd83a17fb02d342f00e9acb65c42
parent477751038d35542657d2179627fc8bced84b12d9 (diff)
QSkyboxEntity default added
C++ equivalent of SkyboxEntity Change-Id: I560b6f5f19660370fb9f3e3edfb596879cf17382 Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
-rw-r--r--src/render/defaults/defaults.pri7
-rw-r--r--src/render/defaults/qskyboxentity.cpp284
-rw-r--r--src/render/defaults/qskyboxentity.h78
-rw-r--r--src/render/defaults/qskyboxentity_p.h100
4 files changed, 467 insertions, 2 deletions
diff --git a/src/render/defaults/defaults.pri b/src/render/defaults/defaults.pri
index 9657f3a88..fb2c04a08 100644
--- a/src/render/defaults/defaults.pri
+++ b/src/render/defaults/defaults.pri
@@ -16,7 +16,9 @@ HEADERS += \
$$PWD/qforwardrenderer.h \
$$PWD/qforwardrenderer_p.h \
$$PWD/qpervertexcolormaterial.h \
- $$PWD/qpervertexcolormaterial_p.h
+ $$PWD/qpervertexcolormaterial_p.h \
+ $$PWD/qskyboxentity.h \
+ $$PWD/qskyboxentity_p.h
SOURCES += \
$$PWD/qphongmaterial.cpp \
@@ -26,4 +28,5 @@ SOURCES += \
$$PWD/qnormaldiffusemapalphamaterial.cpp \
$$PWD/qdiffusespecularmapmaterial.cpp \
$$PWD/qforwardrenderer.cpp \
- $$PWD/qpervertexcolormaterial.cpp
+ $$PWD/qpervertexcolormaterial.cpp \
+ $$PWD/qskyboxentity.cpp
diff --git a/src/render/defaults/qskyboxentity.cpp b/src/render/defaults/qskyboxentity.cpp
new file mode 100644
index 000000000..40655a822
--- /dev/null
+++ b/src/render/defaults/qskyboxentity.cpp
@@ -0,0 +1,284 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 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 "qskyboxentity.h"
+#include "qskyboxentity_p.h"
+
+#include <Qt3DCore/qtransform.h>
+#include <Qt3DRenderer/qeffect.h>
+#include <Qt3DRenderer/qtexture.h>
+#include <Qt3DRenderer/qmaterial.h>
+#include <Qt3DRenderer/qcullface.h>
+#include <Qt3DRenderer/qdepthtest.h>
+#include <Qt3DRenderer/qparameter.h>
+#include <Qt3DRenderer/qtechnique.h>
+#include <Qt3DRenderer/qcuboidmesh.h>
+#include <Qt3DRenderer/qrenderpass.h>
+#include <Qt3DRenderer/qopenglfilter.h>
+#include <Qt3DRenderer/qshaderprogram.h>
+#include <Qt3DCore/qtranslatetransform.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3D {
+
+
+/*!
+ * \class Qt3D::QSkyboxEntityPrivate
+ * \internal
+ */
+QSkyboxEntityPrivate::QSkyboxEntityPrivate(QSkyboxEntity *skyboxEntity)
+ : QEntityPrivate(skyboxEntity)
+ , m_effect(new QEffect())
+ , m_material(new QMaterial())
+ , m_skyboxTexture(new QTextureCubeMap())
+ , m_gl3Shader(new QShaderProgram())
+ , m_gl2es2Shader(new QShaderProgram())
+ , m_gl2Technique(new QTechnique())
+ , m_es2Technique(new QTechnique())
+ , m_gl3Technique(new QTechnique())
+ , m_gl2RenderPass(new QRenderPass())
+ , m_es2RenderPass(new QRenderPass())
+ , m_gl3RenderPass(new QRenderPass())
+ , m_mesh(new QCuboidMesh())
+ , m_transform(new QTransform())
+ , m_translate(new QTranslateTransform())
+ , m_textureParameter(new QParameter(QStringLiteral("skyboxTexture"), m_skyboxTexture))
+ , m_posXImage(new QTextureImage())
+ , m_posYImage(new QTextureImage())
+ , m_posZImage(new QTextureImage())
+ , m_negXImage(new QTextureImage())
+ , m_negYImage(new QTextureImage())
+ , m_negZImage(new QTextureImage())
+ , m_extension(QStringLiteral(".png"))
+{
+}
+
+/*!
+ * \internal
+ */
+void QSkyboxEntityPrivate::init()
+{
+ m_gl3Shader->setVertexShaderCode(QShaderProgram::loadSource(QUrl(QStringLiteral("qrc:/shaders/gl3/skybox.vert"))));
+ m_gl3Shader->setFragmentShaderCode(QShaderProgram::loadSource(QUrl(QStringLiteral("qrc:/shaders/gl3/skybox.frag"))));
+ m_gl2es2Shader->setVertexShaderCode(QShaderProgram::loadSource(QUrl(QStringLiteral("qrc:/shaders/es2/skybox.vert"))));
+ m_gl2es2Shader->setFragmentShaderCode(QShaderProgram::loadSource(QUrl(QStringLiteral("qrc:/shaders/es2/skybox.frag"))));
+
+ m_gl3Technique->openGLFilter()->setApi(QOpenGLFilter::Desktop);
+ m_gl3Technique->openGLFilter()->setMajorVersion(3);
+ m_gl3Technique->openGLFilter()->setMajorVersion(1);
+ m_gl3Technique->openGLFilter()->setProfile(QOpenGLFilter::Core);
+
+ m_gl2Technique->openGLFilter()->setApi(QOpenGLFilter::Desktop);
+ m_gl2Technique->openGLFilter()->setMajorVersion(2);
+ m_gl2Technique->openGLFilter()->setMajorVersion(0);
+ m_gl2Technique->openGLFilter()->setProfile(QOpenGLFilter::None);
+
+ m_es2Technique->openGLFilter()->setApi(QOpenGLFilter::ES);
+ m_es2Technique->openGLFilter()->setMajorVersion(2);
+ m_es2Technique->openGLFilter()->setMajorVersion(0);
+ m_es2Technique->openGLFilter()->setProfile(QOpenGLFilter::None);
+
+ m_gl3RenderPass->setShaderProgram(m_gl3Shader);
+ m_gl2RenderPass->setShaderProgram(m_gl2es2Shader);
+ m_es2RenderPass->setShaderProgram(m_gl2es2Shader);
+
+ QCullFace *cullFront = new QCullFace();
+ cullFront->setMode(QCullFace::Front);
+ QDepthTest *depthTest = new QDepthTest();
+ depthTest->setFunc(QDepthTest::LessOrEqual);
+
+ m_gl3RenderPass->addRenderState(cullFront);
+ m_gl3RenderPass->addRenderState(depthTest);
+ m_gl2RenderPass->addRenderState(cullFront);
+ m_gl2RenderPass->addRenderState(depthTest);
+ m_es2RenderPass->addRenderState(cullFront);
+ m_es2RenderPass->addRenderState(depthTest);
+
+ m_gl3Technique->addPass(m_gl3RenderPass);
+ m_gl2Technique->addPass(m_gl2RenderPass);
+ m_es2Technique->addPass(m_es2RenderPass);
+
+ m_effect->addTechnique(m_gl3Technique);
+ m_effect->addTechnique(m_gl2Technique);
+ m_effect->addTechnique(m_es2Technique);
+
+ m_material->setEffect(m_effect);
+ m_material->addParameter(m_textureParameter);
+
+ m_transform->addTransform(m_translate);
+
+ m_mesh->setXYMeshResolution(QSize(2, 2));
+ m_mesh->setXZMeshResolution(QSize(2, 2));
+ m_mesh->setYZMeshResolution(QSize(2, 2));
+
+ m_posXImage->setCubeMapFace(QTextureCubeMap::CubeMapPositiveX);
+ m_posYImage->setCubeMapFace(QTextureCubeMap::CubeMapPositiveY);
+ m_posZImage->setCubeMapFace(QTextureCubeMap::CubeMapPositiveZ);
+ m_negXImage->setCubeMapFace(QTextureCubeMap::CubeMapNegativeX);
+ m_negYImage->setCubeMapFace(QTextureCubeMap::CubeMapNegativeY);
+ m_negZImage->setCubeMapFace(QTextureCubeMap::CubeMapNegativeZ);
+
+ m_skyboxTexture->setMagnificationFilter(QTextureCubeMap::Linear);
+ m_skyboxTexture->setMinificationFilter(QTextureCubeMap::Linear);
+ m_skyboxTexture->setGenerateMipMaps(false);
+ m_skyboxTexture->setWrapMode(QTextureWrapMode(QTextureWrapMode::ClampToEdge));
+
+ m_skyboxTexture->addTextureImage(m_posXImage);
+ m_skyboxTexture->addTextureImage(m_posYImage);
+ m_skyboxTexture->addTextureImage(m_posZImage);
+ m_skyboxTexture->addTextureImage(m_negXImage);
+ m_skyboxTexture->addTextureImage(m_negYImage);
+ m_skyboxTexture->addTextureImage(m_negZImage);
+
+ q_func()->addComponent(m_mesh);
+ q_func()->addComponent(m_material);
+ q_func()->addComponent(m_transform);
+}
+
+/*!
+ * \internal
+ */
+void QSkyboxEntityPrivate::reloadTexture()
+{
+ m_posXImage->setSource(QUrl(m_baseName + QStringLiteral("_posx") + m_extension));
+ m_posYImage->setSource(QUrl(m_baseName + QStringLiteral("_posy") + m_extension));
+ m_posZImage->setSource(QUrl(m_baseName + QStringLiteral("_posz") + m_extension));
+ m_negXImage->setSource(QUrl(m_baseName + QStringLiteral("_negx") + m_extension));
+ m_negYImage->setSource(QUrl(m_baseName + QStringLiteral("_negy") + m_extension));
+ m_negZImage->setSource(QUrl(m_baseName + QStringLiteral("_negz") + m_extension));
+}
+
+/*!
+ * \class Qt3D::QSkyboxEntity
+ *
+ * \brief Qt3D::QSkyboxEntity is a convenience Qt3D::QEntity subclass that can
+ * be used to insert a skybox in a 3D scene.
+ *
+ * By specifying a base name and an extension, Qt3D::QSkyboxEntity
+ * will take care of building a TextureCubeMap to be rendered at runtime. The
+ * images in the source directory should match the pattern:
+ * \b base name + * "_posx|_posy|_posz|_negx|_negy|_negz" + extension
+ *
+ * By default the extension defaults to .png.
+ *
+ * \note Please note that you shouldn't try to render skybox with an
+ * orthographic projection.
+ *
+ * \since 5.5
+ */
+
+/*!
+ * Constructs a new Qt3D::QSkyboxEntity object with \a parent as parent.
+ */
+QSkyboxEntity::QSkyboxEntity(QNode *parent)
+ : QEntity(*new QSkyboxEntityPrivate(this), parent)
+{
+ d_func()->init();
+}
+
+QSkyboxEntity::~QSkyboxEntity()
+{
+}
+
+/*!
+ * Sets the base name to \a baseName.
+ */
+void QSkyboxEntity::setBaseName(const QString &baseName)
+{
+ Q_D(QSkyboxEntity);
+ if (baseName != d->m_baseName) {
+ d->m_baseName = baseName;
+ emit sourceDirectoryChanged();
+ d->reloadTexture();
+ }
+}
+/*!
+ * Returns the base name.
+ */
+QString QSkyboxEntity::baseName() const
+{
+ Q_D(const QSkyboxEntity);
+ return d->m_baseName;
+}
+
+/*!
+ * Sets the extension to \a extension.
+ */
+void QSkyboxEntity::setExtension(const QString &extension)
+{
+ Q_D(QSkyboxEntity);
+ if (extension != d->m_extension) {
+ d->m_extension = extension;
+ emit extensionChanged();
+ d->reloadTexture();
+ }
+}
+
+/*!
+ * Returns the extension
+ */
+QString QSkyboxEntity::extension() const
+{
+ Q_D(const QSkyboxEntity);
+ return d->m_extension;
+}
+
+/*!
+ * Sets the camera position to \a cameraPosition.
+ */
+void QSkyboxEntity::setCameraPosition(const QVector3D &cameraPosition)
+{
+ Q_D(QSkyboxEntity);
+ if (cameraPosition != d->m_position) {
+ d->m_position = cameraPosition;
+ d->m_translate->setTranslation(d->m_position);
+ emit cameraPositionChanged();
+ }
+}
+
+/*!
+ * Returns the camera postion.
+ */
+QVector3D QSkyboxEntity::cameraPosition() const
+{
+ Q_D(const QSkyboxEntity);
+ return d->m_position;
+}
+
+} // Qt3D
+
+QT_END_NAMESPACE
diff --git a/src/render/defaults/qskyboxentity.h b/src/render/defaults/qskyboxentity.h
new file mode 100644
index 000000000..f2e7a76cb
--- /dev/null
+++ b/src/render/defaults/qskyboxentity.h
@@ -0,0 +1,78 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 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 QT3D_RENDER_QSKYBOXENTITY_H
+#define QT3D_RENDER_QSKYBOXENTITY_H
+
+#include <Qt3DCore/qentity.h>
+#include <Qt3DRenderer/qt3drenderer_global.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3D {
+
+class QSkyboxEntityPrivate;
+
+class QT3DRENDERERSHARED_EXPORT QSkyboxEntity : public QEntity
+{
+ Q_OBJECT
+public:
+ explicit QSkyboxEntity(QNode *parent = 0);
+ ~QSkyboxEntity();
+
+ void setBaseName(const QString &path);
+ QString baseName() const;
+
+ void setExtension(const QString &extension);
+ QString extension() const;
+
+ void setCameraPosition(const QVector3D &cameraPosition);
+ QVector3D cameraPosition() const;
+
+Q_SIGNALS:
+ void sourceDirectoryChanged();
+ void extensionChanged();
+ void cameraPositionChanged();
+
+private:
+ Q_DECLARE_PRIVATE(QSkyboxEntity)
+};
+
+} // Qt3D
+
+QT_END_NAMESPACE
+
+#endif // QT3D_RENDER_QSKYBOXENTITY_H
diff --git a/src/render/defaults/qskyboxentity_p.h b/src/render/defaults/qskyboxentity_p.h
new file mode 100644
index 000000000..2be276fb3
--- /dev/null
+++ b/src/render/defaults/qskyboxentity_p.h
@@ -0,0 +1,100 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 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 QT3D_RENDER_QSKYBOXENTITY_P_H
+#define QT3D_RENDER_QSKYBOXENTITY_P_H
+
+#include <Qt3DCore/private/qentity_p.h>
+#include <QVector3D>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3D {
+
+class QTranslateTransform;
+class QTextureCubeMap;
+class QShaderProgram;
+class QSkyboxEntity;
+class QTextureImage;
+class QCuboidMesh;
+class QRenderPass;
+class QTechnique;
+class QTransform;
+class QParameter;
+class QMaterial;
+class QEffect;
+
+class QSkyboxEntityPrivate : public QEntityPrivate
+{
+ QSkyboxEntityPrivate(QSkyboxEntity *skyboxEntity);
+
+ void init();
+ void reloadTexture();
+
+ Q_DECLARE_PUBLIC(QSkyboxEntity)
+
+ QEffect *m_effect;
+ QMaterial *m_material;
+ QTextureCubeMap *m_skyboxTexture;
+ QShaderProgram *m_gl3Shader;
+ QShaderProgram *m_gl2es2Shader;
+ QTechnique *m_gl2Technique;
+ QTechnique *m_es2Technique;
+ QTechnique *m_gl3Technique;
+ QRenderPass *m_gl2RenderPass;
+ QRenderPass *m_es2RenderPass;
+ QRenderPass *m_gl3RenderPass;
+ QCuboidMesh *m_mesh;
+ QTransform *m_transform;
+ QTranslateTransform *m_translate;
+ QParameter *m_textureParameter;
+ QTextureImage *m_posXImage;
+ QTextureImage *m_posYImage;
+ QTextureImage *m_posZImage;
+ QTextureImage *m_negXImage;
+ QTextureImage *m_negYImage;
+ QTextureImage *m_negZImage;
+ QString m_extension;
+ QString m_baseName;
+ QVector3D m_position;
+};
+
+} // Qt3D
+
+QT_END_NAMESPACE
+
+#endif // QT3D_RENDER_QSKYBOXENTITY_P_H
+