Commit 2a9499a7 authored by Hans-Christian Ebke's avatar Hans-Christian Ebke
Browse files

Replaced super slow qsort by much faster std::sort.

std::sort is a template function so the compiler can inline the comparator
avoiding unnecessary calls. In contrast, qsort is a non-template function
taking a function pointer which results in one function call per comparison
operation.
parent 309206ea
Pipeline #2907 failed with stage
in 56 minutes and 47 seconds
...@@ -473,16 +473,6 @@ void IRenderer::traverseRenderableNodes( ACG::GLState* _glState, ACG::SceneGraph ...@@ -473,16 +473,6 @@ void IRenderer::traverseRenderableNodes( ACG::GLState* _glState, ACG::SceneGraph
} }
} }
int IRenderer::cmpPriority(const void* _a, const void* _b)
{
const ACG::RenderObject* a = *(const ACG::RenderObject**)_a;
const ACG::RenderObject* b = *(const ACG::RenderObject**)_b;
return a->priority - b->priority;
}
void IRenderer::prepareRenderingPipeline(ACG::GLState* _glState, ACG::SceneGraph::DrawModes::DrawMode _drawMode, ACG::SceneGraph::BaseNode* _scenegraphRoot) void IRenderer::prepareRenderingPipeline(ACG::GLState* _glState, ACG::SceneGraph::DrawModes::DrawMode _drawMode, ACG::SceneGraph::BaseNode* _scenegraphRoot)
{ {
// grab view transform from glstate // grab view transform from glstate
...@@ -752,10 +742,13 @@ void IRenderer::clearInputFbo( const ACG::Vec4f& clearColor ) ...@@ -752,10 +742,13 @@ void IRenderer::clearInputFbo( const ACG::Vec4f& clearColor )
void IRenderer::sortRenderObjects() void IRenderer::sortRenderObjects()
{ {
if (!sortedObjects_.empty()) struct RenderObjectComparator {
qsort(&sortedObjects_[0], sortedObjects_.size(), sizeof(ACG::RenderObject*), cmpPriority); bool operator() (ACG::RenderObject *a, ACG::RenderObject * b) {
if (!overlayObjects_.empty()) return (a->priority < b->priority);
qsort(&overlayObjects_[0], overlayObjects_.size(), sizeof(ACG::RenderObject*), cmpPriority); }
};
std::sort(sortedObjects_.begin(), sortedObjects_.end(), RenderObjectComparator());
std::sort(overlayObjects_.begin(), overlayObjects_.end(), RenderObjectComparator());
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment