46 #include <Qt3DCore/QNode>
47 #include <Qt3DRender/QRenderSurfaceSelector>
48 #include <Qt3DRender/QClearBuffers>
49 #include <Qt3DRender/QNoDraw>
50 #include <Qt3DRender/QDispatchCompute>
51 #include <Qt3DRender/QTechniqueFilter>
52 #include <Qt3DRender/QCameraSelector>
53 #include <Qt3DRender/QMemoryBarrier>
54 #include <Qt3DRender/QFilterKey>
55 #include <Qt3DRender/QCamera>
56 #include <Qt3DRender/QSortPolicy>
57 #include <Qt3DRender/QRenderStateSet>
58 #include <Qt3DRender/QDepthTest>
59 #include <Qt3DRender/QNoDepthMask>
60 #include <Qt3DRender/QBlendEquation>
61 #include <Qt3DRender/QBlendEquationArguments>
62 #include <Qt3DRender/QCullFace>
63 #include <Qt3DRender/QRenderCapture>
64 #include <QOpenGLVersionProfile>
74 using namespace DISP3DLIB;
75 using namespace Qt3DRender;
87 , m_pForwardTranspKey(new QFilterKey)
88 , m_pForwardKey(new QFilterKey)
89 , m_pForwardSortedKey(new QFilterKey)
90 , m_pComputeKey(new QFilterKey)
91 , m_pDepthTest(new QDepthTest)
92 , m_pCullFace(new QCullFace)
93 , m_pBlendEquation(new QBlendEquation)
94 , m_pBlendArguments(new QBlendEquationArguments)
95 , m_pNoDepthMask( new QNoDepthMask)
96 , m_bUseOpenGl4_3(false)
99 QOpenGLVersionProfile profile;
100 auto version = profile.version();
101 if ((version.first == 4 && version.second >= 3) || (version.first > 4)) {
102 m_bUseOpenGl4_3 =
true;
112 m_pSurfaceSelector->deleteLater();
113 m_pClearBuffers->deleteLater();
114 m_pNoDraw->deleteLater();
115 m_pDispatchCompute->deleteLater();
116 m_pComputeFilter->deleteLater();
117 m_pCameraSelector->deleteLater();
118 m_pForwardFilter->deleteLater();
119 m_pSortPolicy->deleteLater();
120 m_pForwardKey->deleteLater();
121 m_pComputeKey->deleteLater();
122 m_pForwardState->deleteLater();
123 m_pTransparentState->deleteLater();
124 m_pForwardSortedFilter->deleteLater();
125 m_pForwardSortedKey->deleteLater();
126 m_pForwardTranspFilter->deleteLater();
127 m_pForwardTranspKey->deleteLater();
128 m_pDepthTest->deleteLater();
129 m_pCullFace->deleteLater();
130 m_pBlendEquation->deleteLater();
131 m_pBlendArguments->deleteLater();
132 m_pNoDepthMask->deleteLater();
134 m_pMemoryBarrier->deleteLater();
142 m_pCameraSelector->setCamera(tCamera);
149 m_pDispatchCompute->setWorkGroupX(tX);
150 m_pDispatchCompute->setWorkGroupY(tY);
151 m_pDispatchCompute->setWorkGroupZ(tZ);
158 m_pClearBuffers->setClearColor(tColor);
165 return m_pCapture->requestCapture();
170 void CustomFrameGraph::init()
173 m_pSurfaceSelector =
new QRenderSurfaceSelector(
this);
176 m_pClearBuffers =
new QClearBuffers(m_pSurfaceSelector);
177 m_pNoDraw =
new QNoDraw(m_pClearBuffers);
180 m_pDispatchCompute =
new QDispatchCompute(m_pSurfaceSelector);
181 m_pComputeFilter =
new QTechniqueFilter(m_pDispatchCompute);
184 m_pCameraSelector =
new QCameraSelector(m_pSurfaceSelector);
186 if(m_bUseOpenGl4_3) {
187 m_pMemoryBarrier =
new QMemoryBarrier(m_pCameraSelector);
188 m_pForwardState =
new QRenderStateSet(m_pMemoryBarrier);
191 m_pMemoryBarrier->setWaitOperations(QMemoryBarrier::VertexAttributeArray);
194 m_pForwardState =
new QRenderStateSet(m_pCameraSelector);
197 m_pForwardFilter =
new QTechniqueFilter(m_pForwardState);
200 m_pTransparentState =
new QRenderStateSet(m_pForwardState);
201 m_pForwardTranspFilter =
new QTechniqueFilter(m_pTransparentState);
204 m_pForwardSortedFilter =
new QTechniqueFilter(m_pTransparentState);
205 m_pSortPolicy =
new QSortPolicy(m_pForwardSortedFilter);
206 m_pCapture =
new QRenderCapture(m_pSortPolicy);
209 this->setNormalizedRect(QRectF(0.0f, 0.0f, 1.0f, 1.0f));
212 m_pClearBuffers->setBuffers(QClearBuffers::ColorDepthBuffer);
213 m_pClearBuffers->setClearColor(Qt::black);
216 m_pDepthTest->setDepthFunction(QDepthTest::Less);
217 m_pForwardState->addRenderState(m_pDepthTest);
218 m_pCullFace->setMode(QCullFace::Back);
219 m_pForwardState->addRenderState(m_pCullFace);
222 m_pBlendArguments->setSourceRgb(QBlendEquationArguments::SourceAlpha);
223 m_pBlendArguments->setDestinationRgb(QBlendEquationArguments::OneMinusSourceAlpha);
224 m_pBlendEquation->setBlendFunction(QBlendEquation::Add);
225 m_pTransparentState->addRenderState(m_pBlendArguments);
226 m_pTransparentState->addRenderState(m_pBlendEquation);
227 m_pTransparentState->addRenderState(m_pNoDepthMask);
230 m_pComputeKey->setName(QStringLiteral(
"renderingStyle"));
231 m_pComputeKey->setValue(QStringLiteral(
"compute"));
233 m_pForwardTranspKey->setName(QStringLiteral(
"renderingStyle"));
234 m_pForwardTranspKey->setValue(QStringLiteral(
"forwardTransparent"));
236 m_pForwardKey->setName(QStringLiteral(
"renderingStyle"));
237 m_pForwardKey->setValue(QStringLiteral(
"forward"));
239 m_pForwardSortedKey->setName(QStringLiteral(
"renderingStyle"));
240 m_pForwardSortedKey->setValue(QStringLiteral(
"forwardSorted"));
243 m_pComputeFilter->addMatch(m_pComputeKey);
244 m_pForwardFilter->addMatch(m_pForwardKey);
245 m_pForwardSortedFilter->addMatch(m_pForwardSortedKey);
246 m_pForwardTranspFilter->addMatch(m_pForwardTranspKey);
249 QVector<QSortPolicy::SortType> sortTypes = {QSortPolicy::StateChangeCost, QSortPolicy::BackToFront};
250 m_pSortPolicy->setSortTypes(sortTypes);