// Apply transform to image data
void imageTransform(u32 transform, video::IImage *src, video::IImage *dst);
+/*
+ Adds a new texture to the video driver and returns a pointer to it.
+ This pointer should not be dropped. Any texture that was registered
+ with that name before is removed (this may invalidate some ITexture
+ pointers).
+*/
+video::ITexture* register_texture(video::IVideoDriver *driver,
+ std::string name, video::IImage *img);
+
/*
Generate image based on a string like "stone.png" or "[crack0".
if baseimg is NULL, it is created. Otherwise stuff is made on it.
" create texture \""<<name<<"\""<<std::endl;
}
+ // Create texture from resulting image
if(baseimg != NULL)
- {
- // Create texture from resulting image
- t = driver->addTexture(name.c_str(), baseimg);
- }
+ t = register_texture(driver, name, baseimg);
/*
Add texture to caches (add NULL textures too)
// Create texture from resulting image
video::ITexture *t = NULL;
if(img)
- t = driver->addTexture(sap->name.c_str(), img);
+ t = register_texture(driver, sap->name, img);
// Replace texture
sap->a.atlas = t;
/*
Make texture
*/
- video::ITexture *t = driver->addTexture("__main_atlas__", atlas_img);
+ video::ITexture *t = register_texture(driver, "__main_atlas__", atlas_img);
assert(t);
/*
return baseimg;
}
+video::ITexture* register_texture(video::IVideoDriver *driver,
+ std::string name, video::IImage *img)
+{
+ video::ITexture *old_texture = driver->findTexture(name.c_str());
+ if(old_texture)
+ driver->removeTexture(old_texture);
+ return driver->addTexture(name.c_str(), img);
+}
+
bool generate_image(std::string part_of_name, video::IImage *& baseimg,
IrrlichtDevice *device, SourceImageCache *sourcecache)
{
assert(img_top && img_left && img_right);
// Create textures from images
- video::ITexture *texture_top = driver->addTexture(
- (imagename_top + "__temp__").c_str(), img_top);
- video::ITexture *texture_left = driver->addTexture(
- (imagename_left + "__temp__").c_str(), img_left);
- video::ITexture *texture_right = driver->addTexture(
- (imagename_right + "__temp__").c_str(), img_right);
+ video::ITexture *texture_top = register_texture(driver,
+ imagename_top + "__temp1__", img_top);
+ video::ITexture *texture_left = register_texture(driver,
+ imagename_left + "__temp2__", img_left);
+ video::ITexture *texture_right = register_texture(driver,
+ imagename_right + "__temp3__", img_right);
assert(texture_top && texture_left && texture_right);
// Drop images