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 , mParameterWindowScale( new
Qt3DRender::QParameter(
"WIN_SCALE", QSizeF(), this ) )
41 addParameter( mParameterThickness );
42 addParameter( mParameterMiterLimit );
43 addParameter( mParameterLineColor );
44 addParameter( mParameterWindowScale );
49 Qt3DRender::QShaderProgram *shaderProgram =
new Qt3DRender::QShaderProgram(
this );
50 shaderProgram->setVertexShaderCode( Qt3DRender::QShaderProgram::loadSource( QUrl( QStringLiteral(
"qrc:/shaders/lines.vert" ) ) ) );
51 shaderProgram->setFragmentShaderCode( Qt3DRender::QShaderProgram::loadSource( QUrl( QStringLiteral(
"qrc:/shaders/lines.frag" ) ) ) );
52 shaderProgram->setGeometryShaderCode( Qt3DRender::QShaderProgram::loadSource( QUrl( QStringLiteral(
"qrc:/shaders/lines.geom" ) ) ) );
54 Qt3DRender::QBlendEquation *blendEquation =
new Qt3DRender::QBlendEquation(
this );
55 blendEquation->setBlendFunction( Qt3DRender::QBlendEquation::Add );
57 Qt3DRender::QBlendEquationArguments *blendEquationArgs =
new Qt3DRender::QBlendEquationArguments(
this );
58 blendEquationArgs->setSourceRgb( Qt3DRender::QBlendEquationArguments::SourceAlpha );
59 blendEquationArgs->setDestinationRgb( Qt3DRender::QBlendEquationArguments::OneMinusSourceAlpha );
61 Qt3DRender::QRenderPass *renderPass =
new Qt3DRender::QRenderPass(
this );
62 renderPass->setShaderProgram( shaderProgram );
63 renderPass->addRenderState( blendEquation );
64 renderPass->addRenderState( blendEquationArgs );
67 Qt3DRender::QFilterKey *filterKey =
new Qt3DRender::QFilterKey;
68 filterKey->setName( QStringLiteral(
"renderingStyle" ) );
69 filterKey->setValue(
"forward" );
71 Qt3DRender::QTechnique *technique =
new Qt3DRender::QTechnique;
72 technique->addFilterKey( filterKey );
73 technique->addRenderPass( renderPass );
74 technique->graphicsApiFilter()->setApi( Qt3DRender::QGraphicsApiFilter::OpenGL );
75 technique->graphicsApiFilter()->setProfile( Qt3DRender::QGraphicsApiFilter::CoreProfile );
76 technique->graphicsApiFilter()->setMajorVersion( 3 );
77 technique->graphicsApiFilter()->setMinorVersion( 1 );
79 Qt3DRender::QEffect *effect =
new Qt3DRender::QEffect(
this );
80 effect->addTechnique( technique );
85void QgsLineMaterial::setLineColor(
const QColor &color )
87 mParameterLineColor->setValue( color );
90QColor QgsLineMaterial::lineColor()
const
92 return mParameterLineColor->value().value<QColor>();
95void QgsLineMaterial::setLineWidth(
float width )
97 mParameterThickness->setValue( width );
100float QgsLineMaterial::lineWidth()
const
102 return mParameterThickness->value().toFloat();
105void QgsLineMaterial::setViewportSize(
const QSizeF &viewportSize )
107 mParameterWindowScale->setValue( viewportSize );