QGIS API Documentation 4.1.0-Master (3b8ef1f72a3)
Loading...
Searching...
No Matches
qgshighlightmaterial.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgshighlightmaterial.cpp
3 ---------------------
4 begin : December 2025
5 copyright : (C) 2025 by Stefanos Natsis
6 email : uclaros at gmail dot com
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
17
18#include "qgssettings.h"
19
20#include <QColor>
21#include <QString>
22#include <QUrl>
23#include <Qt3DRender/QEffect>
24#include <Qt3DRender/QGraphicsApiFilter>
25#include <Qt3DRender/QParameter>
26#include <Qt3DRender/QTechnique>
27
28#include "moc_qgshighlightmaterial.cpp"
29
30using namespace Qt::StringLiterals;
31
33
34QgsHighlightMaterial::QgsHighlightMaterial( Qgis::MaterialRenderingTechnique technique, QNode *parent )
35 : QgsMaterial( parent )
36{
37 init( technique );
38}
39
40QgsHighlightMaterial::~QgsHighlightMaterial() = default;
41
42void QgsHighlightMaterial::init( Qgis::MaterialRenderingTechnique renderingTechnique )
43{
44 Qt3DRender::QEffect *effect = new Qt3DRender::QEffect;
45 Qt3DRender::QTechnique *technique = new Qt3DRender::QTechnique;
46 technique->graphicsApiFilter()->setApi( Qt3DRender::QGraphicsApiFilter::OpenGL );
47 technique->graphicsApiFilter()->setProfile( Qt3DRender::QGraphicsApiFilter::CoreProfile );
48 technique->graphicsApiFilter()->setMajorVersion( 3 );
49 technique->graphicsApiFilter()->setMinorVersion( 3 );
50
51 Qt3DRender::QRenderPass *pass = new Qt3DRender::QRenderPass;
52
53 Qt3DRender::QShaderProgram *shaderProgram = new Qt3DRender::QShaderProgram;
54 switch ( renderingTechnique )
55 {
60 {
61 shaderProgram->setVertexShaderCode( Qt3DRender::QShaderProgram::loadSource( QUrl( u"qrc:/shaders/default.vert"_s ) ) );
62 break;
63 }
65 {
66 shaderProgram->setVertexShaderCode( Qt3DRender::QShaderProgram::loadSource( QUrl( u"qrc:/shaders/instanced.vert"_s ) ) );
67 break;
68 }
72 {
73 // Lines are single color and do not need the highlight material
74 // Billboards are not supported yet
75 break;
76 }
77 }
78
79 shaderProgram->setFragmentShaderCode( Qt3DRender::QShaderProgram::loadSource( QUrl( u"qrc:/shaders/singlecolor.frag"_s ) ) );
80 pass->setShaderProgram( shaderProgram );
81
82 const QgsSettings settings;
83 const float alpha = settings.value( u"Map/highlight/colorAlpha"_s, Qgis::DEFAULT_HIGHLIGHT_COLOR.alpha() ).toFloat() / 255.f;
84 QColor color = QColor( settings.value( u"Map/highlight/color"_s, Qgis::DEFAULT_HIGHLIGHT_COLOR.name() ).toString() );
85 color.setAlphaF( alpha );
86 Qt3DRender::QParameter *colorParam = new Qt3DRender::QParameter( u"color"_s, color );
87 pass->addParameter( colorParam );
88
89 technique->addRenderPass( pass );
90 effect->addTechnique( technique );
91 setEffect( effect );
92}
93
static const QColor DEFAULT_HIGHLIGHT_COLOR
Default highlight color.
Definition qgis.h:6652
MaterialRenderingTechnique
Material rendering techniques.
Definition qgis.h:4327
@ Points
Point based rendering, requires point data.
Definition qgis.h:4331
@ Triangles
Triangle based rendering (default).
Definition qgis.h:4328
@ TrianglesFromModel
Triangle based rendering, using a model object source.
Definition qgis.h:4333
@ Lines
Line based rendering, requires line data.
Definition qgis.h:4329
@ Billboards
Flat billboard rendering.
Definition qgis.h:4335
@ TrianglesDataDefined
Triangle based rendering with possibility of datadefined color.
Definition qgis.h:4334
@ InstancedPoints
Instanced based rendering, requiring triangles and point data.
Definition qgis.h:4330
@ TrianglesWithFixedTexture
Triangle based rendering, using a fixed, non-user-configurable texture (e.g. for terrain rendering).
Definition qgis.h:4332
Base class for all materials used within QGIS 3D views.
Definition qgsmaterial.h:40
Stores settings for use within QGIS.
Definition qgssettings.h:68
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.