17#include "moc_qgslinematerial_p.cpp"
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>
36QgsLineMaterial::QgsLineMaterial()
37 : mParameterThickness( new
Qt3DRender::QParameter(
"THICKNESS", 10, this ) )
38 , mParameterMiterLimit( new
Qt3DRender::QParameter(
"MITER_LIMIT", -1, this ) )
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 ) )
43 addParameter( mParameterThickness );
44 addParameter( mParameterMiterLimit );
45 addParameter( mParameterLineColor );
46 addParameter( mParameterUseVertexColors );
47 addParameter( mParameterWindowScale );
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" ) ) ) );
57 Qt3DRender::QRenderPass *renderPass =
new Qt3DRender::QRenderPass(
this );
58 renderPass->setShaderProgram( shaderProgram );
61 Qt3DRender::QFilterKey *filterKey =
new Qt3DRender::QFilterKey;
62 filterKey->setName( QStringLiteral(
"renderingStyle" ) );
63 filterKey->setValue(
"forward" );
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 );
73 Qt3DRender::QEffect *effect =
new Qt3DRender::QEffect(
this );
74 effect->addTechnique( technique );
79void QgsLineMaterial::setLineColor(
const QColor &color )
81 mParameterLineColor->setValue( color );
84QColor QgsLineMaterial::lineColor()
const
86 return mParameterLineColor->value().value<QColor>();
89void QgsLineMaterial::setUseVertexColors(
bool enabled )
91 mParameterUseVertexColors->setValue( enabled );
94bool QgsLineMaterial::useVertexColors()
const
96 return mParameterUseVertexColors->value().toBool();
99void QgsLineMaterial::setLineWidth(
float width )
101 mParameterThickness->setValue( width );
104float QgsLineMaterial::lineWidth()
const
106 return mParameterThickness->value().toFloat();
109void QgsLineMaterial::setViewportSize(
const QSizeF &viewportSize )
111 mParameterWindowScale->setValue( viewportSize );