From 4af5ea25c12d2f2be196b628334af9aef474352c Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 29 Jan 2019 20:09:06 +0100 Subject: [PATCH] - change per-level attenuation of dynamic lights for each viewpoint. To avoid unnecessary work, the current state is tracked. --- src/g_level.cpp | 2 -- src/g_shared/a_dynlight.h | 2 +- src/gl/renderer/gl_scene.cpp | 4 ++++ src/r_data/a_dynlightdata.cpp | 13 +++++++++---- src/r_data/gldefs.cpp | 2 ++ 5 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/g_level.cpp b/src/g_level.cpp index 5491367ad..3a29c2098 100644 --- a/src/g_level.cpp +++ b/src/g_level.cpp @@ -1552,8 +1552,6 @@ void FLevelLocals::Init() brightfog = info->brightfog < 0? gl_brightfog : !!info->brightfog; lightadditivesurfaces = info->lightadditivesurfaces < 0 ? gl_lightadditivesurfaces : !!info->lightadditivesurfaces; notexturefill = info->notexturefill < 0 ? gl_notexturefill : !!info->notexturefill; - - FLightDefaults::SetAttenuationForLevel(); } //========================================================================== diff --git a/src/g_shared/a_dynlight.h b/src/g_shared/a_dynlight.h index 25d6a3477..77c971942 100644 --- a/src/g_shared/a_dynlight.h +++ b/src/g_shared/a_dynlight.h @@ -76,7 +76,7 @@ public: void SetSpot(bool spot) { if (spot) m_lightFlags |= LF_SPOT; else m_lightFlags &= ~LF_SPOT; } void SetSpotInnerAngle(double angle) { m_spotInnerAngle = angle; } void SetSpotOuterAngle(double angle) { m_spotOuterAngle = angle; } - static void SetAttenuationForLevel(); + static void SetAttenuationForLevel(bool); void OrderIntensities() { diff --git a/src/gl/renderer/gl_scene.cpp b/src/gl/renderer/gl_scene.cpp index 8e6475c96..c62203be9 100644 --- a/src/gl/renderer/gl_scene.cpp +++ b/src/gl/renderer/gl_scene.cpp @@ -156,6 +156,10 @@ sector_t * FGLRenderer::RenderViewpoint (FRenderViewpoint &mainvp, AActor * came if (mainview && toscreen) UpdateShadowMap(); + // Update the attenuation flag of all light defaults for each viewpoint. + // This function will only do something if the setting differs. + FLightDefaults::SetAttenuationForLevel(!!(camera->Level->flags3 & LEVEL3_ATTENUATE)); + // Render (potentially) multiple views for stereo 3d // Fixme. The view offsetting should be done with a static table and not require setup of the entire render state for the mode. auto vrmode = VRMode::GetVRMode(mainview && toscreen); diff --git a/src/r_data/a_dynlightdata.cpp b/src/r_data/a_dynlightdata.cpp index f0b66f972..e6ed0c10b 100644 --- a/src/r_data/a_dynlightdata.cpp +++ b/src/r_data/a_dynlightdata.cpp @@ -55,6 +55,7 @@ inline PClassActor * GetRealType(PClassActor * ti) } TDeletingArray LightDefaults; +int AttenuationIsSet = -1; //----------------------------------------------------------------------------- // @@ -101,14 +102,18 @@ void FLightDefaults::ApplyProperties(FDynamicLight * light) const light->SetOffset(m_Pos); // this must be the last thing to do. } -void FLightDefaults::SetAttenuationForLevel() +void FLightDefaults::SetAttenuationForLevel(bool yes) { - for (auto ldef : LightDefaults) + if (AttenuationIsSet != int(yes)) { - if (ldef->m_attenuate == -1) + for (auto ldef : LightDefaults) { - if (level.flags3 & LEVEL3_ATTENUATE) ldef->m_lightFlags |= LF_ATTENUATE; else ldef->m_lightFlags &= ~LF_ATTENUATE; + if (ldef->m_attenuate == -1) + { + if (yes) ldef->m_lightFlags |= LF_ATTENUATE; else ldef->m_lightFlags &= ~LF_ATTENUATE; + } } + AttenuationIsSet = yes; } } diff --git a/src/r_data/gldefs.cpp b/src/r_data/gldefs.cpp index 054e299cd..e853ed6e4 100644 --- a/src/r_data/gldefs.cpp +++ b/src/r_data/gldefs.cpp @@ -53,6 +53,7 @@ void InitializeActorLights(TArray &LightAssociations); TArray usershaders; extern TDeletingArray LightDefaults; +extern int AttenuationIsSet; //----------------------------------------------------------------------------- @@ -1777,6 +1778,7 @@ void ParseGLDefs() const char *defsLump = NULL; LightDefaults.DeleteAndClear(); + AttenuationIsSet = -1; //gl_DestroyUserShaders(); function says 'todo' switch (gameinfo.gametype) {