Don't keep temporary images in RAM
parent
334ec4bb1b
commit
fcfd53aed1
33
src/tile.cpp
33
src/tile.cpp
|
@ -164,16 +164,13 @@ struct TextureInfo
|
||||||
{
|
{
|
||||||
std::string name;
|
std::string name;
|
||||||
video::ITexture *texture;
|
video::ITexture *texture;
|
||||||
video::IImage *img; // The source image
|
|
||||||
|
|
||||||
TextureInfo(
|
TextureInfo(
|
||||||
const std::string &name_,
|
const std::string &name_,
|
||||||
video::ITexture *texture_=NULL,
|
video::ITexture *texture_=NULL
|
||||||
video::IImage *img_=NULL
|
|
||||||
):
|
):
|
||||||
name(name_),
|
name(name_),
|
||||||
texture(texture_),
|
texture(texture_)
|
||||||
img(img_)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -460,10 +457,6 @@ TextureSource::~TextureSource()
|
||||||
//cleanup texture
|
//cleanup texture
|
||||||
if (iter->texture)
|
if (iter->texture)
|
||||||
driver->removeTexture(iter->texture);
|
driver->removeTexture(iter->texture);
|
||||||
|
|
||||||
//cleanup source image
|
|
||||||
if (iter->img)
|
|
||||||
iter->img->drop();
|
|
||||||
}
|
}
|
||||||
m_textureinfo_cache.clear();
|
m_textureinfo_cache.clear();
|
||||||
|
|
||||||
|
@ -666,23 +659,17 @@ u32 TextureSource::getTextureIdDirect(const std::string &name)
|
||||||
|
|
||||||
TextureInfo *ti = &m_textureinfo_cache[base_image_id];
|
TextureInfo *ti = &m_textureinfo_cache[base_image_id];
|
||||||
|
|
||||||
if(ti->img == NULL)
|
if(ti->texture == NULL)
|
||||||
{
|
{
|
||||||
infostream<<"getTextureIdDirect(): WARNING: NULL image in "
|
infostream<<"getTextureIdDirect(): WARNING: NULL Texture in "
|
||||||
<<"cache: \""<<base_image_name<<"\""
|
<<"cache: \""<<base_image_name<<"\""
|
||||||
<<std::endl;
|
<<std::endl;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
core::dimension2d<u32> dim = ti->img->getDimension();
|
core::dimension2d<u32> dim = ti->texture->getSize();
|
||||||
|
|
||||||
baseimg = driver->createImage(video::ECF_A8R8G8B8, dim);
|
baseimg = driver->createImage(ti->texture,v2s32(0,0), dim);
|
||||||
|
|
||||||
ti->img->copyTo(
|
|
||||||
baseimg, // target
|
|
||||||
v2s32(0,0), // position in target
|
|
||||||
core::rect<s32>(v2s32(0,0), dim) // from
|
|
||||||
);
|
|
||||||
|
|
||||||
/*infostream<<"getTextureIdDirect(): Loaded \""
|
/*infostream<<"getTextureIdDirect(): Loaded \""
|
||||||
<<base_image_name<<"\" from image cache"
|
<<base_image_name<<"\" from image cache"
|
||||||
|
@ -717,6 +704,7 @@ u32 TextureSource::getTextureIdDirect(const std::string &name)
|
||||||
{
|
{
|
||||||
// Create texture from resulting image
|
// Create texture from resulting image
|
||||||
t = driver->addTexture(name.c_str(), baseimg);
|
t = driver->addTexture(name.c_str(), baseimg);
|
||||||
|
baseimg->drop();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -726,7 +714,7 @@ u32 TextureSource::getTextureIdDirect(const std::string &name)
|
||||||
JMutexAutoLock lock(m_textureinfo_cache_mutex);
|
JMutexAutoLock lock(m_textureinfo_cache_mutex);
|
||||||
|
|
||||||
u32 id = m_textureinfo_cache.size();
|
u32 id = m_textureinfo_cache.size();
|
||||||
TextureInfo ti(name, t, baseimg);
|
TextureInfo ti(name, t);
|
||||||
m_textureinfo_cache.push_back(ti);
|
m_textureinfo_cache.push_back(ti);
|
||||||
m_name_to_id[name] = id;
|
m_name_to_id[name] = id;
|
||||||
|
|
||||||
|
@ -809,12 +797,13 @@ void TextureSource::rebuildImagesAndTextures()
|
||||||
video::IImage *img = generateImageFromScratch(ti->name);
|
video::IImage *img = generateImageFromScratch(ti->name);
|
||||||
// Create texture from resulting image
|
// Create texture from resulting image
|
||||||
video::ITexture *t = NULL;
|
video::ITexture *t = NULL;
|
||||||
if(img)
|
if(img) {
|
||||||
t = driver->addTexture(ti->name.c_str(), img);
|
t = driver->addTexture(ti->name.c_str(), img);
|
||||||
|
img->drop();
|
||||||
|
}
|
||||||
video::ITexture *t_old = ti->texture;
|
video::ITexture *t_old = ti->texture;
|
||||||
// Replace texture
|
// Replace texture
|
||||||
ti->texture = t;
|
ti->texture = t;
|
||||||
ti->img = img;
|
|
||||||
|
|
||||||
if (t_old != 0)
|
if (t_old != 0)
|
||||||
m_texture_trash.push_back(t_old);
|
m_texture_trash.push_back(t_old);
|
||||||
|
|
Loading…
Reference in New Issue