@@ -28,54 +28,58 @@ with this program; if not, write to the Free Software Foundation, Inc.,
28
28
* converting textures back into images repeatedly, and some don't even
29
29
* allow it at all.
30
30
*/
31
- std::map<io::path, video::IImage *> imgCache ;
31
+ std::map<io::path, video::IImage *> g_imgCache ;
32
32
33
33
/* Maintain a static cache of all pre-scaled textures. These need to be
34
34
* cleared as well when the cached images.
35
35
*/
36
- std::map<io::path, video::ITexture *> txrCache ;
36
+ std::map<io::path, video::ITexture *> g_txrCache ;
37
37
38
38
/* Manually insert an image into the cache, useful to avoid texture-to-image
39
39
* conversion whenever we can intercept it.
40
40
*/
41
- void guiScalingCache (io::path key, video::IVideoDriver *driver, video::IImage *value) {
41
+ void guiScalingCache (io::path key, video::IVideoDriver *driver, video::IImage *value)
42
+ {
42
43
if (!g_settings->getBool (" gui_scaling_filter" ))
43
44
return ;
44
45
video::IImage *copied = driver->createImage (value->getColorFormat (),
45
46
value->getDimension ());
46
47
value->copyTo (copied);
47
- imgCache [key] = copied;
48
+ g_imgCache [key] = copied;
48
49
}
49
50
50
51
// Manually clear the cache, e.g. when switching to different worlds.
51
- void guiScalingCacheClear (video::IVideoDriver *driver) {
52
- for (std::map<io::path, video::IImage *>::iterator it = imgCache.begin ();
53
- it != imgCache.end (); it++) {
52
+ void guiScalingCacheClear (video::IVideoDriver *driver)
53
+ {
54
+ for (std::map<io::path, video::IImage *>::iterator it = g_imgCache.begin ();
55
+ it != g_imgCache.end (); it++) {
54
56
if (it->second != NULL )
55
57
it->second ->drop ();
56
58
}
57
- imgCache .clear ();
58
- for (std::map<io::path, video::ITexture *>::iterator it = txrCache .begin ();
59
- it != txrCache .end (); it++) {
59
+ g_imgCache .clear ();
60
+ for (std::map<io::path, video::ITexture *>::iterator it = g_txrCache .begin ();
61
+ it != g_txrCache .end (); it++) {
60
62
if (it->second != NULL )
61
63
driver->removeTexture (it->second );
62
64
}
63
- txrCache .clear ();
65
+ g_txrCache .clear ();
64
66
}
65
67
66
68
/* Get a cached, high-quality pre-scaled texture for display purposes. If the
67
69
* texture is not already cached, attempt to create it. Returns a pre-scaled texture,
68
70
* or the original texture if unable to pre-scale it.
69
71
*/
70
- video::ITexture *guiScalingResizeCached (video::IVideoDriver *driver, video::ITexture *src,
71
- const core::rect<s32> &srcrect, const core::rect<s32> &destrect) {
72
+ video::ITexture *guiScalingResizeCached (video::IVideoDriver *driver,
73
+ video::ITexture *src, const core::rect<s32> &srcrect,
74
+ const core::rect<s32> &destrect)
75
+ {
72
76
73
77
if (!g_settings->getBool (" gui_scaling_filter" ))
74
78
return src;
75
79
76
80
// Calculate scaled texture name.
77
81
char rectstr[200 ];
78
- sprintf (rectstr, " %d:%d:%d:%d:%d:%d" ,
82
+ snprintf (rectstr, sizeof (rectstr) , " %d:%d:%d:%d:%d:%d" ,
79
83
srcrect.UpperLeftCorner .X ,
80
84
srcrect.UpperLeftCorner .Y ,
81
85
srcrect.getWidth (),
@@ -86,20 +90,20 @@ video::ITexture *guiScalingResizeCached(video::IVideoDriver *driver, video::ITex
86
90
io::path scalename = origname + " @guiScalingFilter:" + rectstr;
87
91
88
92
// Search for existing scaled texture.
89
- video::ITexture *scaled = txrCache [scalename];
93
+ video::ITexture *scaled = g_txrCache [scalename];
90
94
if (scaled)
91
95
return scaled;
92
96
93
97
// Try to find the texture converted to an image in the cache.
94
98
// If the image was not found, try to extract it from the texture.
95
- video::IImage* srcimg = imgCache [origname];
99
+ video::IImage* srcimg = g_imgCache [origname];
96
100
if (srcimg == NULL ) {
97
101
if (!g_settings->getBool (" gui_scaling_filter_txr2img" ))
98
102
return src;
99
103
srcimg = driver->createImageFromData (src->getColorFormat (),
100
104
src->getSize (), src->lock (), false );
101
105
src->unlock ();
102
- imgCache [origname] = srcimg;
106
+ g_imgCache [origname] = srcimg;
103
107
}
104
108
105
109
// Create a new destination image and scale the source into it.
@@ -125,16 +129,17 @@ video::ITexture *guiScalingResizeCached(video::IVideoDriver *driver, video::ITex
125
129
// Convert the scaled image back into a texture.
126
130
scaled = driver->addTexture (scalename, destimg, NULL );
127
131
destimg->drop ();
128
- txrCache [scalename] = scaled;
132
+ g_txrCache [scalename] = scaled;
129
133
130
134
return scaled;
131
135
}
132
136
133
137
/* Convenience wrapper for guiScalingResizeCached that accepts parameters that
134
138
* are available at GUI imagebutton creation time.
135
139
*/
136
- video::ITexture *guiScalingImageButton (video::IVideoDriver *driver, video::ITexture *src,
137
- s32 width, s32 height) {
140
+ video::ITexture *guiScalingImageButton (video::IVideoDriver *driver,
141
+ video::ITexture *src, s32 width, s32 height)
142
+ {
138
143
return guiScalingResizeCached (driver, src,
139
144
core::rect<s32>(0 , 0 , src->getSize ().Width , src->getSize ().Height ),
140
145
core::rect<s32>(0 , 0 , width, height));
@@ -146,8 +151,8 @@ video::ITexture *guiScalingImageButton(video::IVideoDriver *driver, video::IText
146
151
void draw2DImageFilterScaled (video::IVideoDriver *driver, video::ITexture *txr,
147
152
const core::rect<s32> &destrect, const core::rect<s32> &srcrect,
148
153
const core::rect<s32> *cliprect, const video::SColor *const colors,
149
- bool usealpha) {
150
-
154
+ bool usealpha)
155
+ {
151
156
// Attempt to pre-scale image in software in high quality.
152
157
video::ITexture *scaled = guiScalingResizeCached (driver, txr, srcrect, destrect);
153
158
0 commit comments