@@ -164,16 +164,13 @@ struct TextureInfo
164
164
{
165
165
std::string name;
166
166
video::ITexture *texture;
167
- video::IImage *img; // The source image
168
167
169
168
TextureInfo (
170
169
const std::string &name_,
171
- video::ITexture *texture_=NULL ,
172
- video::IImage *img_=NULL
170
+ video::ITexture *texture_=NULL
173
171
):
174
172
name (name_),
175
- texture (texture_),
176
- img (img_)
173
+ texture (texture_)
177
174
{
178
175
}
179
176
};
@@ -460,10 +457,6 @@ TextureSource::~TextureSource()
460
457
// cleanup texture
461
458
if (iter->texture )
462
459
driver->removeTexture (iter->texture );
463
-
464
- // cleanup source image
465
- if (iter->img )
466
- iter->img ->drop ();
467
460
}
468
461
m_textureinfo_cache.clear ();
469
462
@@ -666,23 +659,17 @@ u32 TextureSource::getTextureIdDirect(const std::string &name)
666
659
667
660
TextureInfo *ti = &m_textureinfo_cache[base_image_id];
668
661
669
- if (ti->img == NULL )
662
+ if (ti->texture == NULL )
670
663
{
671
- infostream<<" getTextureIdDirect(): WARNING: NULL image in "
664
+ infostream<<" getTextureIdDirect(): WARNING: NULL Texture in "
672
665
<<" cache: \" " <<base_image_name<<" \" "
673
666
<<std::endl;
674
667
}
675
668
else
676
669
{
677
- core::dimension2d<u32> dim = ti->img ->getDimension ();
678
-
679
- baseimg = driver->createImage (video::ECF_A8R8G8B8, dim);
670
+ core::dimension2d<u32> dim = ti->texture ->getSize ();
680
671
681
- ti->img ->copyTo (
682
- baseimg, // target
683
- v2s32 (0 ,0 ), // position in target
684
- core::rect<s32>(v2s32 (0 ,0 ), dim) // from
685
- );
672
+ baseimg = driver->createImage (ti->texture ,v2s32 (0 ,0 ), dim);
686
673
687
674
/* infostream<<"getTextureIdDirect(): Loaded \""
688
675
<<base_image_name<<"\" from image cache"
@@ -717,6 +704,7 @@ u32 TextureSource::getTextureIdDirect(const std::string &name)
717
704
{
718
705
// Create texture from resulting image
719
706
t = driver->addTexture (name.c_str (), baseimg);
707
+ baseimg->drop ();
720
708
}
721
709
722
710
/*
@@ -726,7 +714,7 @@ u32 TextureSource::getTextureIdDirect(const std::string &name)
726
714
JMutexAutoLock lock (m_textureinfo_cache_mutex);
727
715
728
716
u32 id = m_textureinfo_cache.size ();
729
- TextureInfo ti (name, t, baseimg );
717
+ TextureInfo ti (name, t);
730
718
m_textureinfo_cache.push_back (ti);
731
719
m_name_to_id[name] = id;
732
720
@@ -809,12 +797,13 @@ void TextureSource::rebuildImagesAndTextures()
809
797
video::IImage *img = generateImageFromScratch (ti->name );
810
798
// Create texture from resulting image
811
799
video::ITexture *t = NULL ;
812
- if (img)
800
+ if (img) {
813
801
t = driver->addTexture (ti->name .c_str (), img);
802
+ img->drop ();
803
+ }
814
804
video::ITexture *t_old = ti->texture ;
815
805
// Replace texture
816
806
ti->texture = t;
817
- ti->img = img;
818
807
819
808
if (t_old != 0 )
820
809
m_texture_trash.push_back (t_old);
@@ -975,7 +964,7 @@ bool TextureSource::generateImage(std::string part_of_name, video::IImage *& bas
975
964
976
965
if (image == NULL ) {
977
966
if (part_of_name != " " ) {
978
- if (part_of_name.find (" _normal.png" ) == std::string::npos){
967
+ if (part_of_name.find (" _normal.png" ) == std::string::npos){
979
968
errorstream<<" generateImage(): Could not load image \" "
980
969
<<part_of_name<<" \" " <<" while building texture" <<std::endl;
981
970
errorstream<<" generateImage(): Creating a dummy"
0 commit comments