Allow to preserve more texture config

This commit is contained in:
Benau
2017-03-16 16:20:05 +08:00
parent 0f218cff32
commit de3c9d7411
12 changed files with 117 additions and 95 deletions

View File

@@ -526,9 +526,9 @@ void Material::install(bool srgb, bool premul_alpha)
}
else
{
m_texture = STKTexManager::getInstance()->getTexture
(m_original_full_path, srgb, premul_alpha, false/*set_material*/,
srgb/*mesh_tex*/);
TexConfig tc(srgb, premul_alpha, srgb/*mesh_tex*/);
m_texture = STKTexManager::getInstance()
->getTexture(m_original_full_path, &tc);
}
if (m_texture == NULL) return;
@@ -771,9 +771,8 @@ void Material::setMaterialProperties(video::SMaterial *m, scene::IMeshBuffer* m
STKTexManager* stm = STKTexManager::getInstance();
if (m_gloss_map.size() > 0 && CVS->isDefferedEnabled())
{
glossytex = stm->getTexture(m_gloss_map, false/*srgb*/,
false/*premul_alpha*/, false/*set_material*/,
true/*mesh_tex*/);
TexConfig gtc(false/*srgb*/, false/*premul_alpha*/);
glossytex = stm->getTexture(m_gloss_map, &gtc);
}
else
{
@@ -787,9 +786,11 @@ void Material::setMaterialProperties(video::SMaterial *m, scene::IMeshBuffer* m
stm->STKTexManager::getInstance()->getUnicolorTexture(SColor(0, 0, 0, 0));
if (m_colorization_mask.size() > 0)
{
TexConfig cmtc(false/*srgb*/, false/*premul_alpha*/,
true/*mesh_tex*/, false/*set_material*/,
true/*color_mask*/);
colorization_mask_tex = stm->getTexture(m_colorization_mask,
false/*srgb*/, false/*premul_alpha*/, false/*set_material*/,
true/*mesh_tex*/, false/*no_upload*/, true/*single_channel*/);
&cmtc);
}
m->setTexture(2, colorization_mask_tex);
}
@@ -845,32 +846,29 @@ void Material::setMaterialProperties(video::SMaterial *m, scene::IMeshBuffer* m
m->setTexture(1, glossytex);
return;
case SHADERTYPE_SPLATTING:
tex = stm->getTexture(m_splatting_texture_1,
true/*srgb*/, false/*premul_alpha*/, false/*set_material*/,
true/*mesh_tex*/);
{
TexConfig stc(true/*srgb*/, false/*premul_alpha*/,
true/*mesh_tex*/, false/*set_material*/);
tex = stm->getTexture(m_splatting_texture_1, &stc);
m->setTexture(3, tex);
if (m_splatting_texture_2.size() > 0)
{
tex = stm->getTexture(m_splatting_texture_2,
true/*srgb*/, false/*premul_alpha*/, false/*set_material*/,
true/*mesh_tex*/);
tex = stm->getTexture(m_splatting_texture_2, &stc);
}
m->setTexture(4, tex);
if (m_splatting_texture_3.size() > 0)
{
tex = stm->getTexture(m_splatting_texture_3,
true/*srgb*/, false/*premul_alpha*/, false/*set_material*/,
true/*mesh_tex*/);
tex = stm->getTexture(m_splatting_texture_3, &stc);
}
m->setTexture(5, tex);
if (m_splatting_texture_4.size() > 0)
{
tex = stm->getTexture(m_splatting_texture_4,
false/*srgb*/, false/*premul_alpha*/, false/*set_material*/,
true/*mesh_tex*/);
TexConfig s4tc(false/*srgb*/, false/*premul_alpha*/,
true/*mesh_tex*/, false/*set_material*/);
tex = stm->getTexture(m_splatting_texture_4, &s4tc);
}
m->setTexture(6, tex);
m->setTexture(7, glossytex);
@@ -878,6 +876,7 @@ void Material::setMaterialProperties(video::SMaterial *m, scene::IMeshBuffer* m
// Material and shaders
m->MaterialType = Shaders::getShader(ES_SPLATTING);
return;
}
case SHADERTYPE_WATER:
m->setTexture(1, irr_driver->getTexture(FileManager::TEXTURE,
"waternormals.jpg"));
@@ -912,9 +911,10 @@ void Material::setMaterialProperties(video::SMaterial *m, scene::IMeshBuffer* m
{
if (CVS->isDefferedEnabled())
{
tex = stm->getTexture(m_normal_map_tex, false/*srgb*/,
false/*premul_alpha*/, false/*set_material*/,
true/*mesh_tex*/);
TexConfig nmtc(false/*srgb*/, false/*premul_alpha*/,
true/*mesh_tex*/, false/*set_material*/,
false/*color_mask*/, true/*normal_map*/);
tex = stm->getTexture(m_normal_map_tex, &nmtc);
}
else
tex = stm->STKTexManager::getInstance()->getUnicolorTexture(SColor(0, 0, 0, 0));

View File

@@ -40,9 +40,9 @@ Stars::Stars(AbstractKart *kart)
m_parent_kart_node = kart->getNode();
m_enabled = false;
TexConfig stc(true/*srgb*/, true/*premul_alpha*/);
video::ITexture* texture = STKTexManager::getInstance()->getTexture
("starparticle.png", true/*srgb*/, true/*premul_alpha*/,
false/*set_material*/, true/*mesh_tex*/);
("starparticle.png", &stc);
Material* star_material =
material_manager->getMaterial("starparticle.png");

View File

@@ -1044,10 +1044,11 @@ void STKMeshLoader::loadTextures(SB3dMaterial& material) const
else
full_path = fs->getFileBasename(B3dTexture->TextureName);
TexConfig mtc(i <= 1 ? true : false/*srgb*/, false/*premul_alpha*/,
true/*mesh_tex*/, true/*set_material*/);
video::ITexture* tex =
STKTexManager::getInstance()->getTexture(full_path.c_str(),
i <= 1 ? true : false/*is_srgb*/, false/*premul_alpha*/,
true/*set_material*/);
&mtc);
material.Material.setTexture(i, tex);
if (material.Textures[i]->Flags & 0x10) // Clamp U

View File

@@ -141,10 +141,8 @@ STKTexture* STKTexManager::findTextureInFileSystem(const std::string& filename,
} // findTextureInFileSystem
// ----------------------------------------------------------------------------
video::ITexture* STKTexManager::getTexture(const std::string& path, bool srgb,
bool premul_alpha,
bool set_material, bool mesh_tex,
bool no_upload, bool single_channel,
video::ITexture* STKTexManager::getTexture(const std::string& path,
TexConfig* tc, bool no_upload,
bool create_if_unfound)
{
auto ret = m_all_textures.find(path);
@@ -165,8 +163,7 @@ video::ITexture* STKTexManager::getTexture(const std::string& path, bool srgb,
if (create_if_unfound)
{
new_texture = new STKTexture(full_path.empty() ? path : full_path,
srgb, premul_alpha, set_material, mesh_tex, no_upload,
single_channel);
tc, no_upload);
if (new_texture->getOpenGLTextureName() == 0 && !no_upload)
{
const char* name = new_texture->getName().getPtr();

View File

@@ -39,6 +39,27 @@ namespace irr
namespace video { class SColor; }
}
struct TexConfig
{
bool m_srgb;
bool m_premul_alpha;
bool m_mesh_tex;
bool m_set_material;
bool m_colorization_mask;
bool m_normal_map;
TexConfig(bool srgb = false, bool premul_alpha = false,
bool mesh_tex = true, bool set_material = false,
bool color_mask = false, bool normal_map = false)
{
m_srgb = srgb;
m_premul_alpha = premul_alpha;
m_mesh_tex = mesh_tex;
m_set_material = set_material;
m_colorization_mask = color_mask;
m_normal_map = normal_map;
}
};
class STKTexManager : public Singleton<STKTexManager>, NoCopy
{
private:
@@ -83,12 +104,8 @@ public:
~STKTexManager();
// ------------------------------------------------------------------------
irr::video::ITexture* getTexture(const std::string& path,
bool srgb = false,
bool premul_alpha = false,
bool set_material = false,
bool mesh_tex = false,
TexConfig* tc = NULL,
bool no_upload = false,
bool single_channel = false,
bool create_if_unfound = true);
// ------------------------------------------------------------------------
irr::video::ITexture* getUnicolorTexture(const irr::video::SColor &c);

View File

@@ -35,24 +35,23 @@
static const uint8_t CACHE_VERSION = 1;
#endif
// ----------------------------------------------------------------------------
STKTexture::STKTexture(const std::string& path, bool srgb, bool premul_alpha,
bool set_material, bool mesh_tex, bool no_upload,
bool single_channel)
: video::ITexture(path.c_str()), m_texture_handle(0), m_srgb(srgb),
m_premul_alpha(premul_alpha), m_mesh_texture(mesh_tex),
m_single_channel(single_channel), m_material(NULL),
STKTexture::STKTexture(const std::string& path, TexConfig* tc, bool no_upload)
: video::ITexture(path.c_str()), m_texture_handle(0),
m_single_channel(false), m_tex_config(NULL), m_material(NULL),
m_texture_name(0), m_texture_size(0), m_texture_image(NULL),
m_file(NULL), m_img_loader(NULL)
{
if (set_material)
if (tc != NULL)
{
m_material = material_manager->getMaterialFor(this);
m_mesh_texture = true;
m_tex_config = (TexConfig*)malloc(sizeof(TexConfig));
memcpy(m_tex_config, tc, sizeof(TexConfig));
m_single_channel = m_tex_config->m_colorization_mask;
if (m_tex_config->m_set_material)
m_material = material_manager->getMaterialFor(this);
}
#ifndef SERVER_ONLY
if (!CVS->isGLSL())
m_srgb = false;
if (m_tex_config && !CVS->isGLSL())
m_tex_config->m_srgb = false;
if (!CVS->isARBTextureSwizzleUsable())
m_single_channel = false;
#endif
@@ -62,11 +61,10 @@ STKTexture::STKTexture(const std::string& path, bool srgb, bool premul_alpha,
// ----------------------------------------------------------------------------
STKTexture::STKTexture(uint8_t* data, const std::string& name, size_t size,
bool single_channel, bool delete_ttl)
: video::ITexture(name.c_str()), m_texture_handle(0), m_srgb(false),
m_premul_alpha(false), m_mesh_texture(false),
m_single_channel(single_channel), m_material(NULL),
m_texture_name(0), m_texture_size(0), m_texture_image(NULL),
m_file(NULL), m_img_loader(NULL)
: video::ITexture(name.c_str()), m_texture_handle(0),
m_single_channel(single_channel), m_tex_config(NULL),
m_material(NULL), m_texture_name(0), m_texture_size(0),
m_texture_image(NULL), m_file(NULL), m_img_loader(NULL)
{
m_size.Width = size;
m_size.Height = size;
@@ -77,10 +75,9 @@ STKTexture::STKTexture(uint8_t* data, const std::string& name, size_t size,
// ----------------------------------------------------------------------------
STKTexture::STKTexture(video::IImage* img, const std::string& name)
: video::ITexture(name.c_str()), m_texture_handle(0), m_srgb(false),
m_premul_alpha(false), m_mesh_texture(false),
m_single_channel(false), m_material(NULL), m_texture_name(0),
m_texture_size(0), m_texture_image(NULL),
: video::ITexture(name.c_str()), m_texture_handle(0),
m_single_channel(false), m_tex_config(NULL), m_material(NULL),
m_texture_name(0), m_texture_size(0), m_texture_image(NULL),
m_file(NULL), m_img_loader(NULL)
{
reload(false/*no_upload*/, NULL/*preload_data*/, img);
@@ -98,6 +95,7 @@ STKTexture::~STKTexture()
#endif // !SERVER_ONLY
if (m_texture_image != NULL)
m_texture_image->drop();
free(m_tex_config);
} // ~STKTexture
// ----------------------------------------------------------------------------
@@ -117,7 +115,7 @@ void STKTexture::reload(bool no_upload, uint8_t* preload_data,
std::string compressed_texture;
#if !defined(USE_GLES2)
if (!no_upload && m_mesh_texture && CVS->isTextureCompressionEnabled())
if (!no_upload && isMeshTexture() && CVS->isTextureCompressionEnabled())
{
std::string orig_file = NamedPath.getPtr();
@@ -220,16 +218,16 @@ void STKTexture::reload(bool no_upload, uint8_t* preload_data,
unsigned int internal_format = m_single_channel ? GL_R8 : GL_RGBA;
#if !defined(USE_GLES2)
if (m_mesh_texture && CVS->isTextureCompressionEnabled())
if (isMeshTexture() && CVS->isTextureCompressionEnabled())
{
internal_format = m_single_channel ? GL_COMPRESSED_RED_RGTC1 :
m_srgb ? GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT :
isSrgb() ? GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT :
GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
}
else
{
internal_format =
m_single_channel ? GL_R8 : m_srgb ? GL_SRGB8_ALPHA8 : GL_RGBA8;
m_single_channel ? GL_R8 : isSrgb() ? GL_SRGB8_ALPHA8 : GL_RGBA8;
}
#endif
if (!useThreadedLoading())
@@ -317,7 +315,7 @@ void STKTexture::formatConversion(uint8_t* data, unsigned int* format,
}
}
#endif
if (m_premul_alpha && !m_single_channel)
if (isPremulAlpha() && !m_single_channel)
{
for (unsigned int i = 0; i < w * h; i++)
{
@@ -589,7 +587,7 @@ bool STKTexture::useThreadedLoading() const
return false;
#else
return CVS->supportsThreadedTextureLoading() &&
!CVS->isTextureCompressionEnabled() && m_mesh_texture &&
!CVS->isTextureCompressionEnabled() && isMeshTexture() &&
m_img_loader && m_img_loader->supportThreadedLoading();
#endif
} // useThreadedLoading
@@ -661,3 +659,21 @@ bool STKTexture::useHQMipmap() const
return !m_single_channel && UserConfigParams::m_hq_mipmap &&
m_size.Width > 1 && m_size.Height > 1;
} // useHQMipmap
//-----------------------------------------------------------------------------
bool STKTexture::isSrgb() const
{
return m_tex_config && m_tex_config->m_srgb;
} // isSrgb
//-----------------------------------------------------------------------------
bool STKTexture::isPremulAlpha() const
{
return m_tex_config && m_tex_config->m_premul_alpha;
} // isPremulAlpha
//-----------------------------------------------------------------------------
bool STKTexture::isMeshTexture() const
{
return m_tex_config && m_tex_config->m_mesh_tex;
} // isMeshTexture

View File

@@ -32,6 +32,7 @@ namespace irr
using namespace irr;
struct TexConfig;
class Material;
class STKTexture : public video::ITexture, NoCopy
@@ -41,7 +42,9 @@ private:
uint64_t m_texture_handle;
bool m_srgb, m_premul_alpha, m_mesh_texture, m_single_channel;
bool m_single_channel;
TexConfig* m_tex_config;
Material* m_material;
@@ -78,13 +81,14 @@ private:
}
// ------------------------------------------------------------------------
bool useHQMipmap() const;
// ------------------------------------------------------------------------
bool isSrgb() const;
// ------------------------------------------------------------------------
bool isPremulAlpha() const;
public:
// ------------------------------------------------------------------------
STKTexture(const std::string& path, bool srgb = false,
bool premul_alpha = false, bool set_material = false,
bool mesh_tex = false, bool no_upload = false,
bool single_channel = false);
STKTexture(const std::string& path, TexConfig* tc, bool no_upload = false);
// ------------------------------------------------------------------------
STKTexture(uint8_t* data, const std::string& name, size_t size,
bool single_channel = false, bool delete_ttl = false);
@@ -131,14 +135,6 @@ public:
// ------------------------------------------------------------------------
virtual void unloadHandle();
// ------------------------------------------------------------------------
bool isSrgb() const { return m_srgb; }
// ------------------------------------------------------------------------
bool isPremulAlpha() const { return m_premul_alpha; }
// ------------------------------------------------------------------------
bool isMeshTexture() const { return m_mesh_texture; }
// ------------------------------------------------------------------------
void setMeshTexture(bool val) { m_mesh_texture = val; }
// ------------------------------------------------------------------------
virtual unsigned int getTextureSize() const { return m_texture_size; }
// ------------------------------------------------------------------------
void reload(bool no_upload = false, uint8_t* preload_data = NULL,
@@ -158,6 +154,8 @@ public:
{
return useHQMipmap() ? 2 : 1;
}
// ------------------------------------------------------------------------
bool isMeshTexture() const;
}; // STKTexture

View File

@@ -342,9 +342,7 @@ video::ITexture* IconButtonWidget::getDeactivatedTexture(video::ITexture* textur
name += "_disabled";
STKTexManager* stkm = STKTexManager::getInstance();
STKTexture* disabled_stk_tex = static_cast<STKTexture*>(stkm->getTexture
(name, false/*srgb*/, false/*premul_alpha*/, false/*set_material*/,
false/*mesh_tex*/, false /*no_upload*/, false/*single_channel*/,
false/*create_if_unfound*/));
(name, NULL/*tc*/, false /*no_upload*/, false/*create_if_unfound*/));
if (disabled_stk_tex == NULL)
{
SColor c;

View File

@@ -331,13 +331,12 @@ void SoccerWorld::initKartList()
std::string blue_path =
file_manager->getAsset(FileManager::GUI, "soccer_player_blue.png");
TexConfig btc(true/*srgb*/, true/*premul_alpha*/);
video::ITexture* red = STKTexManager::getInstance()->getTexture
(red_path, true/*srgb*/, true/*premul_alpha*/, false/*set_material*/,
true/*mesh_tex*/);
(red_path, &btc);
video::ITexture* blue = STKTexManager::getInstance()->getTexture
(blue_path, true/*srgb*/, true/*premul_alpha*/, false/*set_material*/,
true/*mesh_tex*/);
(blue_path, &btc);
//Assigning indicators
for(unsigned int i = 0; i < kart_amount; i++)

View File

@@ -179,9 +179,9 @@ void ThreeStrikesBattle::kartAdded(AbstractKart* kart, scene::ISceneNode* node)
// Add heart billboard above it
std::string heart_path =
file_manager->getAsset(FileManager::GUI, "heart.png");
TexConfig btc(true/*srgb*/, true/*premul_alpha*/);
video::ITexture* heart = STKTexManager::getInstance()->getTexture
(heart_path, true/*srgb*/, true/*premul_alpha*/,
false/*set_material*/, true/*mesh_tex*/);
(heart_path, &btc);
float height = kart->getKartHeight() + 0.5f;

View File

@@ -2176,9 +2176,7 @@ void Track::handleSky(const XMLNode &xml_node, const std::string &filename)
if (CVS->isGLSL())
{
t = STKTexManager::getInstance()->getTexture(v[i],
false/*srgb*/, false/*premul_alpha*/,
false/*set_material*/, false/*mesh_tex*/,
true/*no_upload*/);
(TexConfig*)NULL/*tex_config*/, true/*no_upload*/);
}
else
#endif // !SERVER_ONLY
@@ -2222,9 +2220,7 @@ void Track::handleSky(const XMLNode &xml_node, const std::string &filename)
if (CVS->isGLSL())
{
t = STKTexManager::getInstance()->getTexture(v[i],
false/*srgb*/, false/*premul_alpha*/,
false/*set_material*/, false/*mesh_tex*/,
true/*no_upload*/);
(TexConfig*)NULL/*tex_config*/, true/*no_upload*/);
}
else
#endif // !SERVER_ONLY

View File

@@ -862,9 +862,9 @@ TrackObjectPresentationBillboard::TrackObjectPresentationBillboard(
xml_node.get("start", &m_fade_out_start);
xml_node.get("end", &m_fade_out_end );
}
TexConfig tc(true/*srgb*/, true/*premul_alpha*/);
video::ITexture* texture = STKTexManager::getInstance()->getTexture
(file_manager->searchTexture(texture_name), true/*srgb*/,
true/*premul_alpha*/, false/*set_material*/, true/*mesh_tex*/);
(file_manager->searchTexture(texture_name), &tc);
if (texture == NULL)
{