Skip to content

Commit 31c1fca

Browse files
SmallJokerparamat
authored andcommitted
tile.cpp: Automatically upscale lower resolution texture
1 parent 46da0e8 commit 31c1fca

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

doc/lua_api.txt

+1
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ Example:
243243
default_dirt.png^default_grass_side.png
244244

245245
`default_grass_side.png` is overlayed over `default_dirt.png`.
246+
The texture with the lower resolution will be automatically upscaled to the higher resolution texture.
246247

247248
### Texture grouping
248249
Textures can be grouped together by enclosing them in `(` and `)`.

src/client/tile.cpp

+22-1
Original file line numberDiff line numberDiff line change
@@ -1175,7 +1175,28 @@ bool TextureSource::generateImagePart(std::string part_of_name,
11751175
core::rect<s32>(pos_from, dim),
11761176
video::SColor(255,255,255,255),
11771177
NULL);*/
1178-
blit_with_alpha(image, baseimg, pos_from, pos_to, dim);
1178+
1179+
core::dimension2d<u32> dim_dst = baseimg->getDimension();
1180+
if (dim == dim_dst) {
1181+
blit_with_alpha(image, baseimg, pos_from, pos_to, dim);
1182+
} else if (dim.Width * dim.Height < dim_dst.Width * dim_dst.Height) {
1183+
// Upscale overlying image
1184+
video::IImage* scaled_image = m_device->getVideoDriver()->
1185+
createImage(video::ECF_A8R8G8B8, dim_dst);
1186+
image->copyToScaling(scaled_image);
1187+
1188+
blit_with_alpha(scaled_image, baseimg, pos_from, pos_to, dim_dst);
1189+
scaled_image->drop();
1190+
} else {
1191+
// Upscale base image
1192+
video::IImage* scaled_base = m_device->getVideoDriver()->
1193+
createImage(video::ECF_A8R8G8B8, dim);
1194+
baseimg->copyToScaling(scaled_base);
1195+
baseimg->drop();
1196+
baseimg = scaled_base;
1197+
1198+
blit_with_alpha(image, baseimg, pos_from, pos_to, dim);
1199+
}
11791200
}
11801201
//cleanup
11811202
image->drop();

0 commit comments

Comments
 (0)