From 6156e7382a9c65d9318da0cc1545c44a2cf58226 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 2 Jan 2020 23:15:16 +0100 Subject: [PATCH] - preparation for moving GL state into the renderstate struct. --- source/glbackend/gl_hwtexture.cpp | 2 +- source/glbackend/gl_renderstate.h | 17 ++++++++++++++++- source/glbackend/glbackend.cpp | 23 ++++++++--------------- source/glbackend/glbackend.h | 2 +- 4 files changed, 26 insertions(+), 18 deletions(-) diff --git a/source/glbackend/gl_hwtexture.cpp b/source/glbackend/gl_hwtexture.cpp index e00d6c04b..ae1beebe8 100644 --- a/source/glbackend/gl_hwtexture.cpp +++ b/source/glbackend/gl_hwtexture.cpp @@ -63,7 +63,7 @@ unsigned int FHardwareTexture::CreateTexture(int w, int h, int type, bool mipmap { static int gltypes[] = { GL_R8, GL_RGBA8, GL_RGB5_A1, GL_RGBA2 }; static uint8_t bytes[] = { 1, 4, 2, 1 }; - glTexID = GLInterface.GetTextureID(); + glGenTextures(1, &glTexID); glActiveTexture(GL_TEXTURE15); glBindTexture(GL_TEXTURE_2D, glTexID); int size = std::max(w, h); diff --git a/source/glbackend/gl_renderstate.h b/source/glbackend/gl_renderstate.h index 20ed2ea52..f87abe540 100644 --- a/source/glbackend/gl_renderstate.h +++ b/source/glbackend/gl_renderstate.h @@ -22,6 +22,19 @@ enum PRSFlags RF_HICTINT_BLEND_Overlay = 0x100000, RF_HICTINT_BLEND_Hardlight = 0x200000, RF_HICTINT_BLENDMASK = RF_HICTINT_BLEND_Screen | RF_HICTINT_BLEND_Overlay | RF_HICTINT_BLEND_Hardlight, + + STF_BLEND = 1, + STF_COLORMASK = 2, + STF_DEPTHMASK = 4, + STF_DEPTHTEST = 8, + STF_MULTISAMPLE = 16, + STF_STENCILWRITE = 32, + STF_STENCILTEST = 64, + STF_CULLCW = 128, + STF_CULLCCW = 256, + STF_WIREFRAME = 512, + + }; struct PolymostRenderState @@ -37,11 +50,13 @@ struct PolymostRenderState float AlphaThreshold = 0.5f; bool AlphaTest = true; + int StateFlags = STF_COLORMASK|STF_DEPTHMASK; + PalEntry FogColor; IVertexBuffer* VertexBuffer = nullptr; int VB_Offset[2] = {}; IIndexBuffer* IndexBuffer = nullptr; - void Apply(PolymostShader *shader); + void Apply(PolymostShader *shader, int &oldstate); }; diff --git a/source/glbackend/glbackend.cpp b/source/glbackend/glbackend.cpp index 0ee56fda4..e5580e2a6 100644 --- a/source/glbackend/glbackend.cpp +++ b/source/glbackend/glbackend.cpp @@ -193,6 +193,12 @@ void GLInstance::Deinit() palmanager.DeleteAllTextures(); lastPalswapIndex = -1; } + +FHardwareTexture* GLInstance::NewTexture() +{ + return new FHardwareTexture; +} + std::pair GLInstance::AllocVertices(size_t num) { @@ -227,7 +233,7 @@ 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. - renderState.Apply(polymostShader); + renderState.Apply(polymostShader, lastState); if (renderState.VertexBuffer != LastVertexBuffer || LastVB_Offset[0] != renderState.VB_Offset[0] || LastVB_Offset[1] != renderState.VB_Offset[1]) { if (renderState.VertexBuffer) @@ -271,19 +277,6 @@ void GLInstance::Draw(EDrawType type, size_t start, size_t count) if (MatrixChange) RestoreTextureProps(); } -int GLInstance::GetTextureID() -{ - uint32_t id = 0; - glGenTextures(1, &id); - return id; -} - -FHardwareTexture* GLInstance::NewTexture() -{ - return new FHardwareTexture; -} - - void GLInstance::BindTexture(int texunit, FHardwareTexture *tex, int sampler) { if (!tex) return; @@ -540,7 +533,7 @@ void GLInstance::ClearScreen(PalEntry color) } -void PolymostRenderState::Apply(PolymostShader* shader) +void PolymostRenderState::Apply(PolymostShader* shader, int &oldstate) { // Disable brightmaps if non-black fog is used. if (!(Flags & RF_FogDisabled) && !FogColor.isBlack()) Flags &= ~RF_Brightmapping; diff --git a/source/glbackend/glbackend.h b/source/glbackend/glbackend.h index cd6ec21f6..a89731760 100644 --- a/source/glbackend/glbackend.h +++ b/source/glbackend/glbackend.h @@ -196,6 +196,7 @@ class GLInstance int MatrixChange = 0; bool istrans = false; bool g_nontransparent255 = false; // Ugh... This is for movie playback and needs to be maintained as global state. + int lastState = STF_COLORMASK | STF_DEPTHMASK; IVertexBuffer* LastVertexBuffer = nullptr; int LastVB_Offset[2] = {}; @@ -234,7 +235,6 @@ public: std::pair AllocVertices(size_t num); void Draw(EDrawType type, size_t start, size_t count); - int GetTextureID(); FHardwareTexture* NewTexture(); void BindTexture(int texunit, FHardwareTexture *texid, int sampler = NoSampler); void UnbindTexture(int texunit);