From ce758329456f59af7c9177e538b8b3c446f6c712 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 3 Jan 2020 11:43:44 +0100 Subject: [PATCH] - color and depth func moved to render state. --- source/build/src/mdsprite.cpp | 1 - source/glbackend/gl_renderstate.h | 2 ++ source/glbackend/glbackend.cpp | 21 ++++++++------------- source/glbackend/glbackend.h | 26 +++++++++++++++++++------- 4 files changed, 29 insertions(+), 21 deletions(-) diff --git a/source/build/src/mdsprite.cpp b/source/build/src/mdsprite.cpp index 833c1303d..bc7bf4082 100644 --- a/source/build/src/mdsprite.cpp +++ b/source/build/src/mdsprite.cpp @@ -1805,7 +1805,6 @@ static int32_t polymost_md3draw(md3model_t *m, tspriteptr_t tspr) GLInterface.SetTinting(0, 0, PalEntry(255, 255, 255)); GLInterface.SetClamp(prevClamp); - GLInterface.SetPolymostShader(); globalnoeffect=0; return 1; diff --git a/source/glbackend/gl_renderstate.h b/source/glbackend/gl_renderstate.h index 0b439fc41..14dd49fcd 100644 --- a/source/glbackend/gl_renderstate.h +++ b/source/glbackend/gl_renderstate.h @@ -55,9 +55,11 @@ struct PolymostRenderState float Brightness = 1.f; float AlphaThreshold = 0.5f; bool AlphaTest = true; + float Color[4] = { 1,1,1,1 }; int StateFlags = STF_COLORMASK|STF_DEPTHMASK; FRenderStyle Style{}; + int DepthFunc = 1; PalEntry ClearColor = 0; short vp_x, vp_y, vp_w, vp_h; short sc_x, sc_y, sc_w, sc_h; diff --git a/source/glbackend/glbackend.cpp b/source/glbackend/glbackend.cpp index 254f5a858..69f8e4525 100644 --- a/source/glbackend/glbackend.cpp +++ b/source/glbackend/glbackend.cpp @@ -53,6 +53,7 @@ float shadediv[MAXPALOOKUPS]; static int blendstyles[] = { GL_ZERO, GL_ONE, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR, GL_DST_COLOR, GL_ONE_MINUS_DST_COLOR, GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA }; static int renderops[] = { GL_FUNC_ADD, GL_FUNC_ADD, GL_FUNC_SUBTRACT, GL_FUNC_REVERSE_SUBTRACT }; +int depthf[] = { GL_ALWAYS, GL_LESS, GL_EQUAL, GL_LEQUAL }; FileReader GetResource(const char* fn) @@ -235,7 +236,8 @@ void GLInstance::Draw(EDrawType type, size_t start, size_t count) if (activeShader == polymostShader) { - if (istrans) renderState.Flags &= ~RF_Brightmapping; // The way the colormaps are set up means that brightmaps cannot be used on translucent content at all. + glVertexAttrib4fv(2, renderState.Color); + if (renderState.Color[3] != 1.f) renderState.Flags &= ~RF_Brightmapping; // The way the colormaps are set up means that brightmaps cannot be used on translucent content at all. renderState.Apply(polymostShader, lastState); if (renderState.VertexBuffer != LastVertexBuffer || LastVB_Offset[0] != renderState.VB_Offset[0] || LastVB_Offset[1] != renderState.VB_Offset[1]) { @@ -340,18 +342,6 @@ void GLInstance::SetMatrix(int num, const VSMatrix *mat) } } -void GLInstance::SetColor(float r, float g, float b, float a) -{ - glVertexAttrib4f(2, r, g, b, a); - istrans = (a != 1); -} - -void GLInstance::SetDepthFunc(int func) -{ - int f[] = { GL_ALWAYS, GL_LESS, GL_EQUAL, GL_LEQUAL }; - glDepthFunc(f[func]); -} - void GLInstance::ReadPixels(int xdim, int ydim, uint8_t* buffer) { glReadPixels(0, 0, xdim, ydim, GL_RGB, GL_UNSIGNED_BYTE, buffer); @@ -503,6 +493,11 @@ void PolymostRenderState::Apply(PolymostShader* shader, GLState &oldState) oldState.Style = Style; // Flags are not being checked yet, the current shader has no implementation for them. } + if (DepthFunc != oldState.DepthFunc) + { + glDepthFunc(depthf[DepthFunc]); + oldState.DepthFunc = DepthFunc; + } // Disable brightmaps if non-black fog is used. if (!(Flags & RF_FogDisabled) && !FogColor.isBlack()) Flags &= ~RF_Brightmapping; shader->Flags.Set(Flags); diff --git a/source/glbackend/glbackend.h b/source/glbackend/glbackend.h index 41cf1105a..ba5415efc 100644 --- a/source/glbackend/glbackend.h +++ b/source/glbackend/glbackend.h @@ -181,6 +181,7 @@ struct GLState { int Flags = STF_COLORMASK | STF_DEPTHMASK; FRenderStyle Style{}; + int DepthFunc = -1; }; class GLInstance @@ -201,7 +202,6 @@ class GLInstance FTexture* currentTexture = nullptr; int TextureType; int MatrixChange = 0; - bool istrans = false; bool g_nontransparent255 = false; // Ugh... This is for movie playback and needs to be maintained as global state. // Cached GL state. @@ -281,13 +281,7 @@ public: { SetMatrix(num, reinterpret_cast(mat)); } - void SetColor(float r, float g, float b, float a = 1.f); - void SetColorub(uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255) - { - SetColor(r * (1 / 255.f), g * (1 / 255.f), b * (1 / 255.f), a * (1 / 255.f)); - } - void SetDepthFunc(int func); void SetPolymostShader(); void SetSurfaceShader(); void SetVPXShader(); @@ -426,6 +420,11 @@ public: renderState.StateFlags |= STF_SCISSORSET; } + void SetDepthFunc(int func) + { + renderState.DepthFunc = func; + } + void ClearScreen(PalEntry pe) { @@ -444,6 +443,19 @@ public: renderState.Style = style; } + void SetColor(float r, float g, float b, float a = 1.f) + { + renderState.Color[0] = r; + renderState.Color[1] = g; + renderState.Color[2] = b; + renderState.Color[3] = a; + } + void SetColorub(uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255) + { + SetColor(r * (1 / 255.f), g * (1 / 255.f), b * (1 / 255.f), a * (1 / 255.f)); + } + + void UseColorOnly(bool yes) { if (yes) renderState.Flags |= RF_ColorOnly;