@@ -182,6 +182,42 @@ struct TextureInfo
182
182
}
183
183
};
184
184
185
+ /* Upscale textures to user's requested minimum size. This is a trick to make
186
+ * filters look as good on low-res textures as on high-res ones, by making
187
+ * low-res textures BECOME high-res ones. This is helpful for worlds that
188
+ * mix high- and low-res textures, or for mods with least-common-denominator
189
+ * textures that don't have the resources to offer high-res alternatives.
190
+ */
191
+ video::IImage *textureMinSizeUpscale (video::IVideoDriver *driver, video::IImage *orig) {
192
+ if (orig == NULL )
193
+ return orig;
194
+ s32 scaleto = g_settings->getS32 (" texture_min_size" );
195
+ if (scaleto > 0 ) {
196
+
197
+ /* Calculate scaling needed to make the shortest texture dimension
198
+ * equal to the target minimum. If e.g. this is a vertical frames
199
+ * animation, the short dimension will be the real size.
200
+ */
201
+ const core::dimension2d<u32> dim = orig->getDimension ();
202
+ u32 xscale = scaleto / dim.Width ;
203
+ u32 yscale = scaleto / dim.Height ;
204
+ u32 scale = (xscale > yscale) ? xscale : yscale;
205
+
206
+ // Never downscale; only scale up by 2x or more.
207
+ if (scale > 1 ) {
208
+ u32 w = scale * dim.Width ;
209
+ u32 h = scale * dim.Height ;
210
+ const core::dimension2d<u32> newdim = core::dimension2d<u32>(w, h);
211
+ video::IImage *newimg = driver->createImage (
212
+ orig->getColorFormat (), newdim);
213
+ orig->copyToScaling (newimg);
214
+ return newimg;
215
+ }
216
+ }
217
+
218
+ return orig;
219
+ }
220
+
185
221
/*
186
222
SourceImageCache: A cache used for storing source images.
187
223
*/
@@ -276,36 +312,6 @@ class SourceImageCache
276
312
}
277
313
}
278
314
279
- /* Upscale textures to user's requested minimum size. This is a trick to make
280
- * filters look as good on low-res textures as on high-res ones, by making
281
- * low-res textures BECOME high-res ones. This is helpful for worlds that
282
- * mix high- and low-res textures, or for mods with least-common-denominator
283
- * textures that don't have the resources to offer high-res alternatives.
284
- */
285
- s32 scaleto = g_settings->getS32 (" texture_min_size" );
286
- if (scaleto > 0 ) {
287
-
288
- /* Calculate scaling needed to make the shortest texture dimension
289
- * equal to the target minimum. If e.g. this is a vertical frames
290
- * animation, the short dimension will be the real size.
291
- */
292
- const core::dimension2d<u32> dim = toadd->getDimension ();
293
- u32 xscale = scaleto / dim.Width ;
294
- u32 yscale = scaleto / dim.Height ;
295
- u32 scale = (xscale > yscale) ? xscale : yscale;
296
-
297
- // Never downscale; only scale up by 2x or more.
298
- if (scale > 1 ) {
299
- u32 w = scale * dim.Width ;
300
- u32 h = scale * dim.Height ;
301
- const core::dimension2d<u32> newdim = core::dimension2d<u32>(w, h);
302
- video::IImage *newimg = driver->createImage (
303
- toadd->getColorFormat (), newdim);
304
- toadd->copyToScaling (newimg);
305
- toadd = newimg;
306
- }
307
- }
308
-
309
315
if (need_to_grab)
310
316
toadd->grab ();
311
317
m_images[name] = toadd;
@@ -682,7 +688,8 @@ u32 TextureSource::generateTexture(const std::string &name)
682
688
video::IVideoDriver *driver = m_device->getVideoDriver ();
683
689
sanity_check (driver);
684
690
685
- video::IImage *img = generateImage (name);
691
+ video::IImage *origimg = generateImage (name);
692
+ video::IImage *img = textureMinSizeUpscale (driver, origimg);
686
693
687
694
video::ITexture *tex = NULL ;
688
695
@@ -693,6 +700,8 @@ u32 TextureSource::generateTexture(const std::string &name)
693
700
// Create texture from resulting image
694
701
tex = driver->addTexture (name.c_str (), img);
695
702
img->drop ();
703
+ if ((origimg != NULL ) && (img != origimg))
704
+ origimg->drop ();
696
705
}
697
706
698
707
/*
@@ -783,7 +792,8 @@ void TextureSource::rebuildImagesAndTextures()
783
792
// Recreate textures
784
793
for (u32 i=0 ; i<m_textureinfo_cache.size (); i++){
785
794
TextureInfo *ti = &m_textureinfo_cache[i];
786
- video::IImage *img = generateImage (ti->name );
795
+ video::IImage *origimg = generateImage (ti->name );
796
+ video::IImage *img = textureMinSizeUpscale (driver, origimg);
787
797
#ifdef __ANDROID__
788
798
img = Align2Npot2 (img, driver);
789
799
sanity_check (img->getDimension ().Height == npot2 (img->getDimension ().Height ));
@@ -794,6 +804,8 @@ void TextureSource::rebuildImagesAndTextures()
794
804
if (img) {
795
805
t = driver->addTexture (ti->name .c_str (), img);
796
806
img->drop ();
807
+ if (origimg && (origimg != img))
808
+ origimg->drop ();
797
809
}
798
810
video::ITexture *t_old = ti->texture ;
799
811
// Replace texture
0 commit comments