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 };
54 const QByteArray vertexArr( (
const char * ) vert.constData(), vert.size() *
sizeof(
float ) );
57 vertexBuffer->setData( vertexArr );
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 );
68 geom->addAttribute( positionAttribute );
70 Qt3DRender::QGeometryRenderer *renderer =
new Qt3DRender::QGeometryRenderer(
this );
71 renderer->setPrimitiveType( Qt3DRender::QGeometryRenderer::PrimitiveType::Triangles );
72 renderer->setGeometry( geom );
74 addComponent( renderer );
76 mMaterial =
new Qt3DRender::QMaterial(
this );
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 );
88 renderPass->setShaderProgram(
mShader );
90 Qt3DRender::QDepthTest *depthTest =
new Qt3DRender::QDepthTest(
this );
91 depthTest->setDepthFunction( Qt3DRender::QDepthTest::Always );
93 renderPass->addRenderState( depthTest );
95 technique->addRenderPass( renderPass );
97 effect->addTechnique( technique );
102 addComponent( layer );