18 #include <Qt3DCore/QEntity>
19 #include <Qt3DExtras/QCuboidMesh>
20 #include <Qt3DRender/QEffect>
21 #include <Qt3DRender/QMaterial>
22 #include <Qt3DRender/QShaderProgram>
23 #include <Qt3DRender/QFilterKey>
24 #include <Qt3DRender/QRenderPass>
25 #include <Qt3DRender/QTechnique>
26 #include <Qt3DRender/QGraphicsApiFilter>
27 #include <Qt3DRender/QCullFace>
28 #include <Qt3DRender/QDepthTest>
29 #include <Qt3DRender/QSeamlessCubemap>
30 #include <Qt3DRender/QParameter>
31 #include <Qt3DRender/QTextureImage>
40 , mMaterial( new
Qt3DRender::QMaterial( this ) )
41 , mGl3Technique( new
Qt3DRender::QTechnique( this ) )
42 , mFilterKey( new
Qt3DRender::QFilterKey( this ) )
43 , mGl3RenderPass( new
Qt3DRender::QRenderPass( this ) )
45 , mGammaStrengthParameter( new
Qt3DRender::QParameter( QStringLiteral(
"gammaStrength" ), 0.0f ) )
46 , mTextureParameter( new
Qt3DRender::QParameter( this ) )
48 mGl3Technique->graphicsApiFilter()->setApi( Qt3DRender::QGraphicsApiFilter::OpenGL );
51 mGl3Technique->graphicsApiFilter()->setProfile( Qt3DRender::QGraphicsApiFilter::CoreProfile );
54 mFilterKey->setName( QStringLiteral(
"renderingStyle" ) );
55 mFilterKey->setValue( QStringLiteral(
"forward" ) );
59 Qt3DRender::QCullFace *cullFront =
new Qt3DRender::QCullFace();
60 cullFront->setMode( Qt3DRender::QCullFace::Front );
61 Qt3DRender::QDepthTest *depthTest =
new Qt3DRender::QDepthTest();
62 depthTest->setDepthFunction( Qt3DRender::QDepthTest::LessOrEqual );
63 Qt3DRender::QSeamlessCubemap *seamlessCubemap =
new Qt3DRender::QSeamlessCubemap();
77 mMesh->setXYMeshResolution( QSize( 2, 2 ) );
78 mMesh->setXZMeshResolution( QSize( 2, 2 ) );
79 mMesh->setYZMeshResolution( QSize( 2, 2 ) );
81 addComponent(
mMesh );
89 , mTexturePath( texturePath )
90 , mLoadedTexture( new
Qt3DRender::QTextureLoader( parent ) )
91 , mGlShader( new
Qt3DRender::QShaderProgram( this ) )
93 mLoadedTexture->setGenerateMipMaps(
false );
94 mGlShader->setVertexShaderCode( Qt3DRender::QShaderProgram::loadSource( QUrl( QStringLiteral(
"qrc:/shaders/skybox.vert" ) ) ) );
95 mGlShader->setFragmentShaderCode( Qt3DRender::QShaderProgram::loadSource( QUrl( QStringLiteral(
"qrc:/shaders/hdr_skybox.frag" ) ) ) );
104 void QgsPanoramicSkyboxEntity::reloadTexture()
106 mLoadedTexture->setSource( QUrl::fromUserInput( mTexturePath ) );
113 , mGlShader( new
Qt3DRender::QShaderProgram() )
114 , mCubeMap( new
Qt3DRender::QTextureCubeMap( this ) )
117 mCubeFacesPaths[Qt3DRender::QTextureCubeMap::CubeMapPositiveX] = posX;
118 mCubeFacesPaths[Qt3DRender::QTextureCubeMap::CubeMapPositiveY] = posY;
119 mCubeFacesPaths[Qt3DRender::QTextureCubeMap::CubeMapPositiveZ] = posZ;
120 mCubeFacesPaths[Qt3DRender::QTextureCubeMap::CubeMapNegativeX] = negX;
121 mCubeFacesPaths[Qt3DRender::QTextureCubeMap::CubeMapNegativeY] = negY;
122 mCubeFacesPaths[Qt3DRender::QTextureCubeMap::CubeMapNegativeZ] = negZ;
126 void QgsCubeFacesSkyboxEntity::init()
128 mGlShader->setVertexShaderCode( Qt3DRender::QShaderProgram::loadSource( QUrl( QStringLiteral(
"qrc:/shaders/skybox.vert" ) ) ) );
129 mGlShader->setFragmentShaderCode( Qt3DRender::QShaderProgram::loadSource( QUrl( QStringLiteral(
"qrc:/shaders/skybox.frag" ) ) ) );
132 mCubeMap->setMagnificationFilter( Qt3DRender::QTextureCubeMap::Linear );
133 mCubeMap->setMinificationFilter( Qt3DRender::QTextureCubeMap::Linear );
134 mCubeMap->setGenerateMipMaps(
false );
135 mCubeMap->setWrapMode( Qt3DRender::QTextureWrapMode( Qt3DRender::QTextureWrapMode::Repeat ) );
137 mCubeFacesPaths[Qt3DRender::QTextureCubeMap::CubeMapPositiveX] = QString();
138 mCubeFacesPaths[Qt3DRender::QTextureCubeMap::CubeMapPositiveY] = QString();
139 mCubeFacesPaths[Qt3DRender::QTextureCubeMap::CubeMapPositiveZ] = QString();
140 mCubeFacesPaths[Qt3DRender::QTextureCubeMap::CubeMapNegativeX] = QString();
141 mCubeFacesPaths[Qt3DRender::QTextureCubeMap::CubeMapNegativeY] = QString();
142 mCubeFacesPaths[Qt3DRender::QTextureCubeMap::CubeMapNegativeZ] = QString();
148 void QgsCubeFacesSkyboxEntity::reloadTexture()
150 for ( Qt3DRender::QAbstractTextureImage *textureImage : mFacesTextureImages )
152 mCubeMap->removeTextureImage( textureImage );
155 mFacesTextureImages.clear();
157 for (
auto it = mCubeFacesPaths.begin(); it != mCubeFacesPaths.end(); ++it )
159 Qt3DRender::QTextureCubeMap::CubeMapFace face = it.key();
160 QString texturePath = it.value();
161 Qt3DRender::QTextureImage *image =
new Qt3DRender::QTextureImage(
this );
162 image->setFace( face );
163 image->setMirrored(
false );
164 image->setSource( QUrl::fromUserInput( texturePath ) );
165 mCubeMap->addTextureImage( image );
166 mFacesTextureImages.push_back( image );