Preload the container id of materials

This commit is contained in:
Benau 2018-01-10 13:10:12 +08:00
parent f4fb2cb41c
commit 4823c46ad9
19 changed files with 109 additions and 138 deletions

View File

@ -696,7 +696,7 @@ void IrrDriver::createSunInterposer()
#ifndef SERVER_ONLY
scene::IMesh * sphere = m_scene_manager->getGeometryCreator()
->createSphereMesh(1, 16, 16);
Material* material = material_manager->getSPMaterial("solid");
Material* material = material_manager->getDefaultSPMaterial("solid");
m_sun_interposer = new SP::SPDynamicDrawCall
(scene::EPT_TRIANGLES, NULL/*shader*/, material);
for (unsigned i = 0; i < sphere->getMeshBufferCount(); i++)

View File

@ -82,10 +82,6 @@ Material::Material(const XMLNode *node, bool deprecated)
(relative_path.c_str()).c_str();
}
core::stringc texfname(m_texname.c_str());
texfname.make_lower();
m_texname = texfname.c_str();
if (m_full_path.size() > 0)
{
core::stringc texfname2(m_full_path.c_str());
@ -170,7 +166,6 @@ Material::Material(const XMLNode *node, bool deprecated)
node->get("colorization-mask", &m_colorization_mask );
std::string gloss_map;
node->get("gloss-map", &gloss_map );
node->get("water-splash", &m_water_splash );
node->get("jump", &m_is_jump_texture );
node->get("has-gravity", &m_has_gravity );
node->get("uv-two-tex", &m_uv_two_tex );
@ -230,16 +225,10 @@ Material::Material(const XMLNode *node, bool deprecated)
else if (s == "water_shader")
{
m_shader_type = SHADERTYPE_WATER;
node->get("water-shader-speed-1", &m_water_shader_speed_1);
node->get("water-shader-speed-2", &m_water_shader_speed_2);
}
else if (s == "grass")
{
m_shader_type = SHADERTYPE_VEGETATION;
m_grass_speed = 1.5f;
m_grass_amplitude = 0.25f;
node->get("grass-speed", &m_grass_speed);
node->get("grass-amplitude", &m_grass_amplitude);
}
else if (s == "splatting")
{
@ -249,10 +238,6 @@ Material::Material(const XMLNode *node, bool deprecated)
node->get("splatting-texture-3", &m_sampler_path[4]);
node->get("splatting-texture-4", &m_sampler_path[5]);
}
//else
//{
// Log::warn("Material", "Unknown shader type <%s> for <%s>", s.c_str(), m_texname.c_str());
//}
}
else
{
@ -327,23 +312,13 @@ Material::Material(const XMLNode *node, bool deprecated)
s = "";
node->get("graphical-effect", &s);
if (s == "water")
{
m_water_splash = true;
}
else if (s == "grass")
if (s == "grass")
{
m_shader_type = SHADERTYPE_VEGETATION;
m_grass_speed = 1.5f;
m_grass_amplitude = 0.25f;
node->get("grass-speed", &m_grass_speed);
node->get("grass-amplitude", &m_grass_amplitude);
}
else if (s == "water_shader")
{
m_shader_type = SHADERTYPE_WATER;
node->get("water-shader-speed-1", &m_water_shader_speed_1);
node->get("water-shader-speed-2", &m_water_shader_speed_2);
}
else if (s == "normal_map")
{
@ -400,8 +375,6 @@ Material::Material(const XMLNode *node, bool deprecated)
if (water_shader)
{
m_shader_type = SHADERTYPE_WATER;
node->get("water-shader-speed-1", &m_water_shader_speed_1);
node->get("water-shader-speed-2", &m_water_shader_speed_2);
}
// ---- End backwards compatibility
@ -473,6 +446,11 @@ Material::Material(const XMLNode *node, bool deprecated)
}
}
#endif
loadContainerId();
core::stringc texfname(m_texname.c_str());
texfname.make_lower();
m_texname = texfname.c_str();
if (m_disable_z_write && m_shader_type != SHADERTYPE_ALPHA_BLEND && m_shader_type != SHADERTYPE_ADDITIVE)
{
@ -523,6 +501,7 @@ Material::Material(const XMLNode *node, bool deprecated)
if(m_has_gravity)
m_high_tire_adhesion = true;
} // Material
//-----------------------------------------------------------------------------
video::ITexture* Material::getTexture(bool srgb, bool premul_alpha)
{
@ -533,6 +512,19 @@ video::ITexture* Material::getTexture(bool srgb, bool premul_alpha)
return m_texture;
} // getTexture
//-----------------------------------------------------------------------------
void Material::loadContainerId()
{
if (m_sampler_path[0] != "unicolor_white")
{
if (!file_manager->searchTextureContainerId(m_container_id, m_texname))
{
Log::warn("Material", "Missing container id for %s, no texture"
" compression for it will be done", m_texname.c_str());
}
}
} // loadContainerId
//-----------------------------------------------------------------------------
/** Create a standard material using the default settings for materials.
* \param fname Name of the texture file.
@ -573,6 +565,7 @@ Material::Material(const std::string& fname, bool is_full_path,
}
}
}
loadContainerId();
core::stringc texfname(m_texname.c_str());
texfname.make_lower();
@ -609,8 +602,6 @@ void Material::init()
m_colorizable = false;
m_colorization_factor = 0.0f;
m_colorization_mask = "";
m_water_shader_speed_1 = 6.6667f;
m_water_shader_speed_2 = 4.0f;
m_fog = true;
m_max_speed_fraction = 1.0f;
m_slowdown_time = 1.0f;
@ -627,7 +618,6 @@ void Material::init()
m_zipper_speed_gain = -1.0f;
m_zipper_engine_force = -1.0f;
m_zipper_min_speed = -1.0f;
m_water_splash = false;
m_is_jump_texture = false;
m_has_gravity = false;
m_complain_if_not_found = true;

View File

@ -95,14 +95,17 @@ private:
ShaderType m_shader_type;
/** Either ' ' (no mirroring), 'U' or 'V' if a texture needs to be
* mirrored when driving in reverse. Typically used for arrows indicating
* the direction. */
char m_mirror_axis_when_reverse;
/** Set if being on this surface means being under some other mesh.
* This is used to simulate that a kart is in water: the ground under
* the water is marked as 'm_below_surface', which will then trigger a raycast
* up to find the position of the actual water surface. */
bool m_below_surface;
bool m_water_splash;
/** If a kart is falling over a material with this flag set, it
* will trigger the special camera fall effect. */
bool m_falling_effect;
@ -128,34 +131,38 @@ private:
* upside down. */
bool m_has_gravity;
/** Speed of the 'main' wave in the water shader. Only used if
m_shader_type == SHDERTYPE_WATER */
float m_water_shader_speed_1;
/** Speed of the 'secondary' waves in the water shader. Only used if
m_shader_type == SHADERTYPE_WATER */
float m_water_shader_speed_2;
/** If a kart is rescued when crashing into this surface. */
CollisionReaction m_collision_reaction;
/** Particles to show on touch */
std::string m_collision_particles;
/** If m_shader_type == SHADERTYPE_VEGETATION */
float m_grass_speed;
float m_grass_amplitude;
/** If the property should be ignored in the physics. Example would be
* plants that a kart can just drive through. */
bool m_ignore;
bool m_fog;
/** Either ' ' (no mirroring), 'U' or 'V' if a texture needs to be
* mirrored when driving in reverse. Typically used for arrows indicating
* the direction. */
char m_mirror_axis_when_reverse;
/** True if backface culliing should be enabled. */
bool m_backface_culling;
/** Set to true to disable writing to the Z buffer. Usually to be used with alpha blending */
bool m_disable_z_write;
/** True if the material shouldn't be "slippy" at an angle */
bool m_high_tire_adhesion;
bool m_complain_if_not_found;
bool m_deprecated;
bool m_installed;
/** True if this material can be colorized (like red/blue in team game). */
bool m_colorizable;
/** Minimum resulting saturation when colorized (from 0 to 1) */
float m_colorization_factor;
/** If a kart is rescued when crashing into this surface. */
CollisionReaction m_collision_reaction;
/** Particles to show on touch */
std::string m_collision_particles;
/**
* Associated with m_mirror_axis_when_reverse, to avoid mirroring the same material twice
@ -168,35 +175,12 @@ private:
/** Texture clamp bitmask */
unsigned int m_clamp_tex;
/** True if backface culliing should be enabled. */
bool m_backface_culling;
/** Set to true to disable writing to the Z buffer. Usually to be used with alpha blending */
bool m_disable_z_write;
/** True if this material can be colorized (like red/blue in team game). */
bool m_colorizable;
/** Minimum resulting saturation when colorized (from 0 to 1) */
float m_colorization_factor;
/** List of hue pre-defined for colorization (from 0 to 1) */
std::vector<float> m_hue_settings;
/** Random generator for getting pre-defined hue */
RandomGenerator m_random_hue;
/** Some textures need to be pre-multiplied, some divided to give
* the intended effect. */
//enum {ADJ_NONE, ADJ_PREMUL, ADJ_DIV}
// m_adjust_image;
/** True if lightmapping is enabled for this material. */
//bool m_lightmap;
/** True if the material shouldn't be "slippy" at an angle */
bool m_high_tire_adhesion;
/** How much the top speed is reduced per second. */
float m_slowdown_time;
@ -240,12 +224,6 @@ private:
std::string m_colorization_mask;
bool m_complain_if_not_found;
bool m_deprecated;
bool m_installed;
void init ();
void install (bool srgb = false, bool premul_alpha = false);
void initCustomSFX(const XMLNode *sfx);
@ -256,6 +234,8 @@ private:
std::string m_uv_two_tex;
// Full path for textures in sp shader
std::string m_sampler_path[6];
std::string m_container_id;
void loadContainerId();
public:
Material(const XMLNode *node, bool deprecated);
@ -426,6 +406,8 @@ public:
assert(layer < 6);
return m_sampler_path[layer];
}
// ------------------------------------------------------------------------
const std::string& getContainerId() const { return m_container_id; }
};

