QGIS API Documentation 3.39.0-Master (bca3cdb6021)
Loading...
Searching...
No Matches
qgslinematerial_p.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgslinematerial_p.cpp
3 --------------------------------------
4 Date : Apr 2019
5 Copyright : (C) 2019 by Martin Dobias
6 Email : wonder dot sk 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
16#include "qgslinematerial_p.h"
17
18#include <QColor>
19#include <QSizeF>
20#include <QUrl>
21#include <QVector3D>
22
23#include <Qt3DRender/QBlendEquation>
24#include <Qt3DRender/QBlendEquationArguments>
25#include <Qt3DRender/QCamera>
26#include <Qt3DRender/QEffect>
27#include <Qt3DRender/QGraphicsApiFilter>
28#include <Qt3DRender/QParameter>
29#include <Qt3DRender/QRenderPass>
30#include <Qt3DRender/QTechnique>
31
33
34
35QgsLineMaterial::QgsLineMaterial()
36 : mParameterThickness( new Qt3DRender::QParameter( "THICKNESS", 10, this ) )
37 , mParameterMiterLimit( new Qt3DRender::QParameter( "MITER_LIMIT", -1, this ) ) // 0.75
38 , mParameterLineColor( new Qt3DRender::QParameter( "lineColor", QColor( 0, 255, 0 ), this ) )
39 , mParameterUseVertexColors( new Qt3DRender::QParameter( "useVertexColors", false, this ) )
40 , mParameterWindowScale( new Qt3DRender::QParameter( "WIN_SCALE", QSizeF(), this ) )
41{
42 addParameter( mParameterThickness );
43 addParameter( mParameterMiterLimit );
44 addParameter( mParameterLineColor );
45 addParameter( mParameterUseVertexColors );
46 addParameter( mParameterWindowScale );
47
48 //Parameter { name: "tex0"; value: txt },
49 //Parameter { name: "useTex"; value: false },
50
51 Qt3DRender::QShaderProgram *shaderProgram = new Qt3DRender::QShaderProgram( this );
52 shaderProgram->setVertexShaderCode( Qt3DRender::QShaderProgram::loadSource( QUrl( QStringLiteral( "qrc:/shaders/lines.vert" ) ) ) );
53 shaderProgram->setFragmentShaderCode( Qt3DRender::QShaderProgram::loadSource( QUrl( QStringLiteral( "qrc:/shaders/lines.frag" ) ) ) );
54 shaderProgram->setGeometryShaderCode( Qt3DRender::QShaderProgram::loadSource( QUrl( QStringLiteral( "qrc:/shaders/lines.geom" ) ) ) );
55
56 Qt3DRender::QRenderPass *renderPass = new Qt3DRender::QRenderPass( this );
57 renderPass->setShaderProgram( shaderProgram );
58
59 // without this filter the default forward renderer would not render this
60 Qt3DRender::QFilterKey *filterKey = new Qt3DRender::QFilterKey;
61 filterKey->setName( QStringLiteral( "renderingStyle" ) );
62 filterKey->setValue( "forward" );
63
64 Qt3DRender::QTechnique *technique = new Qt3DRender::QTechnique;
65 technique->addFilterKey( filterKey );
66 technique->addRenderPass( renderPass );
67 technique->graphicsApiFilter()->setApi( Qt3DRender::QGraphicsApiFilter::OpenGL );
68 technique->graphicsApiFilter()->setProfile( Qt3DRender::QGraphicsApiFilter::CoreProfile );
69 technique->graphicsApiFilter()->setMajorVersion( 3 );
70 technique->graphicsApiFilter()->setMinorVersion( 1 );
71
72 Qt3DRender::QEffect *effect = new Qt3DRender::QEffect( this );
73 effect->addTechnique( technique );
74
75 setEffect( effect );
76}
77
78void QgsLineMaterial::setLineColor( const QColor &color )
79{
80 mParameterLineColor->setValue( color );
81}
82
83QColor QgsLineMaterial::lineColor() const
84{
85 return mParameterLineColor->value().value<QColor>();
86}
87
88void QgsLineMaterial::setUseVertexColors( bool enabled )
89{
90 mParameterUseVertexColors->setValue( enabled );
91}
92
93bool QgsLineMaterial::useVertexColors() const
94{
95 return mParameterUseVertexColors->value().toBool();
96}
97
98void QgsLineMaterial::setLineWidth( float width )
99{
100 mParameterThickness->setValue( width );
101}
102
103float QgsLineMaterial::lineWidth() const
104{
105 return mParameterThickness->value().toFloat();
106}
107
108void QgsLineMaterial::setViewportSize( const QSizeF &viewportSize )
109{
110 mParameterWindowScale->setValue( viewportSize );
111}
112