42 const QPointF ¢erTexCoords,
const QSizeF &sizeTexCoords,
43 QVector<Qt3DRender::QParameter *> additionalShaderParameters,
44 Qt3DCore::QEntity *parent )
47 setObjectName(
"Preview Quad" );
50 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 };
52 const QByteArray vertexArr( (
const char * ) vert.constData(), vert.size() *
sizeof(
float ) );
55 vertexBuffer->setData( vertexArr );
57 positionAttribute->setName( Qt3DQAttribute::defaultPositionAttributeName() );
58 positionAttribute->setVertexBaseType( Qt3DQAttribute::Float );
59 positionAttribute->setVertexSize( 3 );
60 positionAttribute->setAttributeType( Qt3DQAttribute::VertexAttribute );
61 positionAttribute->setBuffer( vertexBuffer );
62 positionAttribute->setByteOffset( 0 );
63 positionAttribute->setByteStride( 3 *
sizeof(
float ) );
64 positionAttribute->setCount( 6 );
66 geom->addAttribute( positionAttribute );
68 Qt3DRender::QGeometryRenderer *renderer =
new Qt3DRender::QGeometryRenderer;
69 renderer->setPrimitiveType( Qt3DRender::QGeometryRenderer::PrimitiveType::Triangles );
70 renderer->setGeometry( geom );
72 addComponent( renderer );
76 addComponent( mMaterial );
89 mTextureParameter =
new Qt3DRender::QParameter(
"previewTexture", texture );
90 mCenterTextureCoords =
new Qt3DRender::QParameter(
"centerTexCoords", QVector2D( 0, 0 ) );
91 mSizeTextureCoords =
new Qt3DRender::QParameter(
"sizeTexCoords", QVector2D( 1, 1 ) );
92 addParameter( mTextureParameter );
93 addParameter( mCenterTextureCoords );
94 addParameter( mSizeTextureCoords );
95 for ( Qt3DRender::QParameter *parameter : additionalShaderParameters ) addParameter( parameter );
97 mEffect =
new Qt3DRender::QEffect;
99 Qt3DRender::QTechnique *technique =
new Qt3DRender::QTechnique;
101 Qt3DRender::QGraphicsApiFilter *graphicsApiFilter = technique->graphicsApiFilter();
102 graphicsApiFilter->setApi( Qt3DRender::QGraphicsApiFilter::Api::OpenGL );
103 graphicsApiFilter->setProfile( Qt3DRender::QGraphicsApiFilter::OpenGLProfile::CoreProfile );
104 graphicsApiFilter->setMajorVersion( 1 );
105 graphicsApiFilter->setMinorVersion( 5 );
107 Qt3DRender::QRenderPass *renderPass =
new Qt3DRender::QRenderPass;
109 Qt3DRender::QShaderProgram *shader =
new Qt3DRender::QShaderProgram;
110 shader->setVertexShaderCode( Qt3DRender::QShaderProgram::loadSource( QUrl(
"qrc:/shaders/preview.vert" ) ) );
111 shader->setFragmentShaderCode( Qt3DRender::QShaderProgram::loadSource( QUrl(
"qrc:/shaders/preview.frag" ) ) );
112 renderPass->setShaderProgram( shader );
114 technique->addRenderPass( renderPass );
116 mEffect->addTechnique( technique );
117 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)