Apply mask directly on texture
Avoiding the ref counting issues
This commit is contained in:
parent
5e415e3331
commit
ffe4dd88b4
@ -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,11 @@
|
||||
#include "utils/vs.hpp"
|
||||
|
||||
#include <irrlicht.h>
|
||||
#if defined(USE_GLES2)
|
||||
#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,8 +1823,8 @@ 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)
|
||||
{
|
||||
video::IImage* img =
|
||||
m_video_driver->createImage(texture, core::position2d<s32>(0,0),
|
||||
@ -1828,9 +1833,15 @@ video::ITexture* IrrDriver::applyMask(video::ITexture* texture,
|
||||
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())
|
||||
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 +1855,30 @@ 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;
|
||||
} // 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);
|
||||
|
@ -517,20 +517,7 @@ void Material::install(bool is_full_path, bool complain_if_not_found)
|
||||
|
||||
if (m_mask.size() > 0)
|
||||
{
|
||||
m_texture->grab();
|
||||
irr_driver->removeTexture(m_texture);
|
||||
video::ITexture* tex = irr_driver->applyMask(m_texture, m_mask);
|
||||
if (tex)
|
||||
{
|
||||
// TODO: cleanup
|
||||
//m_texture->drop();
|
||||
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
|
||||
|
@ -271,6 +271,7 @@ private:
|
||||
bool m_installed;
|
||||
|
||||
void init ();
|
||||
void install (bool is_full_path=false, bool complain_if_not_found=true);
|
||||
void initCustomSFX(const XMLNode *sfx);
|
||||
void initParticlesEffect(const XMLNode *node);
|
||||
|
||||
@ -282,8 +283,7 @@ public:
|
||||
bool load_texture = true);
|
||||
~Material ();
|
||||
|
||||
void install(bool is_full_path = false, bool complain_if_not_found = true);
|
||||
void unloadTexture();
|
||||
void unloadTexture();
|
||||
|
||||
void setSFXSpeed(SFXBase *sfx, float speed, bool should_be_paused) const;
|
||||
void setMaterialProperties(video::SMaterial *m, scene::IMeshBuffer* mb);
|
||||
|
@ -395,18 +395,6 @@ void MaterialManager::unloadAllTextures()
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void MaterialManager::installAllTextures()
|
||||
{
|
||||
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]->install(true, true);
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
bool MaterialManager::hasMaterial(const std::string& fname)
|
||||
{
|
||||
|
@ -83,7 +83,6 @@ public:
|
||||
void makeMaterialsPermanent();
|
||||
bool hasMaterial(const std::string& fname);
|
||||
|
||||
void installAllTextures();
|
||||
void unloadAllTextures();
|
||||
|
||||
Material* getLatestMaterial() { return m_materials[m_materials.size()-1]; }
|
||||
|
@ -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"
|
||||
|
||||
|
@ -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"
|
||||
|
@ -1645,14 +1645,10 @@ void Track::loadTrackModel(bool reverse_track, unsigned int mode_id)
|
||||
{
|
||||
if(!m_materials_loaded)
|
||||
material_manager->addSharedMaterial(materials_file);
|
||||
material_manager->installAllTextures();
|
||||
m_materials_loaded = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
material_manager->pushTempMaterial(materials_file);
|
||||
material_manager->installAllTextures();
|
||||
}
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user