diff options
author | Paul Lemire <paul.lemire@kdab.com> | 2019-02-28 11:54:59 +0100 |
---|---|---|
committer | Paul Lemire <paul.lemire@kdab.com> | 2019-03-06 14:12:15 +0000 |
commit | f875e7156fa4a2772a6622949877db66aebdacca (patch) | |
tree | b837afa3c36de0a1d94db0bbebfd3a4aa654d517 /tests/auto/render/renderviews | |
parent | a356d132b2a426ecd7edb7858245266433b3e855 (diff) |
QSortPolicy: add sorting by Texture
It can be more efficient to render a scene by sorting drawing commands based on
the textures they are requiring. In conjunction with Material sorting, this can
reduce the amount of GL calls being sent to the driver.
[ChangeLog][Qt3DRender] QSortPolicy can now sort by Texture
Change-Id: Ibc013e9d506ea3061b19a56c548e8184f2b981cc
Reviewed-by: Mike Krus <mike.krus@kdab.com>
Diffstat (limited to 'tests/auto/render/renderviews')
-rw-r--r-- | tests/auto/render/renderviews/tst_renderviews.cpp | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/tests/auto/render/renderviews/tst_renderviews.cpp b/tests/auto/render/renderviews/tst_renderviews.cpp index 3039eaa02..dd03887b8 100644 --- a/tests/auto/render/renderviews/tst_renderviews.cpp +++ b/tests/auto/render/renderviews/tst_renderviews.cpp @@ -406,6 +406,85 @@ private Q_SLOTS: // RenderCommands are deleted by RenderView dtor } + void checkRenderCommandTextureSorting() + { + // GIVEN + RenderView renderView; + QVector<QSortPolicy::SortType> sortTypes; + + sortTypes.push_back(QSortPolicy::Texture); + + + Qt3DCore::QNodeId tex1 = Qt3DCore::QNodeId::createId(); + Qt3DCore::QNodeId tex2 = Qt3DCore::QNodeId::createId(); + Qt3DCore::QNodeId tex3 = Qt3DCore::QNodeId::createId(); + Qt3DCore::QNodeId tex4 = Qt3DCore::QNodeId::createId(); + + RenderCommand *a = new RenderCommand(); + { + ShaderParameterPack pack; + pack.setTexture(0, 0, tex1); + pack.setTexture(1, 0, tex3); + pack.setTexture(2, 0, tex4); + pack.setTexture(3, 0, tex2); + a->m_parameterPack = pack; + } + RenderCommand *b = new RenderCommand(); + RenderCommand *c = new RenderCommand(); + { + ShaderParameterPack pack; + pack.setTexture(0, 0, tex1); + pack.setTexture(3, 0, tex2); + c->m_parameterPack = pack; + } + RenderCommand *d = new RenderCommand(); + { + ShaderParameterPack pack; + pack.setTexture(1, 0, tex3); + pack.setTexture(2, 0, tex4); + d->m_parameterPack = pack; + } + RenderCommand *e = new RenderCommand(); + { + ShaderParameterPack pack; + pack.setTexture(3, 0, tex2); + e->m_parameterPack = pack; + } + RenderCommand *f = new RenderCommand(); + { + ShaderParameterPack pack; + pack.setTexture(3, 0, tex2); + f->m_parameterPack = pack; + } + RenderCommand *g = new RenderCommand(); + { + ShaderParameterPack pack; + pack.setTexture(0, 0, tex1); + pack.setTexture(1, 0, tex3); + pack.setTexture(2, 0, tex4); + pack.setTexture(3, 0, tex2); + g->m_parameterPack = pack; + } + + // WHEN + QVector<RenderCommand *> rawCommands = {a, b, c, d, e, f, g}; + renderView.addSortType(sortTypes); + renderView.setCommands(rawCommands); + renderView.sort(); + + // THEN + const QVector<RenderCommand *> sortedCommands = renderView.commands(); + qDebug() << rawCommands << sortedCommands; + QCOMPARE(rawCommands.size(), sortedCommands.size()); + QCOMPARE(sortedCommands.at(0), a); + QCOMPARE(sortedCommands.at(1), g); + QCOMPARE(sortedCommands.at(2), d); + QCOMPARE(sortedCommands.at(3), c); + QCOMPARE(sortedCommands.at(4), e); + QCOMPARE(sortedCommands.at(5), f); + QCOMPARE(sortedCommands.at(6), b); + // RenderCommands are deleted by RenderView dtor + } private: }; |