From ad2993950a525fd5ef742c77d1deb563b72e9511 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 25 Dec 2016 12:58:29 +0100 Subject: [PATCH 1/6] - fixed light level calculation for low light levels. --- src/gl/renderer/gl_lightdata.cpp | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/gl/renderer/gl_lightdata.cpp b/src/gl/renderer/gl_lightdata.cpp index 25ad12344..ca2d32c41 100644 --- a/src/gl/renderer/gl_lightdata.cpp +++ b/src/gl/renderer/gl_lightdata.cpp @@ -196,14 +196,30 @@ int gl_CalcLightLevel(int lightlevel, int rellight, bool weapon) if ((glset.lightmode & 2) && lightlevel < 192 && !weapon) { - light = xs_CRoundToInt(192.f - (192-lightlevel)* 1.95f); + if (lightlevel > 100) + { + light = xs_CRoundToInt(192.f - (192 - lightlevel)* 1.87f); + if (light + rellight < 20) + { + light = 20 + (light + rellight - 20) / 5; + } + else + { + light += rellight; + } + } + else + { + light = (lightlevel + rellight) / 5; + } + } else { - light=lightlevel; + light=lightlevel+rellight; } - return clamp(light+rellight, 0, 255); + return clamp(light, 0, 255); } //========================================================================== From c5d75c18b419b962e3868b8a2dda138909dc9d07 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 25 Dec 2016 22:56:18 +0100 Subject: [PATCH 2/6] - make gl_finishbeforeswap more useful by handling the case where it causes stalls on NVidia. --- src/gl/scene/gl_scene.cpp | 2 ++ src/gl/system/gl_framebuffer.cpp | 9 ++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/gl/scene/gl_scene.cpp b/src/gl/scene/gl_scene.cpp index 5b969d7b9..5cca167d3 100644 --- a/src/gl/scene/gl_scene.cpp +++ b/src/gl/scene/gl_scene.cpp @@ -91,6 +91,7 @@ extern bool r_showviewer; DWORD gl_fixedcolormap; area_t in_area; TArray currentmapsection; +int camtexcount; void gl_ParseDefs(); @@ -1356,6 +1357,7 @@ void FGLInterface::RenderTextureView (FCanvasTexture *tex, AActor *Viewpoint, in } tex->SetUpdated(); + camtexcount++; } //========================================================================== diff --git a/src/gl/system/gl_framebuffer.cpp b/src/gl/system/gl_framebuffer.cpp index f20c9e502..6d4fdcff8 100644 --- a/src/gl/system/gl_framebuffer.cpp +++ b/src/gl/system/gl_framebuffer.cpp @@ -207,22 +207,25 @@ void OpenGLFrameBuffer::Update() // //========================================================================== -CVAR(Bool, gl_finishbeforeswap, false, 0); +CVAR(Bool, gl_finishbeforeswap, false, CVAR_ARCHIVE|CVAR_GLOBALCONFIG); +extern int camtexcount; void OpenGLFrameBuffer::Swap() { + bool swapbefore = gl_finishbeforeswap && camtexcount == 0; Finish.Reset(); Finish.Clock(); - if (gl_finishbeforeswap) glFinish(); + if (swapbefore) glFinish(); if (needsetgamma) { //DoSetGamma(); needsetgamma = false; } SwapBuffers(); - if (!gl_finishbeforeswap) glFinish(); + if (!swapbefore) glFinish(); Finish.Unclock(); swapped = true; + camtexcount = 0; FHardwareTexture::UnbindAll(); mDebug->Update(); } From 6f16597668f2335ada5008225b8ad5afdd504cec Mon Sep 17 00:00:00 2001 From: ZZYZX Date: Mon, 26 Dec 2016 00:23:05 +0200 Subject: [PATCH 3/6] GL renderer now uses RenderRadius links too --- src/gl/scene/gl_bsp.cpp | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/gl/scene/gl_bsp.cpp b/src/gl/scene/gl_bsp.cpp index f0ddfd642..85cd35bf5 100644 --- a/src/gl/scene/gl_bsp.cpp +++ b/src/gl/scene/gl_bsp.cpp @@ -363,20 +363,26 @@ static inline void RenderThings(subsector_t * sub, sector_t * sector) SetupSprite.Clock(); sector_t * sec=sub->sector; // Handle all things in sector. - for (AActor * thing = sec->thinglist; thing; thing = thing->snext) + if (sec->touching_render_things) { - FIntCVar *cvar = thing->GetClass()->distancecheck; - if (cvar != NULL && *cvar >= 0) + for (auto thing : *sec->touching_render_things) { - double dist = (thing->Pos() - ViewPos).LengthSquared(); - double check = (double)**cvar; - if (dist >= check * check) - { - continue; - } - } + if (thing->validcount == validcount) continue; + thing->validcount = validcount; - GLRenderer->ProcessSprite(thing, sector, false); + FIntCVar *cvar = thing->GetClass()->distancecheck; + if (cvar != NULL && *cvar >= 0) + { + double dist = (thing->Pos() - ViewPos).LengthSquared(); + double check = (double)**cvar; + if (dist >= check * check) + { + continue; + } + } + + GLRenderer->ProcessSprite(thing, sector, false); + } } for (msecnode_t *node = sec->render_thinglist; node; node = node->m_snext) { From f5883d3f86364706bb8649d8718276f1490c9a3e Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 26 Dec 2016 12:02:09 +0100 Subject: [PATCH 4/6] - fixed: DynamicLight needs a render radius of -1 so that it gets excluded from the touching_renderlist. --- wadsrc/static/zscript/shared/dynlights.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/wadsrc/static/zscript/shared/dynlights.txt b/wadsrc/static/zscript/shared/dynlights.txt index 578354130..f851d88d0 100644 --- a/wadsrc/static/zscript/shared/dynlights.txt +++ b/wadsrc/static/zscript/shared/dynlights.txt @@ -5,6 +5,7 @@ class DynamicLight : Actor native Height 0; Radius 0.1; FloatBobPhase 0; + RenderRadius -1; +NOBLOCKMAP +NOGRAVITY +FIXMAPTHINGPOS From be508bc6700b559823d21082f8608cc9a33a9c91 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 26 Dec 2016 12:11:55 +0100 Subject: [PATCH 5/6] - adjust to using msecnode_t's. --- src/gl/scene/gl_bsp.cpp | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/src/gl/scene/gl_bsp.cpp b/src/gl/scene/gl_bsp.cpp index 85cd35bf5..9e5ea258d 100644 --- a/src/gl/scene/gl_bsp.cpp +++ b/src/gl/scene/gl_bsp.cpp @@ -363,27 +363,26 @@ static inline void RenderThings(subsector_t * sub, sector_t * sector) SetupSprite.Clock(); sector_t * sec=sub->sector; // Handle all things in sector. - if (sec->touching_render_things) + for (auto p = sec->touching_renderthings; p != nullptr; p = p->m_snext) { - for (auto thing : *sec->touching_render_things) + auto thing = p->m_thing; + if (thing->validcount == validcount) continue; + thing->validcount = validcount; + + FIntCVar *cvar = thing->GetClass()->distancecheck; + if (cvar != NULL && *cvar >= 0) { - if (thing->validcount == validcount) continue; - thing->validcount = validcount; - - FIntCVar *cvar = thing->GetClass()->distancecheck; - if (cvar != NULL && *cvar >= 0) + double dist = (thing->Pos() - ViewPos).LengthSquared(); + double check = (double)**cvar; + if (dist >= check * check) { - double dist = (thing->Pos() - ViewPos).LengthSquared(); - double check = (double)**cvar; - if (dist >= check * check) - { - continue; - } + continue; } - - GLRenderer->ProcessSprite(thing, sector, false); } + + GLRenderer->ProcessSprite(thing, sector, false); } + for (msecnode_t *node = sec->render_thinglist; node; node = node->m_snext) { AActor *thing = node->m_thing; From 3f7c057f9207fed87ffff41123c745cd8846d132 Mon Sep 17 00:00:00 2001 From: Edoardo Prezioso Date: Mon, 26 Dec 2016 10:39:03 +0100 Subject: [PATCH 6/6] - Fixed heap use after free issue with lights. --- src/gl/dynlights/a_dynlight.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/gl/dynlights/a_dynlight.cpp b/src/gl/dynlights/a_dynlight.cpp index 4ba95af87..114633b3f 100644 --- a/src/gl/dynlights/a_dynlight.cpp +++ b/src/gl/dynlights/a_dynlight.cpp @@ -599,7 +599,6 @@ void ADynamicLight::CollectWithinRadius(const DVector3 &opos, subsector_t *subSe for (unsigned i = 0; i < collected_ss.Size(); i++) { subSec = collected_ss[i].sub; - auto &pos = collected_ss[i].pos; touching_subsectors = AddLightNode(&subSec->lighthead, subSec, this, touching_subsectors); if (subSec->sector->validcount != ::validcount) @@ -608,9 +607,10 @@ void ADynamicLight::CollectWithinRadius(const DVector3 &opos, subsector_t *subSe subSec->sector->validcount = ::validcount; } - for (unsigned int i = 0; i < subSec->numlines; i++) + for (unsigned int j = 0; j < subSec->numlines; ++j) { - seg_t * seg = subSec->firstline + i; + auto &pos = collected_ss[i].pos; + seg_t *seg = subSec->firstline + j; // check distance from x/y to seg and if within radius add this seg and, if present the opposing subsector (lather/rinse/repeat) // If out of range we do not need to bother with this seg.