QGIS API Documentation 3.41.0-Master (3440c17df1d)
Loading...
Searching...
No Matches
qgsrenderpassquad.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsrenderpassquad.cpp
3 --------------------------------------
4 Date : June 2022
5 Copyright : (C) 2022 by Belgacem Nedjima
6 Email : belgacem dot nedjima at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
16#include "qgsrenderpassquad.h"
17#include "moc_qgsrenderpassquad.cpp"
18
19#include <random>
20
21#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
22#include <Qt3DRender/QAttribute>
23#include <Qt3DRender/QBuffer>
24#include <Qt3DRender/QGeometry>
25
26typedef Qt3DRender::QAttribute Qt3DQAttribute;
27typedef Qt3DRender::QBuffer Qt3DQBuffer;
28typedef Qt3DRender::QGeometry Qt3DQGeometry;
29#else
30#include <Qt3DCore/QAttribute>
31#include <Qt3DCore/QBuffer>
32#include <Qt3DCore/QGeometry>
33
34typedef Qt3DCore::QAttribute Qt3DQAttribute;
35typedef Qt3DCore::QBuffer Qt3DQBuffer;
36typedef Qt3DCore::QGeometry Qt3DQGeometry;
37#endif
38
39#include <Qt3DRender/QGeometryRenderer>
40#include <Qt3DRender/QTechnique>
41#include <Qt3DRender/QGraphicsApiFilter>
42#include <Qt3DRender/QDepthTest>
43#include <Qt3DRender/QEffect>
44#include <QUrl>
45#include <QVector3D>
46
47QgsRenderPassQuad::QgsRenderPassQuad( Qt3DRender::QLayer *layer, QNode *parent )
48 : Qt3DCore::QEntity( parent )
49{
50 Qt3DQGeometry *geom = new Qt3DQGeometry( this );
51 Qt3DQAttribute *positionAttribute = new Qt3DQAttribute( this );
52 const QVector<float> vert = { -1.0f, -1.0f, 0.0f, 1.0f, -1.0f, 0.0f, -1.0f, 1.0f, 0.0f, -1.0f, 1.0f, 0.0f, 1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 0.0f };
53
54 const QByteArray vertexArr( ( const char * ) vert.constData(), vert.size() * sizeof( float ) );
55 Qt3DQBuffer *vertexBuffer = nullptr;
56 vertexBuffer = new Qt3DQBuffer( this );
57 vertexBuffer->setData( vertexArr );
58
59 positionAttribute->setName( Qt3DQAttribute::defaultPositionAttributeName() );
60 positionAttribute->setVertexBaseType( Qt3DQAttribute::Float );
61 positionAttribute->setVertexSize( 3 );
62 positionAttribute->setAttributeType( Qt3DQAttribute::VertexAttribute );
63 positionAttribute->setBuffer( vertexBuffer );
64 positionAttribute->setByteOffset( 0 );
65 positionAttribute->setByteStride( 3 * sizeof( float ) );
66 positionAttribute->setCount( 6 );
67
68 geom->addAttribute( positionAttribute );
69
70 Qt3DRender::QGeometryRenderer *renderer = new Qt3DRender::QGeometryRenderer( this );
71 renderer->setPrimitiveType( Qt3DRender::QGeometryRenderer::PrimitiveType::Triangles );
72 renderer->setGeometry( geom );
73
74 addComponent( renderer );
75
76 mMaterial = new Qt3DRender::QMaterial( this );
77
78 Qt3DRender::QEffect *effect = new Qt3DRender::QEffect( this );
79 Qt3DRender::QTechnique *technique = new Qt3DRender::QTechnique( this );
80 Qt3DRender::QGraphicsApiFilter *graphicsApiFilter = technique->graphicsApiFilter();
81 graphicsApiFilter->setApi( Qt3DRender::QGraphicsApiFilter::Api::OpenGL );
82 graphicsApiFilter->setProfile( Qt3DRender::QGraphicsApiFilter::OpenGLProfile::CoreProfile );
83 graphicsApiFilter->setMajorVersion( 3 );
84 graphicsApiFilter->setMinorVersion( 1 );
85 Qt3DRender::QRenderPass *renderPass = new Qt3DRender::QRenderPass( this );
86 mShader = new Qt3DRender::QShaderProgram( this );
87
88 renderPass->setShaderProgram( mShader );
89
90 Qt3DRender::QDepthTest *depthTest = new Qt3DRender::QDepthTest( this );
91 depthTest->setDepthFunction( Qt3DRender::QDepthTest::Always );
92
93 renderPass->addRenderState( depthTest );
94
95 technique->addRenderPass( renderPass );
96
97 effect->addTechnique( technique );
98 mMaterial->setEffect( effect );
99
100 addComponent( mMaterial );
101
102 addComponent( layer );
103}
QgsRenderPassQuad(Qt3DRender::QLayer *layer, QNode *parent=nullptr)
Constructor.
Qt3DRender::QShaderProgram * mShader
Qt3DRender::QMaterial * mMaterial
Qt3DCore::QAttribute Qt3DQAttribute
Qt3DCore::QBuffer Qt3DQBuffer
Qt3DCore::QGeometry Qt3DQGeometry
Qt3DCore::QAttribute Qt3DQAttribute
Qt3DCore::QBuffer Qt3DQBuffer
Qt3DCore::QGeometry Qt3DQGeometry