View File

@ -68,12 +68,13 @@ MaterialManager::~MaterialManager()
delete it->second;
}
for (std::map<std::string, Material*> ::iterator it =
m_sp_materials.begin(); it != m_sp_materials.end(); it++)
m_default_sp_materials.begin(); it != m_default_sp_materials.end();
it++)
{
delete it->second;
}
m_default_materials.clear();
m_sp_materials.clear();
m_default_sp_materials.clear();
} // ~MaterialManager
//-----------------------------------------------------------------------------
@ -141,7 +142,7 @@ Material* MaterialManager::getMaterialSPM(std::string lay_one_tex_lc,
}
} // for i
}
return getSPMaterial(def_shader_name,
return getDefaultSPMaterial(def_shader_name,
StringUtils::getBasename(orignal_layer_one));
}
@ -212,22 +213,22 @@ void MaterialManager::setAllMaterialFlags(video::ITexture* t,
} // setAllMaterialFlags
//-----------------------------------------------------------------------------
Material* MaterialManager::getSPMaterial(const std::string& shader_name,
const std::string& layer_one_lc)
Material* MaterialManager::getDefaultSPMaterial(const std::string& shader_name,
const std::string& l1_lc)
{
core::stringc lc(layer_one_lc.c_str());
core::stringc lc(l1_lc.c_str());
lc.make_lower();
const std::string key = shader_name + lc.c_str();
auto ret = m_sp_materials.find(key);
if (ret != m_sp_materials.end())
auto ret = m_default_sp_materials.find(key);
if (ret != m_default_sp_materials.end())
{
return ret->second;
}
Material* m = new Material(layer_one_lc.empty() ? "unicolor_white" :
layer_one_lc, false, false, false, shader_name);
m_sp_materials[key] = m;
Material* m = new Material(l1_lc.empty() ? "unicolor_white" :
l1_lc, false, false, false, shader_name);
m_default_sp_materials[key] = m;
return m;
} // getSPMaterial
} // getDefaultSPMaterial
//-----------------------------------------------------------------------------
Material* MaterialManager::getDefaultMaterial(video::E_MATERIAL_TYPE shader_type)

