From 4598d28936d3a4772927d1e3a1534f872731b358 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 1 Jul 2018 13:05:39 +0300 Subject: [PATCH] Add functions to control environment map updates If the environment changes only very slowly or not at all, it may be desirable to not update the map every frame. --- source/environmentmap.cpp | 26 +++++++++++++++++++++++++- source/environmentmap.h | 4 ++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/source/environmentmap.cpp b/source/environmentmap.cpp index 95e2c439..9c4df092 100644 --- a/source/environmentmap.cpp +++ b/source/environmentmap.cpp @@ -1,8 +1,11 @@ +#include #include #include "environmentmap.h" #include "renderer.h" #include "texunit.h" +using namespace std; + namespace Msp { namespace GL { @@ -10,7 +13,9 @@ EnvironmentMap::EnvironmentMap(unsigned s, Renderable &r, Renderable &e): Effect(r), size(s), environment(e), - rendered(false) + rendered(false), + update_interval(1), + update_delay(0) { env_tex.storage(RGB, size); env_tex.set_wrap(CLAMP_TO_EDGE); @@ -34,6 +39,17 @@ void EnvironmentMap::set_depth_clip(float n, float f) camera.set_depth_clip(n, f); } +void EnvironmentMap::set_update_interval(unsigned i) +{ + update_interval = i; + update_delay = min(update_delay, update_interval-1); +} + +void EnvironmentMap::queue_update() +{ + update_delay = 0; +} + void EnvironmentMap::setup_frame(Renderer &renderer) { if(rendered) @@ -41,6 +57,14 @@ void EnvironmentMap::setup_frame(Renderer &renderer) rendered = true; renderable.setup_frame(renderer); + + if(update_delay) + { + if(update_interval) + --update_delay; + return; + } + update_delay = update_interval-1; environment.setup_frame(renderer); const Matrix *matrix = renderable.get_matrix(); diff --git a/source/environmentmap.h b/source/environmentmap.h index 5f3b6a14..6fdd3749 100644 --- a/source/environmentmap.h +++ b/source/environmentmap.h @@ -35,11 +35,15 @@ private: Camera camera; mutable ProgramData shdata; bool rendered; + unsigned update_interval; + unsigned update_delay; public: EnvironmentMap(unsigned size, Renderable &rend, Renderable &env); void set_depth_clip(float, float); + void set_update_interval(unsigned); + void queue_update(); virtual void setup_frame(Renderer &); virtual void finish_frame(); -- 2.45.2