15 #include <Qt3DRender/QParameter>
16 #include <Qt3DRender/QShaderProgram>
17 #include <Qt3DRender/QRenderPass>
18 #include <Qt3DRender/QTechnique>
19 #include <Qt3DRender/QGraphicsApiFilter>
20 #include <Qt3DRender/QEffect>
21 #include <Qt3DRender/QBlendEquationArguments>
22 #include <Qt3DRender/QBlendEquation>
23 #include <Qt3DRender/QNoDepthMask>
36 : mSize( new
Qt3DRender::QParameter(
"BB_SIZE", QSizeF( 100, 100 ), this ) )
37 , mViewportSize( new
Qt3DRender::QParameter(
"WIN_SCALE", QSizeF( 800, 600 ), this ) )
39 addParameter( mSize );
40 addParameter( mViewportSize );
43 mTexture2D =
new Qt3DRender::QParameter(
"tex0", QVariant(),
this );
44 addParameter( mTexture2D );
47 Qt3DRender::QBlendEquationArguments *blendState =
new Qt3DRender::QBlendEquationArguments;
48 blendState->setSourceRgb( Qt3DRender::QBlendEquationArguments::SourceAlpha );
49 blendState->setDestinationRgb( Qt3DRender::QBlendEquationArguments::OneMinusSourceAlpha );
51 Qt3DRender::QBlendEquation *blendEquation =
new Qt3DRender::QBlendEquation;
52 blendEquation->setBlendFunction( Qt3DRender::QBlendEquation::Add );
55 Qt3DRender::QShaderProgram *shaderProgram =
new Qt3DRender::QShaderProgram(
this );
56 shaderProgram->setVertexShaderCode( Qt3DRender::QShaderProgram::loadSource( QUrl( QStringLiteral(
"qrc:/shaders/billboards.vert" ) ) ) );
57 shaderProgram->setFragmentShaderCode( Qt3DRender::QShaderProgram::loadSource( QUrl( QStringLiteral(
"qrc:/shaders/billboards.frag" ) ) ) );
58 shaderProgram->setGeometryShaderCode( Qt3DRender::QShaderProgram::loadSource( QUrl( QStringLiteral(
"qrc:/shaders/billboards.geom" ) ) ) );
61 Qt3DRender::QRenderPass *renderPass =
new Qt3DRender::QRenderPass(
this );
62 renderPass->setShaderProgram( shaderProgram );
63 renderPass->addRenderState( blendState );
64 renderPass->addRenderState( blendEquation );
67 Qt3DRender::QFilterKey *filterKey =
new Qt3DRender::QFilterKey;
68 filterKey->setName( QStringLiteral(
"renderingStyle" ) );
69 filterKey->setValue(
"forward" );
72 Qt3DRender::QTechnique *technique =
new Qt3DRender::QTechnique;
73 technique->addRenderPass( renderPass );
74 technique->addFilterKey( filterKey );
75 technique->graphicsApiFilter()->setApi( Qt3DRender::QGraphicsApiFilter::OpenGL );
76 technique->graphicsApiFilter()->setProfile( Qt3DRender::QGraphicsApiFilter::CoreProfile );
77 technique->graphicsApiFilter()->setMajorVersion( 3 );
78 technique->graphicsApiFilter()->setMinorVersion( 1 );
81 Qt3DRender::QEffect *effect =
new Qt3DRender::QEffect(
this );
82 effect->addTechnique( technique );
89 mSize->setValue(
size );
94 return mSize->value().value<QSizeF>();
99 mViewportSize->setValue(
size );
104 return mViewportSize->value().value<QSizeF>();
107 void QgsPoint3DBillboardMaterial::setTexture2DFromImage( QImage image,
double size )
111 QgsTerrainTextureImage *billboardTextureImage =
new QgsTerrainTextureImage( image, randomExtent, QStringLiteral(
"billboard material." ) );
113 setTexture2DFromTextureImage( billboardTextureImage );
132 const double strokeRatio = 0.5;
136 const double minimumExtraSize = 40;
137 const double extraPixel = minimumExtraSize > pixelSize * strokeRatio ? minimumExtraSize : pixelSize * strokeRatio;
138 const int pixelWithExtra = std::ceil( pixelSize + extraPixel );
140 const QImage symbolImage = symbolPixmap.toImage();
141 const QImage flippedSymbolImage = symbolImage.mirrored();
142 setTexture2DFromImage( flippedSymbolImage, pixelWithExtra );
145 void QgsPoint3DBillboardMaterial::setTexture2DFromTextureImage( Qt3DRender::QAbstractTextureImage *textureImage )
148 Qt3DRender::QTexture2D *texture2D =
new Qt3DRender::QTexture2D(
this );
149 texture2D->setGenerateMipMaps(
false );
150 texture2D->setMagnificationFilter( Qt3DRender::QTexture2D::Linear );
151 texture2D->setMinificationFilter( Qt3DRender::QTexture2D::Linear );
154 texture2D->addTextureImage( textureImage );
156 mTexture2D->setValue( QVariant::fromValue( texture2D ) );