From 60632fda6f7509e1d126fee62c08205c87f19296 Mon Sep 17 00:00:00 2001 From: degasus Date: Tue, 21 Jan 2014 10:34:48 +0100 Subject: [PATCH] OpenGL: remove small optimization This one was introduced to reduce the glBindTexture and glActiveTexture calls. But it was quite a bit of logic and only an improvment on uploading/creating a texture, which is done rarely. --- .../Core/VideoBackends/OGL/TextureCache.cpp | 39 +++++-------------- Source/Core/VideoBackends/OGL/TextureCache.h | 3 -- .../Core/VideoBackends/OGL/VertexManager.cpp | 1 - 3 files changed, 10 insertions(+), 33 deletions(-) diff --git a/Source/Core/VideoBackends/OGL/TextureCache.cpp b/Source/Core/VideoBackends/OGL/TextureCache.cpp index e2b5e0dde4..c4a89b004f 100644 --- a/Source/Core/VideoBackends/OGL/TextureCache.cpp +++ b/Source/Core/VideoBackends/OGL/TextureCache.cpp @@ -52,7 +52,6 @@ static u32 s_DepthCbufid; static u32 s_Textures[8]; static u32 s_ActiveTexture; -static u32 s_NextStage; bool SaveTexture(const std::string filename, u32 textarget, u32 tex, int virtual_width, int virtual_height, unsigned int level) { @@ -188,36 +187,26 @@ TextureCache::TCacheEntryBase* TextureCache::CreateTexture(unsigned int width, entry.gl_type = gl_type; entry.pcfmt = pcfmt; - entry.m_tex_levels = tex_levels; + glActiveTexture(GL_TEXTURE0+9); + glBindTexture(GL_TEXTURE_2D, entry.texture); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, tex_levels - 1); entry.Load(width, height, expanded_width, 0); + // This isn't needed as Load() also reset the stage in the end + //TextureCache::SetStage(); + return &entry; } void TextureCache::TCacheEntry::Load(unsigned int width, unsigned int height, unsigned int expanded_width, unsigned int level) { - if (s_ActiveTexture != s_NextStage) - { - glActiveTexture(GL_TEXTURE0 + s_NextStage); - s_ActiveTexture = s_NextStage; - } - - if (s_Textures[s_NextStage] != texture) - { - glBindTexture(GL_TEXTURE_2D, texture); - s_Textures[s_NextStage] = texture; - } - - // TODO: sloppy, just do this on creation? - if (level == 0) - { - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, m_tex_levels - 1); - } - if (pcfmt != PC_TEX_FMT_DXT1) { + glActiveTexture(GL_TEXTURE0+9); + glBindTexture(GL_TEXTURE_2D, texture); + if (expanded_width != width) glPixelStorei(GL_UNPACK_ROW_LENGTH, expanded_width); @@ -232,6 +221,7 @@ void TextureCache::TCacheEntry::Load(unsigned int width, unsigned int height, //glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, //width, height, 0, expanded_width * expanded_height/2, temp); } + TextureCache::SetStage(); GL_REPORT_ERRORD(); } @@ -249,7 +239,6 @@ TextureCache::TCacheEntryBase* TextureCache::CreateRenderTargetTexture( gl_type = GL_UNSIGNED_BYTE; glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0); - entry->m_tex_levels = 1; glTexImage2D(GL_TEXTURE_2D, 0, gl_iformat, scaled_tex_w, scaled_tex_h, 0, gl_format, gl_type, NULL); glBindTexture(GL_TEXTURE_2D, 0); @@ -400,7 +389,6 @@ TextureCache::TextureCache() s_DepthCopyPositionUniform = glGetUniformLocation(s_DepthMatrixProgram.glprogid, "copy_position"); s_ActiveTexture = -1; - s_NextStage = -1; for(auto& gtex : s_Textures) gtex = -1; } @@ -423,11 +411,4 @@ void TextureCache::SetStage () glActiveTexture(GL_TEXTURE0 + s_ActiveTexture); } -void TextureCache::SetNextStage ( unsigned int stage ) -{ - s_NextStage = stage; -} - - - } diff --git a/Source/Core/VideoBackends/OGL/TextureCache.h b/Source/Core/VideoBackends/OGL/TextureCache.h index af1b60bc06..ca3b857190 100644 --- a/Source/Core/VideoBackends/OGL/TextureCache.h +++ b/Source/Core/VideoBackends/OGL/TextureCache.h @@ -22,7 +22,6 @@ public: TextureCache(); static void DisableStage(unsigned int stage); static void SetStage(); - static void SetNextStage(unsigned int stage); private: struct TCacheEntry : TCacheEntryBase @@ -36,8 +35,6 @@ private: int gl_iformat; int gl_type; - int m_tex_levels; - //TexMode0 mode; // current filter and clamp modes that texture is set to //TexMode1 mode1; // current filter and clamp modes that texture is set to diff --git a/Source/Core/VideoBackends/OGL/VertexManager.cpp b/Source/Core/VideoBackends/OGL/VertexManager.cpp index 497845890a..c9d6935e29 100644 --- a/Source/Core/VideoBackends/OGL/VertexManager.cpp +++ b/Source/Core/VideoBackends/OGL/VertexManager.cpp @@ -180,7 +180,6 @@ void VertexManager::vFlush() { if (usedtextures & (1 << i)) { - TextureCache::SetNextStage(i); g_renderer->SetSamplerState(i % 4, i / 4); FourTexUnits &tex = bpmem.tex[i >> 2]; TextureCache::TCacheEntryBase* tentry = TextureCache::Load(i,