18#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
19#include <Qt3DRender/QGeometry>
20#include <Qt3DRender/QAttribute>
21#include <Qt3DRender/QBuffer>
26#include <Qt3DCore/QGeometry>
27#include <Qt3DCore/QAttribute>
28#include <Qt3DCore/QBuffer>
33#include <Qt3DRender/QGeometryRenderer>
34#include <Qt3DRender/QTechnique>
35#include <Qt3DRender/QGraphicsApiFilter>
36#include <Qt3DRender/QShaderProgram>
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 );
83 mMaterial->
setViewPort( QVector2D( centerTexCoords.x(), centerTexCoords.y() ), QVector2D( sizeTexCoords.width(), sizeTexCoords.height() ) );
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 );
122 mCenterTextureCoords->setValue( centerTexCoords );
123 mSizeTextureCoords->setValue( sizeTexCoords );
void setViewPort(QVector2D centerTexCoords, QVector2D sizeTexCoords)
Sets the view port of the quad.
QgsPreviewQuadMaterial(Qt3DRender::QAbstractTexture *texture, QVector< Qt3DRender::QParameter * > additionalShaderParameters=QVector< Qt3DRender::QParameter * >(), QNode *parent=nullptr)
Constructor.
void setViewPort(const QPointF ¢erNDC, const QSizeF &size)
Sets where the quad will be located on the scene.
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)
Qt3DCore::QAttribute Qt3DQAttribute
Qt3DCore::QBuffer Qt3DQBuffer
Qt3DCore::QGeometry Qt3DQGeometry
Qt3DCore::QAttribute Qt3DQAttribute
Qt3DCore::QBuffer Qt3DQBuffer
Qt3DCore::QGeometry Qt3DQGeometry