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.
|
//! Get an access to texture states cache.
|
||||||
SStatesCache& getStatesCache() const;
|
SStatesCache& getStatesCache() const;
|
||||||
|
|
||||||
|
void setImage(IImage* new_image)
|
||||||
|
{
|
||||||
|
if (Image)
|
||||||
|
Image->drop();
|
||||||
|
Image = new_image;
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
//! protected constructor with basic setup, no GL texture name created, for derived classes
|
//! 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.
|
//! sets whether this texture is intended to be used as a render target.
|
||||||
void setIsRenderTarget(bool isTarget);
|
void setIsRenderTarget(bool isTarget);
|
||||||
|
|
||||||
|
void setImage(IImage* new_image)
|
||||||
|
{
|
||||||
|
if (Image)
|
||||||
|
Image->drop();
|
||||||
|
Image = new_image;
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
//! protected constructor with basic setup, no GL texture name created, for derived classes
|
//! protected constructor with basic setup, no GL texture name created, for derived classes
|
||||||
|
@ -65,6 +65,11 @@
|
|||||||
#include "utils/vs.hpp"
|
#include "utils/vs.hpp"
|
||||||
|
|
||||||
#include <irrlicht.h>
|
#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.
|
/* Build-time check that the Irrlicht we're building against works for us.
|
||||||
* Should help prevent distros building against an incompatible library.
|
* Should help prevent distros building against an incompatible library.
|
||||||
@ -1818,8 +1823,8 @@ void IrrDriver::dropAllTextures(const scene::IMesh *mesh)
|
|||||||
} // dropAllTextures
|
} // dropAllTextures
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
video::ITexture* IrrDriver::applyMask(video::ITexture* texture,
|
void IrrDriver::applyMask(video::ITexture* texture,
|
||||||
const std::string& mask_path)
|
const std::string& mask_path)
|
||||||
{
|
{
|
||||||
video::IImage* img =
|
video::IImage* img =
|
||||||
m_video_driver->createImage(texture, core::position2d<s32>(0,0),
|
m_video_driver->createImage(texture, core::position2d<s32>(0,0),
|
||||||
@ -1828,9 +1833,15 @@ video::ITexture* IrrDriver::applyMask(video::ITexture* texture,
|
|||||||
video::IImage* mask =
|
video::IImage* mask =
|
||||||
m_video_driver->createImageFromFile(mask_path.c_str());
|
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();
|
core::dimension2d<u32> dim = img->getDimension();
|
||||||
for (unsigned int x = 0; x < dim.Width; x++)
|
for (unsigned int x = 0; x < dim.Width; x++)
|
||||||
@ -1844,20 +1855,30 @@ video::ITexture* IrrDriver::applyMask(video::ITexture* texture,
|
|||||||
} // for y
|
} // for y
|
||||||
} // for x
|
} // 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();
|
mask->unlock();
|
||||||
img->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
|
Log::warn("irr_driver", "Applying mask failed for '%s'!",
|
||||||
{
|
core::stringc(texture->getName()).c_str());
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string base =
|
|
||||||
StringUtils::getBasename(texture->getName().getPath().c_str());
|
|
||||||
video::ITexture *t = m_video_driver->addTexture(base.c_str(),img, NULL);
|
|
||||||
img->drop();
|
img->drop();
|
||||||
mask->drop();
|
mask->drop();
|
||||||
return t;
|
|
||||||
} // applyMask
|
} // applyMask
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
@ -220,7 +220,7 @@ public:
|
|||||||
void setAllMaterialFlags(scene::IMesh *mesh) const;
|
void setAllMaterialFlags(scene::IMesh *mesh) const;
|
||||||
scene::IAnimatedMesh *getAnimatedMesh(const std::string &name);
|
scene::IAnimatedMesh *getAnimatedMesh(const std::string &name);
|
||||||
scene::IMesh *getMesh(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);
|
const std::string& mask_path);
|
||||||
void displayFPS();
|
void displayFPS();
|
||||||
bool OnEvent(const irr::SEvent &event);
|
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)
|
if (m_mask.size() > 0)
|
||||||
{
|
{
|
||||||
m_texture->grab();
|
irr_driver->applyMask(m_texture, m_mask);
|
||||||
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());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
m_texture->grab();
|
m_texture->grab();
|
||||||
} // install
|
} // install
|
||||||
|
@ -271,6 +271,7 @@ private:
|
|||||||
bool m_installed;
|
bool m_installed;
|
||||||
|
|
||||||
void init ();
|
void init ();
|
||||||
|
void install (bool is_full_path=false, bool complain_if_not_found=true);
|
||||||
void initCustomSFX(const XMLNode *sfx);
|
void initCustomSFX(const XMLNode *sfx);
|
||||||
void initParticlesEffect(const XMLNode *node);
|
void initParticlesEffect(const XMLNode *node);
|
||||||
|
|
||||||
@ -282,8 +283,7 @@ public:
|
|||||||
bool load_texture = true);
|
bool load_texture = true);
|
||||||
~Material ();
|
~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 setSFXSpeed(SFXBase *sfx, float speed, bool should_be_paused) const;
|
||||||
void setMaterialProperties(video::SMaterial *m, scene::IMeshBuffer* mb);
|
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)
|
bool MaterialManager::hasMaterial(const std::string& fname)
|
||||||
{
|
{
|
||||||
|
@ -83,7 +83,6 @@ public:
|
|||||||
void makeMaterialsPermanent();
|
void makeMaterialsPermanent();
|
||||||
bool hasMaterial(const std::string& fname);
|
bool hasMaterial(const std::string& fname);
|
||||||
|
|
||||||
void installAllTextures();
|
|
||||||
void unloadAllTextures();
|
void unloadAllTextures();
|
||||||
|
|
||||||
Material* getLatestMaterial() { return m_materials[m_materials.size()-1]; }
|
Material* getLatestMaterial() { return m_materials[m_materials.size()-1]; }
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
#include "items/attachment_manager.hpp"
|
#include "items/attachment_manager.hpp"
|
||||||
|
|
||||||
#include "graphics/irr_driver.hpp"
|
#include "graphics/irr_driver.hpp"
|
||||||
|
#include "graphics/material.hpp"
|
||||||
#include "graphics/material_manager.hpp"
|
#include "graphics/material_manager.hpp"
|
||||||
#include "io/file_manager.hpp"
|
#include "io/file_manager.hpp"
|
||||||
|
|
||||||
|
@ -23,8 +23,8 @@ namespace irr
|
|||||||
{
|
{
|
||||||
namespace scene { class IAnimatedMesh; }
|
namespace scene { class IAnimatedMesh; }
|
||||||
}
|
}
|
||||||
|
class Material;
|
||||||
|
|
||||||
#include "graphics/material.hpp"
|
|
||||||
#include "items/attachment.hpp"
|
#include "items/attachment.hpp"
|
||||||
#include "utils/no_copy.hpp"
|
#include "utils/no_copy.hpp"
|
||||||
|
|
||||||
|
@ -31,6 +31,7 @@ using namespace irr;
|
|||||||
#include "graphics/glwrap.hpp"
|
#include "graphics/glwrap.hpp"
|
||||||
#endif
|
#endif
|
||||||
#include "graphics/irr_driver.hpp"
|
#include "graphics/irr_driver.hpp"
|
||||||
|
#include "graphics/material.hpp"
|
||||||
#include "graphics/material_manager.hpp"
|
#include "graphics/material_manager.hpp"
|
||||||
#include "guiengine/engine.hpp"
|
#include "guiengine/engine.hpp"
|
||||||
#include "guiengine/modaldialog.hpp"
|
#include "guiengine/modaldialog.hpp"
|
||||||
|
@ -29,6 +29,7 @@
|
|||||||
#include "graphics/glwrap.hpp"
|
#include "graphics/glwrap.hpp"
|
||||||
#endif
|
#endif
|
||||||
#include "graphics/irr_driver.hpp"
|
#include "graphics/irr_driver.hpp"
|
||||||
|
#include "graphics/material.hpp"
|
||||||
#include "graphics/material_manager.hpp"
|
#include "graphics/material_manager.hpp"
|
||||||
#include "guiengine/engine.hpp"
|
#include "guiengine/engine.hpp"
|
||||||
#include "guiengine/modaldialog.hpp"
|
#include "guiengine/modaldialog.hpp"
|
||||||
|
@ -1645,14 +1645,10 @@ void Track::loadTrackModel(bool reverse_track, unsigned int mode_id)
|
|||||||
{
|
{
|
||||||
if(!m_materials_loaded)
|
if(!m_materials_loaded)
|
||||||
material_manager->addSharedMaterial(materials_file);
|
material_manager->addSharedMaterial(materials_file);
|
||||||
material_manager->installAllTextures();
|
|
||||||
m_materials_loaded = true;
|
m_materials_loaded = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
|
||||||
material_manager->pushTempMaterial(materials_file);
|
material_manager->pushTempMaterial(materials_file);
|
||||||
material_manager->installAllTextures();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (std::exception& e)
|
catch (std::exception& e)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user