Skip to content

Commit

Permalink
Main: QueuedRenderableCollection - sort instanced groups
Browse files Browse the repository at this point in the history
as it improves instancing efficiency
  • Loading branch information
paroj committed Jul 26, 2024
1 parent 7f4feb3 commit e6bbedf
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions OgreMain/src/OgreRenderQueueSortingGrouping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ THE SOFTWARE.
*/
#include "OgreStableHeaders.h"
#include "OgreRenderQueueSortingGrouping.h"
#include <algorithm>

namespace Ogre {
namespace {
Expand Down Expand Up @@ -358,9 +359,26 @@ namespace {
DistanceSortDescendingLess(cam));
}
}

// Nothing needs to be done for pass groups, they auto-organise

else if (mOrganisationMode & OM_PASS_GROUP)
{
// sort
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();
});
}
}
}
//-----------------------------------------------------------------------
void QueuedRenderableCollection::addRenderable(Pass* pass, Renderable* rend)
Expand Down

0 comments on commit e6bbedf

Please sign in to comment.