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