From 2341b3575c874b1960814264fa759ad584bf3134 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 28 Jul 2019 02:05:55 +0300 Subject: [PATCH] Add an object LoD bias parameter to Renderer This could be used by environment map and similar effects to render the scene at lower detail. --- source/objectinstance.cpp | 5 +++++ source/objectinstance.h | 2 +- source/renderer.cpp | 8 +++++++- source/renderer.h | 4 ++++ 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/source/objectinstance.cpp b/source/objectinstance.cpp index 450c8106..ef4afffe 100644 --- a/source/objectinstance.cpp +++ b/source/objectinstance.cpp @@ -27,6 +27,11 @@ void ObjectInstance::setup_render(Renderer &renderer, const Tag &) const renderer.transform(matrix); } +unsigned ObjectInstance::get_level_of_detail(const Renderer &renderer) const +{ + return renderer.get_object_lod_bias(); +} + ObjectInstance::Loader::Loader(ObjectInstance &o): DataFile::ObjectLoader(o) diff --git a/source/objectinstance.h b/source/objectinstance.h index 6577dd2a..1ad221c7 100644 --- a/source/objectinstance.h +++ b/source/objectinstance.h @@ -51,7 +51,7 @@ public: anything. */ virtual void finish_render(Renderer &, const Tag &) const { } - virtual unsigned get_level_of_detail(const Renderer &) const { return 0; } + virtual unsigned get_level_of_detail(const Renderer &) const; }; } // namespace GL diff --git a/source/renderer.cpp b/source/renderer.cpp index cc00ac8e..90ac4551 100644 --- a/source/renderer.cpp +++ b/source/renderer.cpp @@ -162,6 +162,11 @@ void Renderer::set_reverse_winding(bool r) state->reverse_winding = r; } +void Renderer::set_object_lod_bias(unsigned b) +{ + state->object_lod_bias = b; +} + void Renderer::push_state() { state_stack.push_back(state_stack.back()); @@ -449,7 +454,8 @@ Renderer::State::State(): mesh(0), vertex_setup(0), winding_test(0), - reverse_winding(false) + reverse_winding(false), + object_lod_bias(0) { } } // namespace GL diff --git a/source/renderer.h b/source/renderer.h index dbb2d490..973e1b00 100644 --- a/source/renderer.h +++ b/source/renderer.h @@ -81,6 +81,7 @@ private: const VertexSetup *vertex_setup; const WindingTest *winding_test; bool reverse_winding; + unsigned object_lod_bias; State(); }; @@ -155,6 +156,9 @@ public: void set_winding_test(const WindingTest *); void set_reverse_winding(bool); + void set_object_lod_bias(unsigned); + unsigned get_object_lod_bias() const { return state->object_lod_bias; } + /** Saves the current state so it can be restored later. */ void push_state(); -- 2.45.2