/* Maintain a static cache to store the images that correspond to textures
* in a format that's manipulable by code. Some platforms exhibit issues
* converting textures back into images repeatedly, and some don't even
* allow it at all.
*/
/* Maintain a static cache to store the images that correspond to textures
* in a format that's manipulable by code. Some platforms exhibit issues
* converting textures back into images repeatedly, and some don't even
* allow it at all.
*/
/* Maintain a static cache of all pre-scaled textures. These need to be
* cleared as well when the cached images.
*/
/* Maintain a static cache of all pre-scaled textures. These need to be
* cleared as well when the cached images.
*/
/* Manually insert an image into the cache, useful to avoid texture-to-image
* conversion whenever we can intercept it.
*/
/* Manually insert an image into the cache, useful to avoid texture-to-image
* conversion whenever we can intercept it.
*/
if (!g_settings->getBool("gui_scaling_filter"))
return;
video::IImage *copied = driver->createImage(value->getColorFormat(),
value->getDimension());
value->copyTo(copied);
if (!g_settings->getBool("gui_scaling_filter"))
return;
video::IImage *copied = driver->createImage(value->getColorFormat(),
value->getDimension());
value->copyTo(copied);
-void guiScalingCacheClear(video::IVideoDriver *driver) {
- for (std::map<io::path, video::IImage *>::iterator it = imgCache.begin();
- it != imgCache.end(); it++) {
- if (it->second != NULL)
- it->second->drop();
+void guiScalingCacheClear()
+{
+ for (auto &it : g_imgCache) {
+ if (it.second)
+ it.second->drop();
- imgCache.clear();
- for (std::map<io::path, video::ITexture *>::iterator it = txrCache.begin();
- it != txrCache.end(); it++) {
- if (it->second != NULL)
- driver->removeTexture(it->second);
+ g_imgCache.clear();
+ for (auto &it : g_txrCache) {
+ if (it.second)
+ RenderingEngine::get_video_driver()->removeTexture(it.second);
}
/* Get a cached, high-quality pre-scaled texture for display purposes. If the
* texture is not already cached, attempt to create it. Returns a pre-scaled texture,
* or the original texture if unable to pre-scale it.
*/
}
/* Get a cached, high-quality pre-scaled texture for display purposes. If the
* texture is not already cached, attempt to create it. Returns a pre-scaled texture,
* or the original texture if unable to pre-scale it.
*/
-video::ITexture *guiScalingResizeCached(video::IVideoDriver *driver, video::ITexture *src,
- const core::rect<s32> &srcrect, const core::rect<s32> &destrect) {
-
+video::ITexture *guiScalingResizeCached(video::IVideoDriver *driver,
+ video::ITexture *src, const core::rect<s32> &srcrect,
+ const core::rect<s32> &destrect)
+{
+ if (src == NULL)
+ return src;
srcrect.UpperLeftCorner.X,
srcrect.UpperLeftCorner.Y,
srcrect.getWidth(),
srcrect.UpperLeftCorner.X,
srcrect.UpperLeftCorner.Y,
srcrect.getWidth(),
io::path scalename = origname + "@guiScalingFilter:" + rectstr;
// Search for existing scaled texture.
io::path scalename = origname + "@guiScalingFilter:" + rectstr;
// Search for existing scaled texture.
if (scaled)
return scaled;
// Try to find the texture converted to an image in the cache.
// If the image was not found, try to extract it from the texture.
if (scaled)
return scaled;
// Try to find the texture converted to an image in the cache.
// If the image was not found, try to extract it from the texture.
if (srcimg == NULL) {
if (!g_settings->getBool("gui_scaling_filter_txr2img"))
return src;
srcimg = driver->createImageFromData(src->getColorFormat(),
src->getSize(), src->lock(), false);
src->unlock();
if (srcimg == NULL) {
if (!g_settings->getBool("gui_scaling_filter_txr2img"))
return src;
srcimg = driver->createImageFromData(src->getColorFormat(),
src->getSize(), src->lock(), false);
src->unlock();
// Convert the scaled image back into a texture.
scaled = driver->addTexture(scalename, destimg, NULL);
destimg->drop();
// Convert the scaled image back into a texture.
scaled = driver->addTexture(scalename, destimg, NULL);
destimg->drop();
/* Convenience wrapper for guiScalingResizeCached that accepts parameters that
* are available at GUI imagebutton creation time.
*/
/* Convenience wrapper for guiScalingResizeCached that accepts parameters that
* are available at GUI imagebutton creation time.
*/
-video::ITexture *guiScalingImageButton(video::IVideoDriver *driver, video::ITexture *src,
- s32 width, s32 height) {
+video::ITexture *guiScalingImageButton(video::IVideoDriver *driver,
+ video::ITexture *src, s32 width, s32 height)
+{
+ if (src == NULL)
+ return src;
return guiScalingResizeCached(driver, src,
core::rect<s32>(0, 0, src->getSize().Width, src->getSize().Height),
core::rect<s32>(0, 0, width, height));
return guiScalingResizeCached(driver, src,
core::rect<s32>(0, 0, src->getSize().Width, src->getSize().Height),
core::rect<s32>(0, 0, width, height));
void draw2DImageFilterScaled(video::IVideoDriver *driver, video::ITexture *txr,
const core::rect<s32> &destrect, const core::rect<s32> &srcrect,
const core::rect<s32> *cliprect, const video::SColor *const colors,
void draw2DImageFilterScaled(video::IVideoDriver *driver, video::ITexture *txr,
const core::rect<s32> &destrect, const core::rect<s32> &srcrect,
const core::rect<s32> *cliprect, const video::SColor *const colors,
// Attempt to pre-scale image in software in high quality.
video::ITexture *scaled = guiScalingResizeCached(driver, txr, srcrect, destrect);
// Attempt to pre-scale image in software in high quality.
video::ITexture *scaled = guiScalingResizeCached(driver, txr, srcrect, destrect);