From 3380420de9c079cac1f589a3be2995bb1559d65b Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 2 Jan 2020 23:56:35 +0100 Subject: [PATCH] - converted the clear screen commands. --- source/build/src/animvpx.cpp | 2 +- source/build/src/engine.cpp | 10 +++----- source/build/src/polymost.cpp | 2 +- source/glbackend/gl_renderstate.h | 3 +++ source/glbackend/glbackend.cpp | 41 +++++++++---------------------- source/glbackend/glbackend.h | 22 ++++++++++++++--- 6 files changed, 38 insertions(+), 42 deletions(-) diff --git a/source/build/src/animvpx.cpp b/source/build/src/animvpx.cpp index 46a2e9343..353437093 100644 --- a/source/build/src/animvpx.cpp +++ b/source/build/src/animvpx.cpp @@ -375,7 +375,7 @@ void animvpx_setup_glstate(int32_t animvpx_flags) texuploaded = 0; //////////////////// - GLInterface.ClearScreen(0, 0, 0, true); + GLInterface.ClearScreen(0, true); } void animvpx_restore_glstate(void) diff --git a/source/build/src/engine.cpp b/source/build/src/engine.cpp index 08f9c05df..e2cab65ae 100644 --- a/source/build/src/engine.cpp +++ b/source/build/src/engine.cpp @@ -993,7 +993,7 @@ void yax_drawrooms(void (*SpriteAnimFunc)(int32_t,int32_t,int32_t,int32_t,int32_ #ifdef USE_OPENGL if (videoGetRenderMode() == REND_POLYMOST) { - GLInterface.ClearScreen(0, 0, 0, true); + GLInterface.ClearScreen(0, true); yax_polymostclearzbuffer = 0; } #endif @@ -10533,10 +10533,7 @@ void videoClearViewableArea(int32_t dacol) { palette_t const p = paletteGetColor(dacol); - GLInterface.ClearScreen((float)p.r * (1.f/255.f), - (float)p.g * (1.f/255.f), - (float)p.b * (1.f/255.f), - false); + GLInterface.ClearScreen(PalEntry(p.r, p.g, p.b), false); return; } #endif @@ -10571,8 +10568,7 @@ void videoClearScreen(int32_t dacol) glox1 = -1; palette_t const p = paletteGetColor(dacol); - PalEntry clearcol = PalEntry(255, p.r, p.g, p.b); - GLInterface.ClearScreen(clearcol); + GLInterface.ClearScreen(PalEntry(255, p.r, p.g, p.b)); return; } #endif diff --git a/source/build/src/polymost.cpp b/source/build/src/polymost.cpp index 210d801ec..be666b3e9 100644 --- a/source/build/src/polymost.cpp +++ b/source/build/src/polymost.cpp @@ -310,7 +310,7 @@ static void resizeglcheck(void) } if (hw_polygonmode) //FUK { - GLInterface.ClearScreen(1, 1, 1, true); + GLInterface.ClearScreen(0xffffff, true); } if ((glox1 != windowxy1.x) || (gloy1 != windowxy1.y) || (glox2 != windowxy2.x) || (gloy2 != windowxy2.y) || (gloxyaspect != gxyaspect) || (gloyxscale != gyxscale) || (glohoriz2 != ghoriz2) || (glohorizcorrect != ghorizcorrect) || (glotang != gtang)) diff --git a/source/glbackend/gl_renderstate.h b/source/glbackend/gl_renderstate.h index f87abe540..24314ca9a 100644 --- a/source/glbackend/gl_renderstate.h +++ b/source/glbackend/gl_renderstate.h @@ -33,6 +33,8 @@ enum PRSFlags STF_CULLCW = 128, STF_CULLCCW = 256, STF_WIREFRAME = 512, + STF_CLEARCOLOR = 1024, + STF_CLEARDEPTH = 2048, }; @@ -51,6 +53,7 @@ struct PolymostRenderState bool AlphaTest = true; int StateFlags = STF_COLORMASK|STF_DEPTHMASK; + PalEntry ClearColor = 0; PalEntry FogColor; diff --git a/source/glbackend/glbackend.cpp b/source/glbackend/glbackend.cpp index 103e85d60..a83510f69 100644 --- a/source/glbackend/glbackend.cpp +++ b/source/glbackend/glbackend.cpp @@ -49,7 +49,6 @@ #include "v_video.h" #include "gl_renderer.h" -extern int xdim, ydim; float shadediv[MAXPALOOKUPS]; FileReader GetResource(const char* fn) @@ -375,17 +374,6 @@ void GLInstance::SetBlendOp(int op) glBlendEquation(renderops[op]); } -void GLInstance::ClearScreen(float r, float g, float b, bool depth) -{ - glClearColor(r, g, b, 1.f); - glClear(depth ? GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT : GL_COLOR_BUFFER_BIT); -} - -void GLInstance::ClearDepth() -{ - glClear(GL_DEPTH_BUFFER_BIT); -} - void GLInstance::SetViewport(int x, int y, int w, int h) { glViewport(x, y, w, h); @@ -442,24 +430,6 @@ void GLInstance::DrawImGui(ImDrawData* data) #endif } -void GLInstance::ClearScreen(PalEntry color) -{ - twod->Clear(); // Since we clear the entire screen, all previous draw operations become redundant, so delete them. -#if 1 - - SetViewport(0, 0, xdim, ydim); - ClearScreen((float)color.r * (1.f / 255.f), - (float)color.g * (1.f / 255.f), - (float)color.b * (1.f / 255.f), - false); -#else - // This must be synchronized with the rest of the 2D operations. - twod->AddColorOnlyQuad(0, 0, xdim, ydim, ); -#endif - -} - - void PolymostRenderState::Apply(PolymostShader* shader, int &oldstate) { if (StateFlags != oldstate) @@ -527,6 +497,17 @@ void PolymostRenderState::Apply(PolymostShader* shader, int &oldstate) { glPolygonMode(GL_FRONT_AND_BACK, (StateFlags & STF_WIREFRAME) ? GL_LINE : GL_FILL); } + if (StateFlags & (STF_CLEARCOLOR| STF_CLEARDEPTH)) + { + glClearColor(ClearColor.r / 255.f, ClearColor.g / 255.f, ClearColor.b / 255.f, 1.f); + int bit = 0; + if (StateFlags & STF_CLEARCOLOR) bit |= GL_COLOR_BUFFER_BIT; + if (StateFlags & STF_CLEARDEPTH) bit |= GL_DEPTH_BUFFER_BIT; + glClear(bit); + StateFlags &= ~(STF_CLEARCOLOR|STF_CLEARDEPTH); + } + + oldstate = StateFlags; } // Disable brightmaps if non-black fog is used. diff --git a/source/glbackend/glbackend.h b/source/glbackend/glbackend.h index e7bd504bb..6d9acf00c 100644 --- a/source/glbackend/glbackend.h +++ b/source/glbackend/glbackend.h @@ -18,6 +18,7 @@ class FTexture; class GLInstance; class F2DDrawer; struct palette_t; +extern int xdim, ydim; struct PaletteData { @@ -283,8 +284,6 @@ public: void SetDepthFunc(int func); void SetBlendFunc(int src, int dst); void SetBlendOp(int op); - void ClearScreen(float r, float g, float b, bool depth); - void ClearDepth(); void SetViewport(int x, int y, int w, int h); void SetPolymostShader(); void SetSurfaceShader(); @@ -292,7 +291,6 @@ public: void SetPalette(int palette); bool ApplyTextureProps(FTexture *tex, int pal); void RestoreTextureProps(); - void ClearScreen(PalEntry color); void ReadPixels(int w, int h, uint8_t* buffer); @@ -394,6 +392,24 @@ public: else renderState.StateFlags &= ~STF_WIREFRAME; } + void ClearScreen(PalEntry pe, bool depth) + { + renderState.ClearColor = pe; + renderState.StateFlags |= STF_CLEARCOLOR; + if (depth) renderState.StateFlags |= STF_CLEARDEPTH; + } + + void ClearScreen(PalEntry pe) + { + //twod->Clear(); + SetViewport(0, 0, xdim, ydim); + ClearScreen(pe, false); + } + + void ClearDepth() + { + renderState.StateFlags |= STF_CLEARDEPTH; + } void UseColorOnly(bool yes) {