Don't use HQ Mipmap on colorization mask
This commit is contained in:
@@ -33,10 +33,10 @@ extern "C"
|
||||
// ----------------------------------------------------------------------------
|
||||
HQMipmapGenerator::HQMipmapGenerator(const io::path& name, uint8_t* data,
|
||||
const core::dimension2d<u32>& size,
|
||||
GLuint texture_name, bool single_channel)
|
||||
GLuint texture_name)
|
||||
: video::ITexture(name), m_orig_data(data), m_size(size),
|
||||
m_texture_name(texture_name), m_texture_size(0),
|
||||
m_single_channel(single_channel), m_mipmap_data(NULL)
|
||||
m_mipmap_data(NULL)
|
||||
{
|
||||
unsigned width = m_size.Width;
|
||||
unsigned height = m_size.Height;
|
||||
@@ -46,12 +46,11 @@ HQMipmapGenerator::HQMipmapGenerator(const io::path& name, uint8_t* data,
|
||||
height = height < 2 ? 1 : height >> 1;
|
||||
m_mipmap_sizes.emplace_back(core::dimension2du(width, height),
|
||||
m_texture_size);
|
||||
m_texture_size += width * height * (m_single_channel ? 1 : 4);
|
||||
m_texture_size += width * height * 4;
|
||||
if (width == 1 && height == 1)
|
||||
break;
|
||||
}
|
||||
m_texture_size = unsigned(m_mipmap_sizes.back().second) +
|
||||
(m_single_channel ? 1 : 4);
|
||||
m_texture_size = unsigned(m_mipmap_sizes.back().second) + 4;
|
||||
m_mipmap_data = malloc(sizeof(imMipmapCascade));
|
||||
} // HQMipmapGenerator
|
||||
|
||||
@@ -63,19 +62,17 @@ void HQMipmapGenerator::threadedReload(void* ptr, void* param) const
|
||||
imMipmapCascade* mm_cascade = (imMipmapCascade*)m_mipmap_data;
|
||||
#ifdef DEBUG
|
||||
int ret = imBuildMipmapCascade(mm_cascade, m_orig_data, m_size.Width,
|
||||
m_size.Height, 1/*layercount*/, m_single_channel ? 1 : 4,
|
||||
m_single_channel ? m_size.Width : m_size.Width * 4, &options, 0);
|
||||
m_size.Height, 1/*layercount*/, 4, m_size.Width * 4, &options, 0);
|
||||
assert(ret == 1);
|
||||
#else
|
||||
imBuildMipmapCascade(mm_cascade, m_orig_data, m_size.Width,
|
||||
m_size.Height, 1/*layercount*/, m_single_channel ? 1 : 4,
|
||||
m_single_channel ? m_size.Width : m_size.Width * 4, &options, 0);
|
||||
m_size.Height, 1/*layercount*/, 4, m_size.Width * 4, &options, 0);
|
||||
#endif
|
||||
for (unsigned int i = 0; i < m_mipmap_sizes.size(); i++)
|
||||
{
|
||||
memcpy((uint8_t*)ptr + m_mipmap_sizes[i].second,
|
||||
mm_cascade->mipmap[i + 1],
|
||||
m_mipmap_sizes[i].first.getArea() * (m_single_channel ? 1 : 4));
|
||||
m_mipmap_sizes[i].first.getArea() * 4);
|
||||
#ifdef DUMP_MIPMAP
|
||||
uint8_t* data = (uint8_t*)mm_cascade->mipmap[i + 1];
|
||||
if (m_single_channel)
|
||||
@@ -94,8 +91,6 @@ void HQMipmapGenerator::threadedReload(void* ptr, void* param) const
|
||||
image->drop();
|
||||
#endif
|
||||
}
|
||||
imFreeMipmapCascade((imMipmapCascade*)m_mipmap_data);
|
||||
free(m_mipmap_data);
|
||||
} // threadedReload
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@@ -107,7 +102,7 @@ void HQMipmapGenerator::threadedSubImage(void* ptr) const
|
||||
{
|
||||
glTexSubImage2D(GL_TEXTURE_2D, i + 1, 0, 0,
|
||||
m_mipmap_sizes[i].first.Width, m_mipmap_sizes[i].first.Height,
|
||||
m_single_channel ? GL_RED : GL_BGRA, GL_UNSIGNED_BYTE,
|
||||
GL_BGRA, GL_UNSIGNED_BYTE,
|
||||
(uint8_t*)ptr + m_mipmap_sizes[i].second);
|
||||
}
|
||||
delete this;
|
||||
@@ -118,4 +113,6 @@ void HQMipmapGenerator::threadedSubImage(void* ptr) const
|
||||
void HQMipmapGenerator::cleanThreadedLoader()
|
||||
{
|
||||
delete[] m_orig_data;
|
||||
imFreeMipmapCascade((imMipmapCascade*)m_mipmap_data);
|
||||
free(m_mipmap_data);
|
||||
} // cleanThreadedLoader
|
||||
|
||||
@@ -38,8 +38,6 @@ private:
|
||||
|
||||
unsigned int m_texture_size;
|
||||
|
||||
bool m_single_channel;
|
||||
|
||||
void* m_mipmap_data;
|
||||
|
||||
std::vector<std::pair<core::dimension2d<u32>, size_t> > m_mipmap_sizes;
|
||||
@@ -47,8 +45,7 @@ private:
|
||||
public:
|
||||
// ------------------------------------------------------------------------
|
||||
HQMipmapGenerator(const io::path& name, uint8_t* data,
|
||||
const core::dimension2d<u32>& size, GLuint texture_name,
|
||||
bool single_channel);
|
||||
const core::dimension2d<u32>& size, GLuint texture_name);
|
||||
// ------------------------------------------------------------------------
|
||||
virtual ~HQMipmapGenerator() {}
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
@@ -236,35 +236,7 @@ void STKTexture::reload(bool no_upload, uint8_t* preload_data,
|
||||
if (!useThreadedLoading())
|
||||
formatConversion(data, &format, w, h);
|
||||
|
||||
if (useThreadedLoading())
|
||||
{
|
||||
if (m_texture_name == 0)
|
||||
{
|
||||
glGenTextures(1, &m_texture_name);
|
||||
glBindTexture(GL_TEXTURE_2D, m_texture_name);
|
||||
if (m_single_channel)
|
||||
{
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_R, GL_ONE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_G, GL_ONE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_B, GL_ONE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_A, GL_RED);
|
||||
}
|
||||
int levels = 1;
|
||||
int width = w;
|
||||
int height = h;
|
||||
while (true)
|
||||
{
|
||||
width = width < 2 ? 1 : width >> 1;
|
||||
height = height < 2 ? 1 : height >> 1;
|
||||
levels++;
|
||||
if (width == 1 && height == 1)
|
||||
break;
|
||||
}
|
||||
glTexStorage2D(GL_TEXTURE_2D, levels, internal_format, w, h);
|
||||
}
|
||||
}
|
||||
else if (!no_upload)
|
||||
if (!no_upload)
|
||||
{
|
||||
const bool reload = m_texture_name != 0;
|
||||
if (!reload)
|
||||
@@ -281,8 +253,26 @@ void STKTexture::reload(bool no_upload, uint8_t* preload_data,
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_B, GL_ONE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_A, GL_RED);
|
||||
}
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, internal_format, w, h, 0, format,
|
||||
GL_UNSIGNED_BYTE, data);
|
||||
if (useThreadedLoading())
|
||||
{
|
||||
int levels = 1;
|
||||
int width = w;
|
||||
int height = h;
|
||||
while (true)
|
||||
{
|
||||
width = width < 2 ? 1 : width >> 1;
|
||||
height = height < 2 ? 1 : height >> 1;
|
||||
levels++;
|
||||
if (width == 1 && height == 1)
|
||||
break;
|
||||
}
|
||||
glTexStorage2D(GL_TEXTURE_2D, levels, internal_format, w, h);
|
||||
}
|
||||
else
|
||||
{
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, internal_format, w, h, 0, format,
|
||||
GL_UNSIGNED_BYTE, data);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -291,7 +281,7 @@ void STKTexture::reload(bool no_upload, uint8_t* preload_data,
|
||||
}
|
||||
if (orig_img)
|
||||
orig_img->unlock();
|
||||
if (hasMipMaps())
|
||||
if (!useThreadedLoading() && hasMipMaps())
|
||||
glGenerateMipmap(GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
@@ -631,7 +621,7 @@ void STKTexture::threadedReload(void* ptr, void* param) const
|
||||
if (useHQMipmap())
|
||||
{
|
||||
HQMipmapGenerator* hqmg = new HQMipmapGenerator(NamedPath, data,
|
||||
m_size, m_texture_name, m_single_channel);
|
||||
m_size, m_texture_name);
|
||||
((STKTexManager*)(param))->addThreadedLoadTexture(hqmg);
|
||||
}
|
||||
else
|
||||
@@ -665,6 +655,6 @@ void STKTexture::cleanThreadedLoader()
|
||||
//-----------------------------------------------------------------------------
|
||||
bool STKTexture::useHQMipmap() const
|
||||
{
|
||||
return UserConfigParams::m_hq_mipmap && m_size.Width > 1 &&
|
||||
m_size.Height > 1;
|
||||
return !m_single_channel && UserConfigParams::m_hq_mipmap &&
|
||||
m_size.Width > 1 && m_size.Height > 1;
|
||||
} // useHQMipmap
|
||||
|
||||
Reference in New Issue
Block a user