Merge branch 'fix_2316'
This commit is contained in:
commit
dfca641172
@ -109,6 +109,13 @@ public:
|
||||
//! Get an access to texture states cache.
|
||||
SStatesCache& getStatesCache() const;
|
||||
|
||||
void setImage(IImage* new_image)
|
||||
{
|
||||
if (Image)
|
||||
Image->drop();
|
||||
Image = new_image;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
//! protected constructor with basic setup, no GL texture name created, for derived classes
|
||||
|
@ -103,6 +103,13 @@ public:
|
||||
//! sets whether this texture is intended to be used as a render target.
|
||||
void setIsRenderTarget(bool isTarget);
|
||||
|
||||
void setImage(IImage* new_image)
|
||||
{
|
||||
if (Image)
|
||||
Image->drop();
|
||||
Image = new_image;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
//! protected constructor with basic setup, no GL texture name created, for derived classes
|
||||
|
@ -65,6 +65,12 @@
|
||||
#include "utils/vs.hpp"
|
||||
|
||||
#include <irrlicht.h>
|
||||
#if defined(USE_GLES2)
|
||||
#define _IRR_COMPILE_WITH_OGLES2_
|
||||
#include "../../lib/irrlicht/source/Irrlicht/COGLES2Texture.h"
|
||||
#else
|
||||
#include "../../lib/irrlicht/source/Irrlicht/COpenGLTexture.h"
|
||||
#endif
|
||||
|
||||
/* Build-time check that the Irrlicht we're building against works for us.
|
||||
* Should help prevent distros building against an incompatible library.
|
||||
@ -1818,19 +1824,35 @@ void IrrDriver::dropAllTextures(const scene::IMesh *mesh)
|
||||
} // dropAllTextures
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
video::ITexture* IrrDriver::applyMask(video::ITexture* texture,
|
||||
const std::string& mask_path)
|
||||
void IrrDriver::applyMask(video::ITexture* texture,
|
||||
const std::string& mask_path)
|
||||
{
|
||||
#ifndef SERVER_ONLY
|
||||
const core::dimension2d<u32> size = texture->getSize();
|
||||
video::IImage* img =
|
||||
m_video_driver->createImage(texture, core::position2d<s32>(0,0),
|
||||
texture->getSize());
|
||||
m_video_driver->createImage(texture, core::position2d<s32>(0,0), size);
|
||||
|
||||
video::IImage* mask =
|
||||
m_video_driver->createImageFromFile(mask_path.c_str());
|
||||
|
||||
if (img == NULL || mask == NULL) return NULL;
|
||||
if (img == NULL || mask == NULL)
|
||||
{
|
||||
Log::warn("irr_driver", "Applying mask failed for '%s'!",
|
||||
core::stringc(texture->getName()).c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
if (img->lock() && mask->lock())
|
||||
if (mask->getDimension() != size)
|
||||
{
|
||||
video::IImage* mask_scaled =
|
||||
m_video_driver->createImage(texture->getColorFormat(), size);
|
||||
mask->copyToScaling(mask_scaled);
|
||||
mask->drop();
|
||||
mask = mask_scaled;
|
||||
}
|
||||
|
||||
void* dest = img->lock();
|
||||
if (dest != NULL && mask->lock())
|
||||
{
|
||||
core::dimension2d<u32> dim = img->getDimension();
|
||||
for (unsigned int x = 0; x < dim.Width; x++)
|
||||
@ -1844,20 +1866,31 @@ video::ITexture* IrrDriver::applyMask(video::ITexture* texture,
|
||||
} // for y
|
||||
} // for x
|
||||
|
||||
if (!CVS->isGLSL())
|
||||
{
|
||||
// For new graphical pipeline, it will be done in texture manager
|
||||
// compressTexture
|
||||
glBindTexture(GL_TEXTURE_2D, getTextureGLuint(texture));
|
||||
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, dim.Width, dim.Height,
|
||||
GL_BGRA, GL_UNSIGNED_BYTE, dest);
|
||||
glGenerateMipmap(GL_TEXTURE_2D);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
}
|
||||
mask->unlock();
|
||||
img->unlock();
|
||||
#if defined(USE_GLES2)
|
||||
static_cast<irr::video::COGLES2Texture*>(texture)->setImage(img);
|
||||
#else
|
||||
static_cast<irr::video::COpenGLTexture*>(texture)->setImage(img);
|
||||
#endif
|
||||
mask->drop();
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
std::string base =
|
||||
StringUtils::getBasename(texture->getName().getPath().c_str());
|
||||
video::ITexture *t = m_video_driver->addTexture(base.c_str(),img, NULL);
|
||||
Log::warn("irr_driver", "Applying mask failed for '%s'!",
|
||||
core::stringc(texture->getName()).c_str());
|
||||
img->drop();
|
||||
mask->drop();
|
||||
return t;
|
||||
#endif
|
||||
} // applyMask
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
@ -220,7 +220,7 @@ public:
|
||||
void setAllMaterialFlags(scene::IMesh *mesh) const;
|
||||
scene::IAnimatedMesh *getAnimatedMesh(const std::string &name);
|
||||
scene::IMesh *getMesh(const std::string &name);
|
||||
video::ITexture *applyMask(video::ITexture* texture,
|
||||
void applyMask(video::ITexture* texture,
|
||||
const std::string& mask_path);
|
||||
void displayFPS();
|
||||
bool OnEvent(const irr::SEvent &event);
|
||||
|
@ -59,6 +59,7 @@ Material::Material(const XMLNode *node, bool deprecated)
|
||||
{
|
||||
m_shader_type = SHADERTYPE_SOLID;
|
||||
m_deprecated = deprecated;
|
||||
m_installed = false;
|
||||
|
||||
node->get("name", &m_texname);
|
||||
if (m_texname=="")
|
||||
@ -74,7 +75,6 @@ Material::Material(const XMLNode *node, bool deprecated)
|
||||
m_full_path = file_manager->getFileSystem()->getAbsolutePath(relativePath.c_str()).c_str();
|
||||
init();
|
||||
|
||||
node->get("dont-load", &m_dont_load_texture);
|
||||
bool b = false;
|
||||
|
||||
node->get("clampu", &b); if (b) m_clamp_tex |= UCLAMP; //blender 2.4 style
|
||||
@ -397,9 +397,17 @@ Material::Material(const XMLNode *node, bool deprecated)
|
||||
|
||||
if(m_has_gravity)
|
||||
m_high_tire_adhesion = true;
|
||||
|
||||
install(/*is_full_path*/false);
|
||||
} // Material
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
video::ITexture* Material::getTexture()
|
||||
{
|
||||
if (!m_installed)
|
||||
{
|
||||
install(/*is_full_path*/true);
|
||||
}
|
||||
return m_texture;
|
||||
} // getTexture
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Create a standard material using the default settings for materials.
|
||||
@ -410,14 +418,16 @@ Material::Material(const std::string& fname, bool is_full_path,
|
||||
bool complain_if_not_found, bool load_texture)
|
||||
{
|
||||
m_deprecated = false;
|
||||
|
||||
m_installed = false;
|
||||
m_texname = fname;
|
||||
init();
|
||||
m_full_path = file_manager->getFileSystem()->getAbsolutePath(
|
||||
file_manager->searchTexture(m_texname).c_str()).c_str();
|
||||
|
||||
m_complain_if_not_found = complain_if_not_found;
|
||||
|
||||
if (load_texture)
|
||||
install(is_full_path, complain_if_not_found);
|
||||
install(is_full_path);
|
||||
} // Material
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -425,7 +435,6 @@ Material::Material(const std::string& fname, bool is_full_path,
|
||||
*/
|
||||
void Material::init()
|
||||
{
|
||||
m_dont_load_texture = false;
|
||||
m_texture = NULL;
|
||||
m_clamp_tex = 0;
|
||||
m_shader_type = SHADERTYPE_SOLID;
|
||||
@ -463,7 +472,7 @@ void Material::init()
|
||||
m_water_splash = false;
|
||||
m_is_jump_texture = false;
|
||||
m_has_gravity = false;
|
||||
|
||||
m_complain_if_not_found = true;
|
||||
for (int n=0; n<EMIT_KINDS_COUNT; n++)
|
||||
{
|
||||
m_particles_effects[n] = NULL;
|
||||
@ -471,16 +480,18 @@ void Material::init()
|
||||
} // init
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void Material::install(bool is_full_path, bool complain_if_not_found)
|
||||
void Material::install(bool is_full_path)
|
||||
{
|
||||
// Don't load a texture that are not supposed to be loaded automatically
|
||||
if(m_dont_load_texture) return;
|
||||
if (m_installed) return;
|
||||
|
||||
m_installed = true;
|
||||
|
||||
const std::string &full_path = is_full_path
|
||||
? m_texname
|
||||
: file_manager->searchTexture(m_texname);
|
||||
|
||||
if (complain_if_not_found && full_path.size() == 0)
|
||||
if (m_complain_if_not_found && full_path.size() == 0)
|
||||
{
|
||||
Log::error("material", "Cannot find texture '%s'.", m_texname.c_str());
|
||||
m_texture = NULL;
|
||||
@ -491,7 +502,7 @@ void Material::install(bool is_full_path, bool complain_if_not_found)
|
||||
m_texture = irr_driver->getTexture(full_path,
|
||||
false, //isPreMul(),
|
||||
false, //isPreDiv(),
|
||||
complain_if_not_found);
|
||||
m_complain_if_not_found);
|
||||
}
|
||||
|
||||
if (m_texture == NULL) return;
|
||||
@ -501,17 +512,7 @@ void Material::install(bool is_full_path, bool complain_if_not_found)
|
||||
|
||||
if (m_mask.size() > 0)
|
||||
{
|
||||
video::ITexture* tex = irr_driver->applyMask(m_texture, m_mask);
|
||||
if (tex)
|
||||
{
|
||||
irr_driver->removeTexture(m_texture);
|
||||
m_texture = tex;
|
||||
}
|
||||
else
|
||||
{
|
||||
Log::warn("material", "Applying mask failed for '%s'!",
|
||||
m_texname.c_str());
|
||||
}
|
||||
irr_driver->applyMask(m_texture, m_mask);
|
||||
}
|
||||
m_texture->grab();
|
||||
} // install
|
||||
@ -519,12 +520,7 @@ void Material::install(bool is_full_path, bool complain_if_not_found)
|
||||
//-----------------------------------------------------------------------------
|
||||
Material::~Material()
|
||||
{
|
||||
if (m_texture != NULL)
|
||||
{
|
||||
m_texture->drop();
|
||||
if(m_texture->getReferenceCount()==1)
|
||||
irr_driver->removeTexture(m_texture);
|
||||
}
|
||||
unloadTexture();
|
||||
|
||||
// If a special sfx is installed (that isn't part of stk itself), the
|
||||
// entry needs to be removed from the sfx_manager's mapping, since other
|
||||
@ -535,6 +531,22 @@ Material::~Material()
|
||||
}
|
||||
} // ~Material
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void Material::unloadTexture()
|
||||
{
|
||||
if (m_texture != NULL)
|
||||
{
|
||||
m_texture->drop();
|
||||
if (m_texture->getReferenceCount() == 1)
|
||||
{
|
||||
irr_driver->removeTexture(m_texture);
|
||||
}
|
||||
m_texture = NULL;
|
||||
m_installed = false;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Initialise the data structures for a custom sfx to be played when a
|
||||
* kart is driving on that particular material.
|
||||
@ -708,6 +720,11 @@ void Material::setSFXSpeed(SFXBase *sfx, float speed, bool should_be_paused) con
|
||||
*/
|
||||
void Material::setMaterialProperties(video::SMaterial *m, scene::IMeshBuffer* mb)
|
||||
{
|
||||
if (!m_installed)
|
||||
{
|
||||
install(/*is_full_path*/true);
|
||||
}
|
||||
|
||||
if (m_deprecated ||
|
||||
(m->getTexture(0) != NULL &&
|
||||
((core::stringc)m->getTexture(0)->getName()).find("deprecated") != -1))
|
||||
|
@ -92,12 +92,6 @@ private:
|
||||
|
||||
std::string m_full_path;
|
||||
|
||||
/** If true, the texture will not automatically be loaded and bound
|
||||
* at load time, it must be loaded elsewhere. This is used to store
|
||||
* material settings for font textures, without loading fonts for
|
||||
* languages that might not be needed at all. */
|
||||
bool m_dont_load_texture;
|
||||
|
||||
/** Name of a special sfx to play when a kart is on this terrain, or
|
||||
* "" if no special sfx exists. */
|
||||
std::string m_sfx_name;
|
||||
@ -266,10 +260,14 @@ private:
|
||||
|
||||
std::string m_gloss_map;
|
||||
|
||||
bool m_complain_if_not_found;
|
||||
|
||||
bool m_deprecated;
|
||||
|
||||
bool m_installed;
|
||||
|
||||
void init ();
|
||||
void install (bool is_full_path=false, bool complain_if_not_found=true);
|
||||
void install (bool is_full_path=false);
|
||||
void initCustomSFX(const XMLNode *sfx);
|
||||
void initParticlesEffect(const XMLNode *node);
|
||||
|
||||
@ -281,6 +279,8 @@ public:
|
||||
bool load_texture = true);
|
||||
~Material ();
|
||||
|
||||
void unloadTexture();
|
||||
|
||||
void setSFXSpeed(SFXBase *sfx, float speed, bool should_be_paused) const;
|
||||
void setMaterialProperties(video::SMaterial *m, scene::IMeshBuffer* mb);
|
||||
void adjustForFog(scene::ISceneNode* parent, video::SMaterial *m,
|
||||
@ -290,14 +290,7 @@ public:
|
||||
void isInitiallyHidden(scene::IMeshBuffer* who);
|
||||
|
||||
/** Returns the ITexture associated with this material. */
|
||||
video::ITexture *getTexture() const
|
||||
{
|
||||
// Note that dont load means that the textures are not loaded
|
||||
// via the material. So getTexture should only get called for
|
||||
// automatically loaded textures (used atm for font textures).
|
||||
assert(!m_dont_load_texture);
|
||||
return m_texture;
|
||||
} // getTexture
|
||||
video::ITexture *getTexture();
|
||||
// ------------------------------------------------------------------------
|
||||
bool isIgnore () const { return m_ignore; }
|
||||
// ------------------------------------------------------------------------
|
||||
|
@ -86,13 +86,16 @@ Material* MaterialManager::getMaterialFor(video::ITexture* t,
|
||||
return getDefaultMaterial(material_type);
|
||||
|
||||
core::stringc img_path = core::stringc(t->getName());
|
||||
const std::string image = StringUtils::getBasename(img_path.c_str());
|
||||
img_path.make_lower();
|
||||
|
||||
if (!img_path.empty() && (img_path.findFirst('/') != -1 || img_path.findFirst('\\') != -1))
|
||||
{
|
||||
// Search backward so that temporary (track) textures are found first
|
||||
for (int i = (int)m_materials.size() - 1; i >= 0; i--)
|
||||
{
|
||||
if (m_materials[i]->getTexFullPath() == img_path.c_str())
|
||||
core::stringc fullpath = core::stringc(m_materials[i]->getTexFullPath().c_str());
|
||||
fullpath.make_lower();
|
||||
if (fullpath == img_path.c_str())
|
||||
{
|
||||
return m_materials[i];
|
||||
}
|
||||
@ -100,9 +103,14 @@ Material* MaterialManager::getMaterialFor(video::ITexture* t,
|
||||
}
|
||||
else
|
||||
{
|
||||
core::stringc image(StringUtils::getBasename(img_path.c_str()).c_str());
|
||||
image.make_lower();
|
||||
|
||||
for (int i = (int)m_materials.size() - 1; i >= 0; i--)
|
||||
{
|
||||
if (m_materials[i]->getTexFname() == image)
|
||||
core::stringc texfname(m_materials[i]->getTexFname().c_str());
|
||||
texfname.make_lower();
|
||||
if (texfname == image)
|
||||
{
|
||||
return m_materials[i];
|
||||
}
|
||||
@ -139,7 +147,7 @@ Material* MaterialManager::getDefaultMaterial(video::E_MATERIAL_TYPE shader_type
|
||||
auto it = m_default_materials.find(shader_type);
|
||||
if (it == m_default_materials.end())
|
||||
{
|
||||
Material* default_material = new Material("", false, false, false);
|
||||
Material* default_material = new Material("Default", false, false, false);
|
||||
|
||||
// TODO: workaround, should not hardcode these material types here?
|
||||
// Try to find a cleaner way
|
||||
@ -339,10 +347,16 @@ Material *MaterialManager::getMaterial(const std::string& fname,
|
||||
else
|
||||
basename = fname;
|
||||
|
||||
core::stringc basename_lower(basename.c_str());
|
||||
basename_lower.make_lower();
|
||||
|
||||
// Search backward so that temporary (track) textures are found first
|
||||
for(int i = (int)m_materials.size()-1; i>=0; i-- )
|
||||
for (int i = (int)m_materials.size()-1; i>=0; i-- )
|
||||
{
|
||||
if(m_materials[i]->getTexFname()==basename) return m_materials[i];
|
||||
core::stringc fname(m_materials[i]->getTexFname().c_str());
|
||||
fname.make_lower();
|
||||
if (fname == basename_lower)
|
||||
return m_materials[i];
|
||||
}
|
||||
|
||||
// Add the new material
|
||||
@ -365,6 +379,18 @@ void MaterialManager::makeMaterialsPermanent()
|
||||
m_shared_material_index = (int) m_materials.size();
|
||||
} // makeMaterialsPermanent
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void MaterialManager::unloadAllTextures()
|
||||
{
|
||||
std::string texture_folder = file_manager->getAssetDirectory(FileManager::TEXTURE);
|
||||
for (int i = 0; i < m_shared_material_index; i++)
|
||||
{
|
||||
if (m_materials[i]->getTexFullPath().find(texture_folder) != std::string::npos)
|
||||
m_materials[i]->unloadTexture();
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
bool MaterialManager::hasMaterial(const std::string& fname)
|
||||
{
|
||||
|
@ -83,6 +83,8 @@ public:
|
||||
void makeMaterialsPermanent();
|
||||
bool hasMaterial(const std::string& fname);
|
||||
|
||||
void unloadAllTextures();
|
||||
|
||||
Material* getLatestMaterial() { return m_materials[m_materials.size()-1]; }
|
||||
}; // MaterialManager
|
||||
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include "items/attachment_manager.hpp"
|
||||
|
||||
#include "graphics/irr_driver.hpp"
|
||||
#include "graphics/material.hpp"
|
||||
#include "graphics/material_manager.hpp"
|
||||
#include "io/file_manager.hpp"
|
||||
|
||||
|
@ -23,8 +23,8 @@ namespace irr
|
||||
{
|
||||
namespace scene { class IAnimatedMesh; }
|
||||
}
|
||||
class Material;
|
||||
|
||||
#include "graphics/material.hpp"
|
||||
#include "items/attachment.hpp"
|
||||
#include "utils/no_copy.hpp"
|
||||
|
||||
@ -49,7 +49,7 @@ public:
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the icon to display in the race gui if a kart
|
||||
* has an attachment. */
|
||||
const Material* getIcon (int type) const {return m_all_icons [type]; }
|
||||
Material* getIcon (int type) const { return m_all_icons [type]; }
|
||||
// ------------------------------------------------------------------------
|
||||
};
|
||||
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include "graphics/camera.hpp"
|
||||
#include "graphics/irr_driver.hpp"
|
||||
#include "graphics/material.hpp"
|
||||
#include "graphics/material_manager.hpp"
|
||||
#include "graphics/render_info.hpp"
|
||||
#include "io/file_manager.hpp"
|
||||
#include "input/device_manager.hpp"
|
||||
@ -430,6 +431,7 @@ Controller* World::loadAIController(AbstractKart *kart)
|
||||
//-----------------------------------------------------------------------------
|
||||
World::~World()
|
||||
{
|
||||
material_manager->unloadAllTextures();
|
||||
RewindManager::destroy();
|
||||
|
||||
irr_driver->onUnloadWorld();
|
||||
|
@ -31,6 +31,7 @@ using namespace irr;
|
||||
#include "graphics/glwrap.hpp"
|
||||
#endif
|
||||
#include "graphics/irr_driver.hpp"
|
||||
#include "graphics/material.hpp"
|
||||
#include "graphics/material_manager.hpp"
|
||||
#include "guiengine/engine.hpp"
|
||||
#include "guiengine/modaldialog.hpp"
|
||||
|
@ -29,6 +29,7 @@
|
||||
#include "graphics/glwrap.hpp"
|
||||
#endif
|
||||
#include "graphics/irr_driver.hpp"
|
||||
#include "graphics/material.hpp"
|
||||
#include "graphics/material_manager.hpp"
|
||||
#include "guiengine/engine.hpp"
|
||||
#include "guiengine/modaldialog.hpp"
|
||||
|
Loading…
Reference in New Issue
Block a user