View File

@ -51,7 +51,7 @@ private:
std::vector<Material*> m_materials;
std::map<video::E_MATERIAL_TYPE, Material*> m_default_materials;
std::map<std::string, Material*> m_sp_materials;
std::map<std::string, Material*> m_default_sp_materials;
Material* getDefaultMaterial(video::E_MATERIAL_TYPE material_type);
public:
@ -90,7 +90,7 @@ public:
void unloadAllTextures();
Material* getSPMaterial(const std::string& shader_name, const std::string& layer_one_lc = "");
Material* getDefaultSPMaterial(const std::string& shader_name, const std::string& layer_one_lc = "");
Material* getLatestMaterial() { return m_materials[m_materials.size()-1]; }
}; // MaterialManager

View File

@ -34,7 +34,7 @@ ShowCurve::ShowCurve(float width, float height,
{
m_dy_dc = std::make_shared<SP::SPDynamicDrawCall>
(irr::scene::EPT_TRIANGLES, SP::getSPShader("alphablend"),
material_manager->getSPMaterial("alphablend"));
material_manager->getDefaultSPMaterial("alphablend"));
SP::addDynamicDrawCall(m_dy_dc);
} // ShowCurve

View File

@ -81,7 +81,7 @@ SlipStream::SlipStream(AbstractKart* kart) : MovingTexture(0, 0), m_kart(kart)
{
m_debug_dc = std::make_shared<SP::SPDynamicDrawCall>
(scene::EPT_TRIANGLE_STRIP, SP::getSPShader("additive"),
material_manager->getSPMaterial("additive"));
material_manager->getDefaultSPMaterial("additive"));
m_debug_dc->getVerticesVector().resize(4);
video::S3DVertexSkinnedMesh* v =
m_debug_dc->getVerticesVector().data();

