43 const QPointF ¢erTexCoords,
const QSizeF &sizeTexCoords,
44 QVector<Qt3DRender::QParameter *> additionalShaderParameters,
45 Qt3DCore::QEntity *parent )
48 setObjectName(
"Preview Quad" );
51 const QVector<float> vert = { -1.0f, -1.0f, 1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 1.0f };
53 const QByteArray vertexArr( (
const char * ) vert.constData(), vert.size() *
sizeof(
float ) );
56 vertexBuffer->setData( vertexArr );
58 positionAttribute->setName( Qt3DQAttribute::defaultPositionAttributeName() );
59 positionAttribute->setVertexBaseType( Qt3DQAttribute::Float );
60 positionAttribute->setVertexSize( 3 );
61 positionAttribute->setAttributeType( Qt3DQAttribute::VertexAttribute );
62 positionAttribute->setBuffer( vertexBuffer );
63 positionAttribute->setByteOffset( 0 );
64 positionAttribute->setByteStride( 3 *
sizeof(
float ) );
65 positionAttribute->setCount( 6 );
67 geom->addAttribute( positionAttribute );
69 Qt3DRender::QGeometryRenderer *renderer =
new Qt3DRender::QGeometryRenderer;
70 renderer->setPrimitiveType( Qt3DRender::QGeometryRenderer::PrimitiveType::Triangles );
71 renderer->setGeometry( geom );
73 addComponent( renderer );
77 addComponent( mMaterial );
90 mTextureParameter =
new Qt3DRender::QParameter(
"previewTexture", texture );
91 mCenterTextureCoords =
new Qt3DRender::QParameter(
"centerTexCoords", QVector2D( 0, 0 ) );
92 mSizeTextureCoords =
new Qt3DRender::QParameter(
"sizeTexCoords", QVector2D( 1, 1 ) );
93 addParameter( mTextureParameter );
94 addParameter( mCenterTextureCoords );
95 addParameter( mSizeTextureCoords );
96 for ( Qt3DRender::QParameter *parameter : additionalShaderParameters ) addParameter( parameter );
98 mEffect =
new Qt3DRender::QEffect;
100 Qt3DRender::QTechnique *technique =
new Qt3DRender::QTechnique;
102 Qt3DRender::QGraphicsApiFilter *graphicsApiFilter = technique->graphicsApiFilter();
103 graphicsApiFilter->setApi( Qt3DRender::QGraphicsApiFilter::Api::OpenGL );
104 graphicsApiFilter->setProfile( Qt3DRender::QGraphicsApiFilter::OpenGLProfile::CoreProfile );
105 graphicsApiFilter->setMajorVersion( 1 );
106 graphicsApiFilter->setMinorVersion( 5 );
108 Qt3DRender::QRenderPass *renderPass =
new Qt3DRender::QRenderPass;
110 Qt3DRender::QShaderProgram *shader =
new Qt3DRender::QShaderProgram;
111 shader->setVertexShaderCode( Qt3DRender::QShaderProgram::loadSource( QUrl(
"qrc:/shaders/preview.vert" ) ) );
112 shader->setFragmentShaderCode( Qt3DRender::QShaderProgram::loadSource( QUrl(
"qrc:/shaders/preview.frag" ) ) );
113 renderPass->setShaderProgram( shader );
115 technique->addRenderPass( renderPass );
117 mEffect->addTechnique( technique );
118 setEffect( mEffect );
QgsPreviewQuad(Qt3DRender::QAbstractTexture *texture, const QPointF ¢erNDC, const QSizeF &size, QVector< Qt3DRender::QParameter * > additionalShaderParameters=QVector< Qt3DRender::QParameter * >(), Qt3DCore::QEntity *parent=nullptr)
Construct an object that displays a texture for debugging purposes (example: depth buffer)