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>
35QgsLineMaterial::QgsLineMaterial()
36 : mParameterThickness( new
Qt3DRender::QParameter(
"THICKNESS", 10, this ) )
37 , mParameterMiterLimit( new
Qt3DRender::QParameter(
"MITER_LIMIT", -1, this ) )
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 ) )
42 addParameter( mParameterThickness );
43 addParameter( mParameterMiterLimit );
44 addParameter( mParameterLineColor );
45 addParameter( mParameterUseVertexColors );
46 addParameter( mParameterWindowScale );
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" ) ) ) );
56 Qt3DRender::QBlendEquation *blendEquation =
new Qt3DRender::QBlendEquation(
this );
57 blendEquation->setBlendFunction( Qt3DRender::QBlendEquation::Add );
59 Qt3DRender::QBlendEquationArguments *blendEquationArgs =
new Qt3DRender::QBlendEquationArguments(
this );
60 blendEquationArgs->setSourceRgb( Qt3DRender::QBlendEquationArguments::SourceAlpha );
61 blendEquationArgs->setDestinationRgb( Qt3DRender::QBlendEquationArguments::OneMinusSourceAlpha );
63 Qt3DRender::QRenderPass *renderPass =
new Qt3DRender::QRenderPass(
this );
64 renderPass->setShaderProgram( shaderProgram );
65 renderPass->addRenderState( blendEquation );
66 renderPass->addRenderState( blendEquationArgs );
69 Qt3DRender::QFilterKey *filterKey =
new Qt3DRender::QFilterKey;
70 filterKey->setName( QStringLiteral(
"renderingStyle" ) );
71 filterKey->setValue(
"forward" );
73 Qt3DRender::QTechnique *technique =
new Qt3DRender::QTechnique;
74 technique->addFilterKey( filterKey );
75 technique->addRenderPass( renderPass );
76 technique->graphicsApiFilter()->setApi( Qt3DRender::QGraphicsApiFilter::OpenGL );
77 technique->graphicsApiFilter()->setProfile( Qt3DRender::QGraphicsApiFilter::CoreProfile );
78 technique->graphicsApiFilter()->setMajorVersion( 3 );
79 technique->graphicsApiFilter()->setMinorVersion( 1 );
81 Qt3DRender::QEffect *effect =
new Qt3DRender::QEffect(
this );
82 effect->addTechnique( technique );
87void QgsLineMaterial::setLineColor(
const QColor &color )
89 mParameterLineColor->setValue( color );
92QColor QgsLineMaterial::lineColor()
const
94 return mParameterLineColor->value().value<QColor>();
97void QgsLineMaterial::setUseVertexColors(
bool enabled )
99 mParameterUseVertexColors->setValue( enabled );
102bool QgsLineMaterial::useVertexColors()
const
104 return mParameterUseVertexColors->value().toBool();
107void QgsLineMaterial::setLineWidth(
float width )
109 mParameterThickness->setValue( width );
112float QgsLineMaterial::lineWidth()
const
114 return mParameterThickness->value().toFloat();
117void QgsLineMaterial::setViewportSize(
const QSizeF &viewportSize )
119 mParameterWindowScale->setValue( viewportSize );