diff --git a/source/glbackend/gl_renderstate.h b/source/glbackend/gl_renderstate.h index f4f7383a4..ddb706cc6 100644 --- a/source/glbackend/gl_renderstate.h +++ b/source/glbackend/gl_renderstate.h @@ -75,6 +75,7 @@ struct PolymostRenderState PalEntry ClearColor = 0; short vp_x, vp_y, vp_w, vp_h; short sc_x, sc_y, sc_w, sc_h; + int texIds[5], samplerIds[5]; PalEntry FogColor; diff --git a/source/glbackend/glbackend.cpp b/source/glbackend/glbackend.cpp index 176eee4fa..da22e26bb 100644 --- a/source/glbackend/glbackend.cpp +++ b/source/glbackend/glbackend.cpp @@ -84,7 +84,6 @@ void GLInstance::Init(int ydim) if (!mSamplers) { mSamplers = new FSamplerManager; - memset(LastBoundTextures, 0, sizeof(LastBoundTextures)); } //glinfo.bufferstorage = !!strstr(glinfo.extensions, "GL_ARB_buffer_storage"); @@ -279,41 +278,6 @@ void GLInstance::Draw(EDrawType type, size_t start, size_t count) matrixArray.Resize(1); } -void GLInstance::BindTexture(int texunit, FHardwareTexture *tex, int sampler) -{ - if (!tex) return; - if (texunit == 0 && tex->isIndexed()) - { - renderState.Flags |= RF_UsePalette; - } - else renderState.Flags &= ~RF_UsePalette; - - if (texunit != 0) glActiveTexture(GL_TEXTURE0 + texunit); - glBindTexture(GL_TEXTURE_2D, tex->GetTextureHandle()); - mSamplers->Bind(texunit, sampler == NoSampler? tex->GetSampler() : sampler, 0); - if (texunit != 0) glActiveTexture(GL_TEXTURE0); - LastBoundTextures[texunit] = tex->GetTextureHandle(); - if (texunit == 0) texv = tex; -} - -void GLInstance::UnbindTexture(int texunit) -{ - if (LastBoundTextures[texunit] != 0) - { - if (texunit != 0) glActiveTexture(GL_TEXTURE0+texunit); - glBindTexture(GL_TEXTURE_2D, 0); - if (texunit != 0) glActiveTexture(GL_TEXTURE0); - LastBoundTextures[texunit] = 0; - } -} - -void GLInstance::UnbindAllTextures() -{ - for(int texunit = 0; texunit < MAX_TEXTURES; texunit++) - { - UnbindTexture(texunit); - } -} void GLInstance::SetMatrix(int num, const VSMatrix *mat) { @@ -373,8 +337,26 @@ void GLInstance::DrawImGui(ImDrawData* data) #endif } + void PolymostRenderState::Apply(PolymostShader* shader, GLState &oldState) { + bool reset = false; + for (int i = 0; i < 5; i++) + { + if (texIds[i] != oldState.TexId[i] || samplerIds[i] != oldState.SamplerId[i]) + { + if (i != 0) + { + glActiveTexture(GL_TEXTURE0 + i); + reset = true; + } + glBindTexture(GL_TEXTURE_2D, texIds[i]); + glBindSampler(i, samplerIds[i]); + oldState.TexId[i] = texIds[i]; + oldState.SamplerId[i] = samplerIds[i]; + } + if (reset) glActiveTexture(GL_TEXTURE0); + } if (StateFlags != oldState.Flags) { if ((StateFlags ^ oldState.Flags) & STF_DEPTHTEST) diff --git a/source/glbackend/glbackend.h b/source/glbackend/glbackend.h index d5e497dd4..de878b4f5 100644 --- a/source/glbackend/glbackend.h +++ b/source/glbackend/glbackend.h @@ -170,19 +170,16 @@ struct GLState int Flags = STF_COLORMASK | STF_DEPTHMASK; FRenderStyle Style{}; int DepthFunc = -1; + int TexId[5] = {}, SamplerId[5] = {}; }; class GLInstance { enum { - MAX_TEXTURES = 15, // slot 15 is used internally and not available. - THCACHESIZE = 200, + MAX_TEXTURES = 5, /*15*/ // slot 15 is used internally and not available. - The renderer uses only 5, though. }; std::vector Buffer; // cheap-ass implementation. The primary purpose is to get the GL accesses out of polymost.cpp, not writing something performant right away. - unsigned int LastBoundTextures[MAX_TEXTURES]; - unsigned TextureHandleCache[THCACHESIZE]; - int currentindex = THCACHESIZE; int maxTextureSize; PaletteManager palmanager; int lastPalswapIndex = -1; @@ -232,9 +229,6 @@ public: void Draw(EDrawType type, size_t start, size_t count); FHardwareTexture* NewTexture(); - void BindTexture(int texunit, FHardwareTexture *texid, int sampler = NoSampler); - void UnbindTexture(int texunit); - void UnbindAllTextures(); void EnableNonTransparent255(bool on) { g_nontransparent255 = on; @@ -441,6 +435,31 @@ public: SetColor(r * (1 / 255.f), g * (1 / 255.f), b * (1 / 255.f), a * (1 / 255.f)); } + void BindTexture(int texunit, FHardwareTexture* tex, int sampler = NoSampler) + { + if (!tex) return; + if (texunit == 0) + { + if (tex->isIndexed()) renderState.Flags |= RF_UsePalette; + else renderState.Flags &= ~RF_UsePalette; + } + renderState.texIds[texunit] = tex->GetTextureHandle(); + renderState.samplerIds[texunit] = sampler == NoSampler ? tex->GetSampler() : sampler; + } + + void UnbindTexture(int texunit) + { + renderState.texIds[texunit] = 0; + renderState.samplerIds[texunit] = 0; + } + + void UnbindAllTextures() + { + for (int texunit = 0; texunit < MAX_TEXTURES; texunit++) + { + UnbindTexture(texunit); + } + } void UseColorOnly(bool yes) { diff --git a/source/sw/src/player.cpp b/source/sw/src/player.cpp index b53ecda4c..3d3291b44 100644 --- a/source/sw/src/player.cpp +++ b/source/sw/src/player.cpp @@ -6483,7 +6483,7 @@ DoPlayerBeginDie(PLAYERp pp) { bak = GlobInfoStringTime; GlobInfoStringTime = 999; - PutStringInfo(pp, GStrings("TXT_PRESSSPACER")); + PutStringInfo(pp, GStrings("TXT_PRESSSPACE")); GlobInfoStringTime = bak; }