Skip to content

Commit

Permalink
Main: QueuedRenderableCollection - cluster instead of sorting
Browse files Browse the repository at this point in the history
reduces asymptotic complexity and is faster
  • Loading branch information
paroj committed Jul 27, 2024
1 parent e6bbedf commit 5bcfd92
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions OgreMain/src/OgreRenderQueueSortingGrouping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ THE SOFTWARE.
#include "OgreStableHeaders.h"
#include "OgreRenderQueueSortingGrouping.h"
#include <algorithm>
#include <unordered_map>

namespace Ogre {
namespace {
Expand Down Expand Up @@ -361,25 +362,29 @@ namespace {
}
else if (mOrganisationMode & OM_PASS_GROUP)
{
// sort
// cluster by submesh
for(auto& it : mGrouped)
{
auto instanced = it.first->hasVertexProgram() && it.first->getVertexProgram()->isInstancingIncluded();
if (!instanced)
continue;

std::sort(it.second.begin(), it.second.end(),
[](const Renderable* a, const Renderable* b)
{
auto sa = dynamic_cast<const SubEntity*>(a);
auto sb = dynamic_cast<const SubEntity*>(b);
if (!sa || !sb)
return a < b;
return sa->getSubMesh() < sb->getSubMesh();
});

std::unordered_map<SubMesh*, RenderableList> bySubMesh;
for (auto* rend : it.second)
{
auto subEntity = dynamic_cast<SubEntity*>(rend);
SubMesh* subMesh = subEntity ? subEntity->getSubMesh() : 0;
bySubMesh[subMesh].push_back(rend);
}
it.second.clear();
for (auto& it2 : bySubMesh)
{
it.second.insert(it.second.end(), it2.second.begin(), it2.second.end());
}
}
}
}

//-----------------------------------------------------------------------
void QueuedRenderableCollection::addRenderable(Pass* pass, Renderable* rend)
{
Expand Down

0 comments on commit 5bcfd92

Please sign in to comment.