Add an object LoD bias parameter to Renderer
authorMikko Rasa <tdb@tdb.fi>
Sat, 27 Jul 2019 23:05:55 +0000 (02:05 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sat, 27 Jul 2019 23:05:55 +0000 (02:05 +0300)
This could be used by environment map and similar effects to render the
scene at lower detail.

source/objectinstance.cpp
source/objectinstance.h
source/renderer.cpp
source/renderer.h

index 450c810646f23b5b8439de2e6275730432ea73e4..ef4afffeeab8c5a97753ab6800417d6c15478e4a 100644 (file)
@@ -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<ObjectInstance>(o)
index 6577dd2a6265f6ca241d88dc2bf9337447d40afc..1ad221c78e9f3796c22e2d04ae52817fec477b8b 100644 (file)
@@ -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
index cc00ac8e3affda145ec8e2f8afcc5c1d7bb4af40..90ac455107ffc078a6db1dbe8e452ea06ed44f7a 100644 (file)
@@ -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
index dbb2d4905cf57ab2e3c18ef76816af577851da3b..973e1b00263330101aca291ccef3c38a75e5e82c 100644 (file)
@@ -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();