diff --git a/src/gl/models/gl_models.cpp b/src/gl/models/gl_models.cpp index a6235fe49..390664c3d 100644 --- a/src/gl/models/gl_models.cpp +++ b/src/gl/models/gl_models.cpp @@ -54,8 +54,6 @@ CVAR(Bool, gl_light_models, true, CVAR_ARCHIVE) -extern int modellightindex; - VSMatrix FGLModelRenderer::GetViewToWorldMatrix() { VSMatrix objectToWorldMatrix; @@ -359,9 +357,9 @@ void FModelVertexBuffer::SetupFrame(FModelRenderer *renderer, unsigned int frame // //=========================================================================== -void gl_RenderModel(GLSprite * spr) +void gl_RenderModel(GLSprite * spr, int mli) { - FGLModelRenderer renderer; + FGLModelRenderer renderer(mli); renderer.RenderModel(spr->x, spr->y, spr->z, spr->modelframe, spr->actor); } @@ -371,8 +369,8 @@ void gl_RenderModel(GLSprite * spr) // //=========================================================================== -void gl_RenderHUDModel(DPSprite *psp, float ofsX, float ofsY) +void gl_RenderHUDModel(DPSprite *psp, float ofsX, float ofsY, int mli) { - FGLModelRenderer renderer; + FGLModelRenderer renderer(mli); renderer.RenderHUDModel(psp, ofsX, ofsY); } diff --git a/src/gl/models/gl_models.h b/src/gl/models/gl_models.h index 636c1944c..de3fdfe7e 100644 --- a/src/gl/models/gl_models.h +++ b/src/gl/models/gl_models.h @@ -32,7 +32,10 @@ class GLSprite; class FGLModelRenderer : public FModelRenderer { + int modellightindex = -1; public: + FGLModelRenderer(int mli) : modellightindex(mli) + {} void BeginDrawModel(AActor *actor, FSpriteModelFrame *smf, const VSMatrix &objectToWorldMatrix) override; void EndDrawModel(AActor *actor, FSpriteModelFrame *smf) override; IModelVertexBuffer *CreateVertexBuffer(bool needindex, bool singleframe) override; @@ -48,5 +51,5 @@ public: double GetTimeFloat() override; }; -void gl_RenderModel(GLSprite * spr); -void gl_RenderHUDModel(DPSprite *psp, float ofsx, float ofsy); +void gl_RenderModel(GLSprite * spr, int mli); +void gl_RenderHUDModel(DPSprite *psp, float ofsx, float ofsy, int mli); diff --git a/src/gl/scene/gl_sprite.cpp b/src/gl/scene/gl_sprite.cpp index 34e2d58fd..55c675f74 100644 --- a/src/gl/scene/gl_sprite.cpp +++ b/src/gl/scene/gl_sprite.cpp @@ -79,7 +79,6 @@ EXTERN_CVAR (Bool, r_debug_disable_vis_filter) extern TArray sprites; extern TArray SpriteFrames; extern uint32_t r_renderercaps; -extern int modellightindex; enum HWRenderStyle { @@ -474,7 +473,7 @@ void GLSprite::Draw(int pass) } else { - gl_RenderModel(this); + gl_RenderModel(this, dynlightindex); } } diff --git a/src/gl/scene/gl_spritelight.cpp b/src/gl/scene/gl_spritelight.cpp index 840129f34..400c769ec 100644 --- a/src/gl/scene/gl_spritelight.cpp +++ b/src/gl/scene/gl_spritelight.cpp @@ -44,8 +44,6 @@ #include "gl/textures/gl_material.h" #include "gl/dynlights/gl_lightbuffer.h" -FDynLightData modellightdata; -int modellightindex = -1; template T smoothstep(const T edge0, const T edge1, const T x) @@ -198,6 +196,8 @@ void BSPWalkCircle(float x, float y, float radiusSquared, const Callback &callba int gl_SetDynModelLight(AActor *self, int dynlightindex) { + static FDynLightData modellightdata; // If this ever gets multithreaded, this variable must either be made non-static or thread_local. + // For deferred light mode this function gets called twice. First time for list upload, and second for draw. if (gl.lightmethod == LM_DEFERRED && dynlightindex != -1) { diff --git a/src/gl/scene/gl_weapon.cpp b/src/gl/scene/gl_weapon.cpp index 160c4dab9..3915c25e6 100644 --- a/src/gl/scene/gl_weapon.cpp +++ b/src/gl/scene/gl_weapon.cpp @@ -73,7 +73,7 @@ void GLSceneDrawer::DrawPSprite (player_t * player,DPSprite *psp, float sx, floa // [BB] In the HUD model step we just render the model and break out. if ( hudModelStep ) { - gl_RenderHUDModel(psp, sx, sy); + gl_RenderHUDModel(psp, sx, sy, weapondynlightindex[psp]); return; } diff --git a/src/gl/textures/gl_texture.cpp b/src/gl/textures/gl_texture.cpp index 307948ece..bbb9d6123 100644 --- a/src/gl/textures/gl_texture.cpp +++ b/src/gl/textures/gl_texture.cpp @@ -314,7 +314,7 @@ void gl_PrecacheTexture(uint8_t *texhitlist, TMap &actorhitl } // cache all used models - FGLModelRenderer renderer; + FGLModelRenderer renderer(-1); for (unsigned i = 0; i < Models.Size(); i++) { if (modellist[i])