View File

@ -1785,7 +1785,7 @@ SPMesh* convertEVTStandard(irr::scene::IMesh* mesh,
const irr::video::SColor* color)
{
SPMesh* spm = new SPMesh();
Material* material = material_manager->getSPMaterial("solid");
Material* material = material_manager->getDefaultSPMaterial("solid");
for (unsigned i = 0; i < mesh->getMeshBufferCount(); i++)
{
std::vector<video::S3DVertexSkinnedMesh> vertices;

View File

@ -42,7 +42,8 @@ SPDynamicDrawCall::SPDynamicDrawCall(scene::E_PRIMITIVE_TYPE pt,
m_textures[0][j] = SPTextureManager::get()->getTexture
(std::get<2>(m_stk_material[0])->getSamplerPath(j),
j == 0 ? std::get<2>(m_stk_material[0]) : NULL,
j < 2 && CVS->isDefferedEnabled());
j < 2 && CVS->isDefferedEnabled(),
std::get<2>(m_stk_material[0])->getContainerId());
}
m_tex_cmp[m_textures[0][0]->getPath() + m_textures[0][1]->getPath()] = 0;
m_pitch = 48;

View File

@ -163,7 +163,8 @@ void SPMeshBuffer::uploadGLMesh()
m_textures[i][j] = SPTextureManager::get()->getTexture
(std::get<2>(m_stk_material[i])->getSamplerPath(j),
j == 0 ? std::get<2>(m_stk_material[i]) : NULL,
j < 2 && CVS->isDefferedEnabled());
j < 2 && CVS->isDefferedEnabled(),
std::get<2>(m_stk_material[i])->getContainerId());
}
// Use .spm uv texture 1 and 2 for compare in scene manager
m_tex_cmp[m_textures[i][0]->getPath() + m_textures[i][1]->getPath()] =

View File

@ -50,7 +50,7 @@ namespace SP
{
// ----------------------------------------------------------------------------
SPTexture::SPTexture(const std::string& path, Material* m, bool undo_srgb,
int ta_idx)
int ta_idx, const std::string& container_id)
: m_path(path), m_texture_array_idx(ta_idx), m_width(0), m_height(0),
m_material(m), m_undo_srgb(undo_srgb)
{
@ -63,34 +63,25 @@ SPTexture::SPTexture(const std::string& path, Material* m, bool undo_srgb,
createWhite(false/*private_init*/);
if (!CVS->isTextureCompressionEnabled())
if (!CVS->isTextureCompressionEnabled() || container_id.empty())
{
return;
}
std::string basename = StringUtils::getBasename(m_path);
std::string container_id;
if (file_manager->searchTextureContainerId(container_id, basename))
{
std::string cache_subdir = "hd/";
if ((UserConfigParams::m_high_definition_textures & 0x01) == 0x01)
{
cache_subdir = "hd/";
}
else
{
cache_subdir = StringUtils::insertValues("resized_%i/",
(int)UserConfigParams::m_max_texture_size);
}
m_cache_directory = file_manager->getCachedTexturesDir() +
cache_subdir + container_id;
file_manager->checkAndCreateDirectoryP(m_cache_directory);
}
if (m_cache_directory.empty())
std::string cache_subdir = "hd/";
if ((UserConfigParams::m_high_definition_textures & 0x01) == 0x01)
{
Log::warn("SPTexture", "Missing container info for %s, no texture"
" compression cache.", m_path.c_str());
cache_subdir = "hd/";
}
else
{
cache_subdir = StringUtils::insertValues("resized_%i/",
(int)UserConfigParams::m_max_texture_size);
}
m_cache_directory = file_manager->getCachedTexturesDir() +
cache_subdir + container_id;
file_manager->checkAndCreateDirectoryP(m_cache_directory);
#endif
} // SPTexture
@ -609,7 +600,8 @@ bool SPTexture::threadedLoad()
}
else
{
if (CVS->isTextureCompressionEnabled() && image &&
if (!m_cache_directory.empty() &&
CVS->isTextureCompressionEnabled() && image &&
image->getDimension().Width >= 4 &&
image->getDimension().Height >= 4)
{

View File

@ -186,7 +186,7 @@ public:
}
// ------------------------------------------------------------------------
SPTexture(const std::string& path, Material* m, bool undo_srgb,
int ta_idx);
int ta_idx, const std::string& container_id);
// ------------------------------------------------------------------------
~SPTexture();
// ------------------------------------------------------------------------

View File

@ -225,7 +225,8 @@ void SPTextureManager::checkForGLCommand(bool before_scene)
// ----------------------------------------------------------------------------
std::shared_ptr<SPTexture> SPTextureManager::getTexture(const std::string& p,
Material* m,
bool undo_srgb)
bool undo_srgb,
const std::string& cid)
{
checkForGLCommand();
auto ret = m_textures.find(p);
@ -247,7 +248,7 @@ std::shared_ptr<SPTexture> SPTextureManager::getTexture(const std::string& p,
}
std::shared_ptr<SPTexture> t =
std::make_shared<SPTexture>(p, m, undo_srgb, ta_idx);
std::make_shared<SPTexture>(p, m, undo_srgb, ta_idx, cid);
addThreadedFunction(std::bind(&SPTexture::threadedLoad, t));
m_textures[p] = t;
return t;

View File

@ -112,7 +112,8 @@ public:
void checkForGLCommand(bool before_scene = false);
// ------------------------------------------------------------------------
std::shared_ptr<SPTexture> getTexture(const std::string& p,
Material* m, bool undo_srgb);
Material* m, bool undo_srgb,
const std::string& container_id);
// ------------------------------------------------------------------------
int dumpTextureUsage();
// ------------------------------------------------------------------------

