1 /***************************************************************************
2   qgsskyboxentity.h
3   --------------------------------------
4   Date                 : August 2020
5   Copyright            : (C) 2020 by Belgacem Nedjima
6   Email                : gb uderscore nedjima at esi dot dz
7  ***************************************************************************
8  *                                                                         *
9  *   This program is free software; you can redistribute it and/or modify  *
10  *   it under the terms of the GNU General Public License as published by  *
11  *   the Free Software Foundation; either version 2 of the License, or     *
12  *   (at your option) any later version.                                   *
13  *                                                                         *
14  ***************************************************************************/
15 
16 #ifndef QGSSKYBOXENTITY_H
17 #define QGSSKYBOXENTITY_H
18 
19 #include <Qt3DCore/QEntity>
20 #include <QVector3D>
21 #include <Qt3DRender/QTexture>
22 #include <Qt3DExtras/QCuboidMesh>
23 #include <Qt3DRender/QEffect>
24 #include <Qt3DRender/QMaterial>
25 #include <Qt3DRender/QShaderProgram>
26 #include <Qt3DRender/QFilterKey>
27 #include <Qt3DRender/QRenderPass>
28 #include <Qt3DExtras/QPlaneMesh>
29 #include <Qt3DRender/QParameter>
30 
31 #include "qgis_3d.h"
32 
33 class QgsImageTexture;
34 
35 #define SIP_NO_FILE
36 
37 /**
38  * \brief Base class for all skybox types.
39  *
40  * It holds the common member data between different skybox entity types
41  * \ingroup 3d
42  * \since QGIS 3.16
43  */
44 class _3D_EXPORT QgsSkyboxEntity : public Qt3DCore::QEntity
45 {
46     Q_OBJECT
47   public:
48     //! Skybox type enumeration
49     enum SkyboxType
50     {
51       PanoramicSkybox,
52       DistinctTexturesSkybox
53     };
54   public:
55     //! Constructor
56     QgsSkyboxEntity( QNode *parent = nullptr );
57 
58     //! Returns the type of the current skybox
59     virtual SkyboxType type() const = 0;
60 
61   protected:
62     Qt3DRender::QEffect *mEffect = nullptr;
63     Qt3DRender::QMaterial *mMaterial = nullptr;
64     Qt3DRender::QTechnique *mGl3Technique = nullptr;
65     Qt3DRender::QFilterKey *mFilterKey = nullptr;
66     Qt3DRender::QRenderPass *mGl3RenderPass = nullptr;
67     Qt3DExtras::QCuboidMesh *mMesh = nullptr;
68     Qt3DRender::QParameter *mGammaStrengthParameter = nullptr;
69     Qt3DRender::QParameter *mTextureParameter = nullptr;
70 };
71 
72 /**
73  * \brief A skybox constructed from a panoramic image.
74  *
75  * \ingroup 3d
76  * \since QGIS 3.16
77  */
78 class _3D_EXPORT QgsPanoramicSkyboxEntity : public QgsSkyboxEntity
79 {
80   public:
81     //! Construct a skybox from a panoramic 360 image
82     QgsPanoramicSkyboxEntity( const QString &texturePath, Qt3DCore::QNode *parent = nullptr );
83 
84     //! Returns the path of the current texture in use
texturePath()85     QString texturePath() const { return mTexturePath; }
86     //! Returns the type of the current skybox
type()87     SkyboxType type() const override { return SkyboxType::PanoramicSkybox; }
88 
89   private:
90     void reloadTexture();
91   private:
92     QString mTexturePath;
93     Qt3DRender::QTextureLoader *mLoadedTexture = nullptr;
94     Qt3DRender::QShaderProgram *mGlShader = nullptr;
95 };
96 
97 /**
98  * \brief A skybox constructed from a 6 cube faces.
99  *
100  * \ingroup 3d
101  * \since QGIS 3.16
102  */
103 class _3D_EXPORT QgsCubeFacesSkyboxEntity : public QgsSkyboxEntity
104 {
105   public:
106     //! Constructs a skybox from 6 different images
107     QgsCubeFacesSkyboxEntity( const QString &posX, const QString &posY, const QString &posZ, const QString &negX, const QString &negY, const QString &negZ, Qt3DCore::QNode *parent = nullptr );
108 
109     //! Returns the type of the current skybox
type()110     SkyboxType type() const override { return SkyboxType::DistinctTexturesSkybox; }
111 
112   private:
113     void init();
114     void reloadTexture();
115   private:
116     QMap<Qt3DRender::QTextureCubeMap::CubeMapFace, QString> mCubeFacesPaths;
117     Qt3DRender::QShaderProgram *mGlShader = nullptr;
118     QVector<Qt3DRender::QTextureImage *> mFacesTextureImages;
119     Qt3DRender::QTextureCubeMap *mCubeMap = nullptr;
120 };
121 
122 #endif // QGSSKYBOXENTITY_H
123