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.
This commit is contained in:
parent
fe02833f13
commit
60632fda6f
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue