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