From 6285a309ce7c9c3412fae608f9958fb8be5cacd9 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 3 May 2018 21:47:58 +0200 Subject: [PATCH] - added UploadLights to the DrawInfo interface. - removed GLPASS_PLAIN because it was the same as GLPASS_ALL. --- src/gl/compatibility/gl_20.cpp | 16 ++++++++-------- src/gl/dynlights/gl_lightbuffer.h | 2 -- src/gl/scene/gl_drawinfo.cpp | 8 ++++++++ src/gl/scene/gl_drawinfo.h | 2 +- src/gl/scene/gl_flats.cpp | 3 +-- src/gl/scene/gl_sprite.cpp | 9 --------- src/gl/scene/gl_walls_draw.cpp | 1 - src/hwrenderer/scene/hw_drawinfo.h | 2 ++ src/hwrenderer/scene/hw_sprites.cpp | 11 +++++++++++ 9 files changed, 31 insertions(+), 23 deletions(-) diff --git a/src/gl/compatibility/gl_20.cpp b/src/gl/compatibility/gl_20.cpp index 72f38465f4..d6f06eda76 100644 --- a/src/gl/compatibility/gl_20.cpp +++ b/src/gl/compatibility/gl_20.cpp @@ -857,8 +857,8 @@ void GLSceneDrawer::RenderMultipassStuff() gl_RenderState.EnableTexture(false); gl_RenderState.EnableBrightmap(false); gl_RenderState.Apply(); - gl_drawinfo->dldrawlists[GLLDL_WALLS_PLAIN].DrawWalls(gl_drawinfo, GLPASS_PLAIN); - gl_drawinfo->dldrawlists[GLLDL_FLATS_PLAIN].DrawFlats(gl_drawinfo, GLPASS_PLAIN); + gl_drawinfo->dldrawlists[GLLDL_WALLS_PLAIN].DrawWalls(gl_drawinfo, GLPASS_ALL); + gl_drawinfo->dldrawlists[GLLDL_FLATS_PLAIN].DrawFlats(gl_drawinfo, GLPASS_ALL); // Part 2: masked geometry. This is set up so that only pixels with alpha>0.5 will show // This creates a blank surface that only fills the nontransparent parts of the texture @@ -866,18 +866,18 @@ void GLSceneDrawer::RenderMultipassStuff() gl_RenderState.SetTextureMode(TM_MASK); gl_RenderState.EnableBrightmap(true); gl_RenderState.AlphaFunc(GL_GEQUAL, gl_mask_threshold); - gl_drawinfo->dldrawlists[GLLDL_WALLS_MASKED].DrawWalls(gl_drawinfo, GLPASS_PLAIN); - gl_drawinfo->dldrawlists[GLLDL_FLATS_MASKED].DrawFlats(gl_drawinfo, GLPASS_PLAIN); + gl_drawinfo->dldrawlists[GLLDL_WALLS_MASKED].DrawWalls(gl_drawinfo, GLPASS_ALL); + gl_drawinfo->dldrawlists[GLLDL_FLATS_MASKED].DrawFlats(gl_drawinfo, GLPASS_ALL); // Part 3: The base of fogged surfaces, including the texture gl_RenderState.EnableBrightmap(false); gl_RenderState.SetTextureMode(TM_MODULATE); gl_RenderState.AlphaFunc(GL_GEQUAL, 0); - gl_drawinfo->dldrawlists[GLLDL_WALLS_FOG].DrawWalls(gl_drawinfo, GLPASS_PLAIN); - gl_drawinfo->dldrawlists[GLLDL_FLATS_FOG].DrawFlats(gl_drawinfo, GLPASS_PLAIN); + gl_drawinfo->dldrawlists[GLLDL_WALLS_FOG].DrawWalls(gl_drawinfo, GLPASS_ALL); + gl_drawinfo->dldrawlists[GLLDL_FLATS_FOG].DrawFlats(gl_drawinfo, GLPASS_ALL); gl_RenderState.AlphaFunc(GL_GEQUAL, gl_mask_threshold); - gl_drawinfo->dldrawlists[GLLDL_WALLS_FOGMASKED].DrawWalls(gl_drawinfo, GLPASS_PLAIN); - gl_drawinfo->dldrawlists[GLLDL_FLATS_FOGMASKED].DrawFlats(gl_drawinfo, GLPASS_PLAIN); + gl_drawinfo->dldrawlists[GLLDL_WALLS_FOGMASKED].DrawWalls(gl_drawinfo, GLPASS_ALL); + gl_drawinfo->dldrawlists[GLLDL_FLATS_FOGMASKED].DrawFlats(gl_drawinfo, GLPASS_ALL); // second pass: draw lights glDepthMask(false); diff --git a/src/gl/dynlights/gl_lightbuffer.h b/src/gl/dynlights/gl_lightbuffer.h index 49fc87cd9f..959dddcbd1 100644 --- a/src/gl/dynlights/gl_lightbuffer.h +++ b/src/gl/dynlights/gl_lightbuffer.h @@ -37,7 +37,5 @@ public: int gl_SetDynModelLight(AActor *self, int dynlightindex); -extern thread_local FDynLightData lightdata; - #endif diff --git a/src/gl/scene/gl_drawinfo.cpp b/src/gl/scene/gl_drawinfo.cpp index 9eec763deb..ea5a72e569 100644 --- a/src/gl/scene/gl_drawinfo.cpp +++ b/src/gl/scene/gl_drawinfo.cpp @@ -41,6 +41,7 @@ #include "gl/renderer/gl_renderstate.h" #include "gl/stereo3d/scoped_color_mask.h" #include "gl/renderer/gl_quaddrawer.h" +#include "gl/dynlights/gl_lightbuffer.h" FDrawInfo * gl_drawinfo; FDrawInfoList di_list; @@ -522,3 +523,10 @@ GLDecal *FDrawInfo::AddDecal(bool onmirror) return decal; } +int FDrawInfo::UploadLights(FDynLightData &data) +{ + return GLRenderer->mLights->UploadLights(data); +} + + + diff --git a/src/gl/scene/gl_drawinfo.h b/src/gl/scene/gl_drawinfo.h index ff592b9e4c..86be6200fa 100644 --- a/src/gl/scene/gl_drawinfo.h +++ b/src/gl/scene/gl_drawinfo.h @@ -48,7 +48,6 @@ enum Drawpasses { GLPASS_ALL, // Main pass with dynamic lights GLPASS_LIGHTSONLY, // only collect dynamic lights - GLPASS_PLAIN, // Main pass without dynamic lights GLPASS_DECALS, // Draws a decal GLPASS_TRANSLUCENT, // Draws translucent objects @@ -82,6 +81,7 @@ struct FDrawInfo : public HWDrawInfo void AddSprite(GLSprite *sprite, bool translucent) override; std::pair AllocVertices(unsigned int count) override; + int UploadLights(FDynLightData &data) override; // Legacy GL only. bool PutWallCompat(GLWall *wall, int passflag); diff --git a/src/gl/scene/gl_flats.cpp b/src/gl/scene/gl_flats.cpp index 8befbfb799..950a74cff5 100644 --- a/src/gl/scene/gl_flats.cpp +++ b/src/gl/scene/gl_flats.cpp @@ -288,8 +288,7 @@ void FDrawInfo::DrawFlat(GLFlat *flat, int pass, bool trans) // trans only has m switch (pass) { - case GLPASS_PLAIN: // Single-pass rendering - case GLPASS_ALL: // Same, but also creates the dynlight data. + case GLPASS_ALL: // Single-pass rendering mDrawer->SetColor(flat->lightlevel, rel, flat->Colormap,1.0f); mDrawer->SetFog(flat->lightlevel, rel, &flat->Colormap, false); if (!flat->gltexture->tex->isFullbright()) diff --git a/src/gl/scene/gl_sprite.cpp b/src/gl/scene/gl_sprite.cpp index ad4b7eb386..a05020373c 100644 --- a/src/gl/scene/gl_sprite.cpp +++ b/src/gl/scene/gl_sprite.cpp @@ -327,15 +327,6 @@ void FDrawInfo::AddSprite(GLSprite *sprite, bool translucent) list = GLDL_MODELS; } - // That's a lot of checks... - if (sprite->modelframe && sprite->RenderStyle.BlendOp != STYLEOP_Shadow && level.HasDynamicLights && gl_light_sprites && mDrawer->FixedColormap == CM_DEFAULT && !sprite->fullbright && !gl.legacyMode) - { - hw_GetDynModelLight(sprite->actor, lightdata); - sprite->dynlightindex = GLRenderer->mLights->UploadLights(lightdata); - } - else - sprite->dynlightindex = -1; - auto newsprt = gl_drawinfo->drawlists[list].NewSprite(); *newsprt = *sprite; } diff --git a/src/gl/scene/gl_walls_draw.cpp b/src/gl/scene/gl_walls_draw.cpp index a03e531508..19d97ac000 100644 --- a/src/gl/scene/gl_walls_draw.cpp +++ b/src/gl/scene/gl_walls_draw.cpp @@ -261,7 +261,6 @@ void FDrawInfo::DrawWall(GLWall *wall, int pass) switch (pass) { case GLPASS_ALL: - case GLPASS_PLAIN: RenderTexturedWall(wall, GLWall::RWF_TEXTURED); break; diff --git a/src/hwrenderer/scene/hw_drawinfo.h b/src/hwrenderer/scene/hw_drawinfo.h index 2914a7a9cc..80df35ea53 100644 --- a/src/hwrenderer/scene/hw_drawinfo.h +++ b/src/hwrenderer/scene/hw_drawinfo.h @@ -158,6 +158,8 @@ public: virtual void AddMirrorSurface(GLWall *w) = 0; virtual void AddFlat(GLFlat *flat, bool fog) = 0; virtual void AddSprite(GLSprite *sprite, bool translucent) = 0; + + virtual int UploadLights(FDynLightData &data) = 0; virtual GLDecal *AddDecal(bool onmirror) = 0; virtual std::pair AllocVertices(unsigned int count) = 0; diff --git a/src/hwrenderer/scene/hw_sprites.cpp b/src/hwrenderer/scene/hw_sprites.cpp index 6e20960a1a..4a0c82bf55 100644 --- a/src/hwrenderer/scene/hw_sprites.cpp +++ b/src/hwrenderer/scene/hw_sprites.cpp @@ -50,6 +50,7 @@ #include "hwrenderer/utility/hw_clock.h" #include "hwrenderer/utility/hw_lighting.h" #include "hwrenderer/textures/hw_material.h" +#include "hwrenderer/dynlights/hw_dynlightdata.h" extern TArray sprites; extern TArray SpriteFrames; @@ -217,6 +218,16 @@ bool GLSprite::CalculateVertices(HWDrawInfo *di, FVector3 *v) inline void GLSprite::PutSprite(HWDrawInfo *di, bool translucent) { + // That's a lot of checks... + if (modelframe && RenderStyle.BlendOp != STYLEOP_Shadow && gl_light_sprites && level.HasDynamicLights && di->FixedColormap == CM_DEFAULT && !fullbright && !(screen->hwcaps & RFL_NO_SHADERS)) + { + hw_GetDynModelLight(actor, lightdata); + dynlightindex = di->UploadLights(lightdata); + } + else + dynlightindex = -1; + + di->AddSprite(this, translucent); }