QGIS API Documentation 3.36.0-Maidenhead (09951dc0acf)
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
18#include <random>
19
20#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
21#include <Qt3DRender/QAttribute>
22#include <Qt3DRender/QBuffer>
23#include <Qt3DRender/QGeometry>
24
25typedef Qt3DRender::QAttribute Qt3DQAttribute;
26typedef Qt3DRender::QBuffer Qt3DQBuffer;
27typedef Qt3DRender::QGeometry Qt3DQGeometry;
28#else
29#include <Qt3DCore/QAttribute>
30#include <Qt3DCore/QBuffer>
31#include <Qt3DCore/QGeometry>
32
33typedef Qt3DCore::QAttribute Qt3DQAttribute;
34typedef Qt3DCore::QBuffer Qt3DQBuffer;
35typedef Qt3DCore::QGeometry Qt3DQGeometry;
36#endif
37
38#include <Qt3DRender/QGeometryRenderer>
39#include <Qt3DRender/QTechnique>
40#include <Qt3DRender/QGraphicsApiFilter>
41#include <Qt3DRender/QDepthTest>
42#include <Qt3DRender/QEffect>
43#include <QUrl>
44#include <QVector3D>
45
47 : Qt3DCore::QEntity( parent )
48{
49 Qt3DQGeometry *geom = new Qt3DQGeometry( this );
50 Qt3DQAttribute *positionAttribute = new Qt3DQAttribute( this );
51 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 };
52
53 const QByteArray vertexArr( ( const char * ) vert.constData(), vert.size() * sizeof( float ) );
54 Qt3DQBuffer *vertexBuffer = nullptr;
55 vertexBuffer = new Qt3DQBuffer( this );
56 vertexBuffer->setData( vertexArr );
57
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 );
66
67 geom->addAttribute( positionAttribute );
68
69 Qt3DRender::QGeometryRenderer *renderer = new Qt3DRender::QGeometryRenderer( this );
70 renderer->setPrimitiveType( Qt3DRender::QGeometryRenderer::PrimitiveType::Triangles );
71 renderer->setGeometry( geom );
72
73 addComponent( renderer );
74
75 mMaterial = new Qt3DRender::QMaterial( this );
76
77 Qt3DRender::QEffect *effect = new Qt3DRender::QEffect( this );
78 Qt3DRender::QTechnique *technique = new Qt3DRender::QTechnique( this );
79 Qt3DRender::QGraphicsApiFilter *graphicsApiFilter = technique->graphicsApiFilter();
80 graphicsApiFilter->setApi( Qt3DRender::QGraphicsApiFilter::Api::OpenGL );
81 graphicsApiFilter->setProfile( Qt3DRender::QGraphicsApiFilter::OpenGLProfile::CoreProfile );
82 graphicsApiFilter->setMajorVersion( 3 );
83 graphicsApiFilter->setMinorVersion( 1 );
84 Qt3DRender::QRenderPass *renderPass = new Qt3DRender::QRenderPass( this );
85 mShader = new Qt3DRender::QShaderProgram( this );
86
87 renderPass->setShaderProgram( mShader );
88
89 Qt3DRender::QDepthTest *depthTest = new Qt3DRender::QDepthTest( this );
90 depthTest->setDepthFunction( Qt3DRender::QDepthTest::Always );
91
92 renderPass->addRenderState( depthTest );
93
94 technique->addRenderPass( renderPass );
95
96 effect->addTechnique( technique );
97 mMaterial->setEffect( effect );
98
99 addComponent( mMaterial );
100
101 mLayer = new Qt3DRender::QLayer( this );
102 mLayer->setRecursive( true );
103 addComponent( mLayer );
104}
105
Qt3DRender::QLayer * mLayer
QgsRenderPassQuad(QNode *parent=nullptr)
Constructor.
Qt3DRender::QShaderProgram * mShader
Qt3DRender::QMaterial * mMaterial
Qt3DCore::QAttribute Qt3DQAttribute
Definition qgs3daxis.cpp:28
Qt3DCore::QBuffer Qt3DQBuffer
Definition qgs3daxis.cpp:30
Qt3DCore::QGeometry Qt3DQGeometry
Definition qgs3daxis.cpp:29
Qt3DCore::QAttribute Qt3DQAttribute
Qt3DCore::QBuffer Qt3DQBuffer
Qt3DCore::QGeometry Qt3DQGeometry