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 };
53 const QByteArray vertexArr( (
const char * ) vert.constData(), vert.size() *
sizeof(
float ) );
56 vertexBuffer->setData( vertexArr );
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 );
67 geom->addAttribute( positionAttribute );
69 Qt3DRender::QGeometryRenderer *renderer =
new Qt3DRender::QGeometryRenderer(
this );
70 renderer->setPrimitiveType( Qt3DRender::QGeometryRenderer::PrimitiveType::Triangles );
71 renderer->setGeometry( geom );
73 addComponent( renderer );
75 mMaterial =
new Qt3DRender::QMaterial(
this );
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 );
87 renderPass->setShaderProgram(
mShader );
89 Qt3DRender::QDepthTest *depthTest =
new Qt3DRender::QDepthTest(
this );
90 depthTest->setDepthFunction( Qt3DRender::QDepthTest::Always );
92 renderPass->addRenderState( depthTest );
94 technique->addRenderPass( renderPass );
96 effect->addTechnique( technique );
101 addComponent( layer );