summaryrefslogtreecommitdiff
path: root/renderer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'renderer.cpp')
-rw-r--r--renderer.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/renderer.cpp b/renderer.cpp
index c7040ec..64c3795 100644
--- a/renderer.cpp
+++ b/renderer.cpp
@@ -5,6 +5,8 @@ extern "C" {
#include "memory.h"
}
+#include <algorithm>
+
struct VP_Cbuffer {
m4f view_projection;
};
@@ -91,6 +93,21 @@ void Drawlist::render(
}
}
+void Drawlist::sort(const Renderer& r) {
+ const Camera& cam = r.get_camera(camera);
+ v3f far = cam.position + cam.far * cam.forward;
+ /* ideally want to sort the meshes within each model as
+ * well but as long as the models are small it wont matter
+ * too much... */
+ std::sort(
+ models,
+ models + count,
+ [&far](const Model_Instance* a, const Model_Instance* b) {
+ return v3f::dot(a->centre, far) < v3f::dot(b->centre, far);
+ }
+ );
+}
+
void Renderer::update_globals(
const Lighting* l,
Device* d,
@@ -136,6 +153,8 @@ void Renderer::render(
.build_rp();
}
+ drawlists[FORWARD].sort(*this);
+
ctx.debug_push("depth prepass");
drawlists[FORWARD].render(*this, dev, a, l, depth_prepass, 0);
ctx.debug_pop();