From ba397f5ca11381338c7a29b01e20e5e779c5627e Mon Sep 17 00:00:00 2001
From: Christoph Oelckers <coelckers@users.noreply.github.com>
Date: Thu, 11 Jun 2020 23:55:23 +0200
Subject: [PATCH] - always draw floors opaque

---
 source/build/src/polymost.cpp     | 4 ++++
 source/glbackend/glbackend.cpp    | 2 +-
 source/glbackend/glbackend.h      | 5 +++++
 source/glbackend/pm_renderstate.h | 1 +
 4 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/source/build/src/polymost.cpp b/source/build/src/polymost.cpp
index 4d8cf7c6b..f42fa18c8 100644
--- a/source/build/src/polymost.cpp
+++ b/source/build/src/polymost.cpp
@@ -433,6 +433,9 @@ static void polymost_drawpoly(vec2f_t const * const dpxy, int32_t const n, int32
         SetRenderStyleFromBlend((method & DAMETH_MASKPROPS) > DAMETH_MASK, drawpoly_blend, (method & DAMETH_MASKPROPS) == DAMETH_TRANS2);
     }
 
+    if (!(method & (DAMETH_WALL | DAMETH_CLAMPED | DAMETH_MASK)))
+        GLInterface.SetTextureMode(TM_OPAQUE);
+
     float pc[4];
 
     // The shade rgb from the tint is ignored here.
@@ -479,6 +482,7 @@ static void polymost_drawpoly(vec2f_t const * const dpxy, int32_t const n, int32
 
     GLInterface.SetTinting(-1, 0xffffff, 0xffffff);
 	GLInterface.SetNpotEmulation(0.f, 0.f);
+    GLInterface.SetTextureMode(TM_NORMAL);
 
 	if (skyzbufferhack && skyzbufferhack_pass == 0)
     {
diff --git a/source/glbackend/glbackend.cpp b/source/glbackend/glbackend.cpp
index 4a3beb545..5b869db12 100644
--- a/source/glbackend/glbackend.cpp
+++ b/source/glbackend/glbackend.cpp
@@ -575,7 +575,6 @@ void PolymostRenderState::Apply(FRenderState& state, GLState& oldState)
 	{
 		state.EnableDepthTest(StateFlags & STF_DEPTHTEST);
 		state.EnableMultisampling(StateFlags & STF_MULTISAMPLE);
-		state.SetTextureMode((StateFlags & STF_BLEND) ? TM_OPAQUE : TM_NORMAL);
 
 		if ((StateFlags ^ oldState.Flags) & (STF_STENCILTEST | STF_STENCILWRITE))
 		{
@@ -641,6 +640,7 @@ void PolymostRenderState::Apply(FRenderState& state, GLState& oldState)
 	state.SetFog((Flags & RF_MapFog) ? PalEntry(0x999999) : FogColor, 21.f);	// Fixme: The real density still needs to be implemented. 21 is a reasonable default only.
 	state.SetSoftLightLevel(ShadeDiv >= 1 / 1000.f ? 255 - Scale(Shade, 255, numshades) : 255);
 	state.SetLightParms(VisFactor, ShadeDiv / (numshades - 2));
+	state.SetTextureMode(TextureMode);
 
 	state.SetNpotEmulation(NPOTEmulation.Y, NPOTEmulation.X);
 	state.AlphaFunc(Alpha_Greater, AlphaTest ? AlphaThreshold : -1.f);
diff --git a/source/glbackend/glbackend.h b/source/glbackend/glbackend.h
index f1b7534ea..f2d807796 100644
--- a/source/glbackend/glbackend.h
+++ b/source/glbackend/glbackend.h
@@ -146,6 +146,11 @@ public:
 	
 	void ReadPixels(int w, int h, uint8_t* buffer);
 
+	void SetTextureMode(int m)
+	{
+		renderState.TextureMode = m;
+	}
+
 	void SetDepthBias(float a, float b)
 	{
 		renderState.mBias.mFactor = a;
diff --git a/source/glbackend/pm_renderstate.h b/source/glbackend/pm_renderstate.h
index bda644a9c..d89c6e0d6 100644
--- a/source/glbackend/pm_renderstate.h
+++ b/source/glbackend/pm_renderstate.h
@@ -53,6 +53,7 @@ struct PolymostRenderState
 	float ShadeDiv = 62.f;
 	float VisFactor = 128.f;
 	int Flags = 0;
+	int TextureMode = TM_NORMAL;
 	FVector2 NPOTEmulation = { 0.f, 0.f };
     float AlphaThreshold = 0.5f;
 	bool AlphaTest = true;