From 0b2821d696dba4cd12a518d7469a4bb216b7511f Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 5 May 2016 10:28:21 +0200 Subject: [PATCH] - added dynamic light rendering with textures on flats --- src/gl/compatibility/gl_20.cpp | 77 ++++++++++++++++++++-------------- src/gl/scene/gl_flats.cpp | 5 +++ src/gl/scene/gl_wall.h | 7 +++- 3 files changed, 56 insertions(+), 33 deletions(-) diff --git a/src/gl/compatibility/gl_20.cpp b/src/gl/compatibility/gl_20.cpp index e69ce961eb..5c7c983d30 100644 --- a/src/gl/compatibility/gl_20.cpp +++ b/src/gl/compatibility/gl_20.cpp @@ -582,20 +582,12 @@ void GLWall::RenderFogBoundaryCompat() // Flats // //========================================================================== -enum -{ - LIGHTPASS_MULT, - LIGHTPASS_ADD, - LIGHTPASS_FOG -}; void GLFlat::DrawSubsectorLights(subsector_t * sub, int pass) { Plane p; Vector nearPt, up, right, t1; float scale; - unsigned int k; - seg_t *v; FLightNode * node = sub->lighthead; gl_RenderState.Apply(); @@ -603,33 +595,13 @@ void GLFlat::DrawSubsectorLights(subsector_t * sub, int pass) { ADynamicLight * light = node->lightsource; - if (light->flags2&MF2_DORMANT) + if (light->flags2&MF2_DORMANT || + (pass == GLPASS_LIGHTTEX && light->IsAdditive()) || + (pass == GLPASS_LIGHTTEX_ADDITIVE && !light->IsAdditive())) { node = node->nextLight; continue; } - switch (pass) - { - case LIGHTPASS_MULT: - if (light->IsAdditive()) - { - node = node->nextLight; - continue; - } - break; - - case LIGHTPASS_ADD: - if (!light->IsAdditive()) - { - node = node->nextLight; - continue; - } - break; - - default: - break; - } - // we must do the side check here because gl_SetupLight needs the correct plane orientation // which we don't have for Legacy-style 3D-floors @@ -666,6 +638,49 @@ void GLFlat::DrawSubsectorLights(subsector_t * sub, int pass) } } +//========================================================================== +// +// +// +//========================================================================== + +void GLFlat::DrawLightsCompat(int pass) +{ + gl_RenderState.Apply(); + if (sub) + { + // This represents a single subsector + DrawSubsectorLights(sub, pass); + } + else + { + // Draw the subsectors belonging to this sector + for (int i = 0; isubsectorcount; i++) + { + subsector_t * sub = sector->subsectors[i]; + if (gl_drawinfo->ss_renderflags[sub - subsectors] & renderflags) + { + DrawSubsectorLights(sub, pass); + } + } + + // Draw the subsectors assigned to it due to missing textures + if (!(renderflags&SSRF_RENDER3DPLANES)) + { + gl_subsectorrendernode * node = (renderflags&SSRF_RENDERFLOOR) ? + gl_drawinfo->GetOtherFloorPlanes(sector->sectornum) : + gl_drawinfo->GetOtherCeilingPlanes(sector->sectornum); + + while (node) + { + DrawSubsectorLights(sub, pass); + node = node->next; + } + } + } +} + + //========================================================================== // // diff --git a/src/gl/scene/gl_flats.cpp b/src/gl/scene/gl_flats.cpp index 6b6f0e4a9b..850a936154 100644 --- a/src/gl/scene/gl_flats.cpp +++ b/src/gl/scene/gl_flats.cpp @@ -443,6 +443,11 @@ void GLFlat::Draw(int pass, bool trans) // trans only has meaning for GLPASS_LIG } if (renderstyle==STYLE_Add) gl_RenderState.BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); break; + + case GLPASS_LIGHTTEX: + case GLPASS_LIGHTTEX_ADDITIVE: + DrawLightsCompat(pass); + break; } } diff --git a/src/gl/scene/gl_wall.h b/src/gl/scene/gl_wall.h index cb443cd2af..3bdcbd6ce9 100644 --- a/src/gl/scene/gl_wall.h +++ b/src/gl/scene/gl_wall.h @@ -296,15 +296,18 @@ public: int dynlightindex; + // compatibility fallback stuff. + void DrawSubsectorLights(subsector_t * sub, int pass); + void DrawLightsCompat(int pass); + bool PutFlatCompat(bool fog); + void SetupSubsectorLights(int pass, subsector_t * sub, int *dli = NULL); void DrawSubsector(subsector_t * sub); - void DrawSubsectorLights(subsector_t * sub, int pass); void DrawSkyboxSector(int pass, bool processlights); void DrawSubsectors(int pass, bool processlights, bool istrans); void ProcessLights(bool istrans); void PutFlat(bool fog = false); - bool PutFlatCompat(bool fog); void Process(sector_t * model, int whichplane, bool notexture); void SetFrom3DFloor(F3DFloor *rover, bool top, bool underside); void ProcessSector(sector_t * frontsector);