improve texture mipmap count

GL_TEXTURE_MAX_LEVEL set how many mipmaps should be allocated, but all of them must be created.
GL_TEXTURE_MAX_LOD set how many mipmaps may be used.
This commit is contained in:
degasus 2013-01-16 21:15:07 +01:00
parent 8a7f1e9264
commit b778b86e26
2 changed files with 14 additions and 19 deletions

View File

@ -214,7 +214,7 @@ TextureCache::TCacheEntryBase* TextureCache::CreateTexture(unsigned int width,
entry.gl_type = gl_type;
entry.pcfmt = pcfmt;
entry.bHaveMipMaps = tex_levels != 1;
entry.m_tex_levels = tex_levels;
return &entry;
}
@ -225,20 +225,18 @@ void TextureCache::TCacheEntry::Load(unsigned int width, unsigned int height,
glBindTexture(GL_TEXTURE_2D, texture);
//GL_REPORT_ERRORD();
if(level == 0 && m_tex_levels != 0)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, m_tex_levels - 1);
if (pcfmt != PC_TEX_FMT_DXT1)
{
if (expanded_width != width)
glPixelStorei(GL_UNPACK_ROW_LENGTH, expanded_width);
if (bHaveMipMaps && autogen_mips)
{
glTexImage2D(GL_TEXTURE_2D, level, gl_iformat, width, height, 0, gl_format, gl_type, temp);
glTexImage2D(GL_TEXTURE_2D, level, gl_iformat, width, height, 0, gl_format, gl_type, temp);
if (autogen_mips)
glGenerateMipmap(GL_TEXTURE_2D);
}
else
{
glTexImage2D(GL_TEXTURE_2D, level, gl_iformat, width, height, 0, gl_format, gl_type, temp);
}
if (expanded_width != width)
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
@ -264,11 +262,8 @@ TextureCache::TCacheEntryBase* TextureCache::CreateRenderTargetTexture(
gl_iformat = GL_RGBA,
gl_type = GL_UNSIGNED_BYTE;
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
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);
@ -424,7 +419,7 @@ void TextureCache::TCacheEntry::SetTextureParameters(const TexMode0 &newmode, co
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
(newmode.mag_filter || g_Config.bForceFiltering) ? GL_LINEAR : GL_NEAREST);
if (bHaveMipMaps)
if (m_tex_levels != 1)
{
// TODO: not used anywhere
if (g_ActiveConfig.bForceFiltering && newmode.min_filter < 4)
@ -432,8 +427,8 @@ void TextureCache::TCacheEntry::SetTextureParameters(const TexMode0 &newmode, co
int filt = newmode.min_filter;
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, c_MinLinearFilter[filt & 7]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, newmode1.min_lod >> 4);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, newmode1.max_lod >> 4);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_LOD, newmode1.min_lod >> 4);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, newmode1.max_lod >> 4);
}
else
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,

View File

@ -46,7 +46,7 @@ private:
int gl_iformat;
int gl_type;
bool bHaveMipMaps;
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