View File

@ -61,7 +61,7 @@ RubberBand::RubberBand(Plunger *plunger, AbstractKart *kart)
}
m_dy_dc = std::make_shared<SP::SPDynamicDrawCall>
(scene::EPT_TRIANGLE_STRIP, SP::getSPShader("unlit"),
material_manager->getSPMaterial("unlit"));
material_manager->getDefaultSPMaterial("unlit"));
m_dy_dc->getVerticesVector().resize(4);
// Set the vertex colors properly, as the new pipeline doesn't use the old
// light values

View File

@ -104,7 +104,8 @@ FeatureUnlockedCutScene::UnlockedThing::UnlockedThing(irr::video::ITexture* pict
if (CVS->isGLSL())
{
m_sp_pictures.push_back(SP::SPTextureManager::get()
->getTexture(pict->getName().getPtr(), NULL, true));
->getTexture(pict->getName().getPtr(), NULL, true,
""/*container_id*/));
}
else
{
@ -131,7 +132,8 @@ FeatureUnlockedCutScene::UnlockedThing::UnlockedThing(std::vector<irr::video::IT
for (auto* pict : picts)
{
m_sp_pictures.push_back(SP::SPTextureManager::get()
->getTexture(pict->getName().getPtr(), NULL, true));
->getTexture(pict->getName().getPtr(), NULL, true,
""/*container_id*/));
}
}
else

View File

@ -69,7 +69,7 @@ CheckCannon::CheckCannon(const XMLNode &node, unsigned int index)
{
m_debug_target_dy_dc = std::make_shared<SP::SPDynamicDrawCall>
(scene::EPT_TRIANGLE_STRIP, SP::getSPShader("additive"),
material_manager->getSPMaterial("additive"));
material_manager->getDefaultSPMaterial("additive"));
SP::addDynamicDrawCall(m_debug_target_dy_dc);
m_debug_target_dy_dc->getVerticesVector().resize(4);
auto& vertices = m_debug_target_dy_dc->getVerticesVector();

View File

@ -78,7 +78,7 @@ CheckLine::CheckLine(const XMLNode &node, unsigned int index)
#ifndef SERVER_ONLY
m_debug_dy_dc = std::make_shared<SP::SPDynamicDrawCall>
(scene::EPT_TRIANGLE_STRIP, SP::getSPShader("additive"),
material_manager->getSPMaterial("additive"));
material_manager->getDefaultSPMaterial("additive"));
SP::addDynamicDrawCall(m_debug_dy_dc);
m_debug_dy_dc->getVerticesVector().resize(4);
auto& vertices = m_debug_dy_dc->getVerticesVector();

View File

@ -348,7 +348,7 @@ void Graph::createMeshSP(bool show_invisible, bool enable_transparency,
spmb->setSPMVertices(vertices);
spmb->setIndices(indices);
spmb->recalculateBoundingBox();
spmb->setSTKMaterial(material_manager->getSPMaterial(
spmb->setSTKMaterial(material_manager->getDefaultSPMaterial(
enable_transparency ? "alphablend" : "unlit"));
spm->addSPMeshBuffer(spmb);
spm->setBoundingBox(spmb->getBoundingBox());