1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Remove use_texture_alpha compatibility code for nodeboxes & meshes (#13929)

This commit is contained in:
sfan5 2023-12-13 13:15:59 +01:00 committed by GitHub
parent 6eb9269741
commit d1a55e9ca4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 72 deletions

View file

@ -420,8 +420,6 @@ void ContentFeatures::reset()
void ContentFeatures::setAlphaFromLegacy(u8 legacy_alpha)
{
// No special handling for nodebox/mesh here as it doesn't make sense to
// throw warnings when the server is too old to support the "correct" way
switch (drawtype) {
case NDT_NORMAL:
alpha = legacy_alpha == 255 ? ALPHAMODE_OPAQUE : ALPHAMODE_CLIP;
@ -648,6 +646,8 @@ void ContentFeatures::deSerialize(std::istream &is, u16 protocol_version)
if (is.eof())
throw SerializationError("");
alpha = static_cast<enum AlphaMode>(tmp);
if (alpha == ALPHAMODE_LEGACY_COMPAT)
alpha = ALPHAMODE_OPAQUE;
tmp = readU8(is);
if (is.eof())
@ -749,55 +749,6 @@ static void fillTileAttribs(ITextureSource *tsrc, TileLayer *layer,
}
}
bool ContentFeatures::textureAlphaCheck(ITextureSource *tsrc, const TileDef *tiles, int length)
{
video::IVideoDriver *driver = RenderingEngine::get_video_driver();
static thread_local bool long_warning_printed = false;
std::set<std::string> seen;
for (int i = 0; i < length; i++) {
if (seen.find(tiles[i].name) != seen.end())
continue;
seen.insert(tiles[i].name);
// Load the texture and see if there's any transparent pixels
video::ITexture *texture = tsrc->getTexture(tiles[i].name);
video::IImage *image = driver->createImage(texture,
core::position2d<s32>(0, 0), texture->getOriginalSize());
if (!image)
continue;
core::dimension2d<u32> dim = image->getDimension();
bool ok = true;
for (u16 x = 0; x < dim.Width; x++) {
for (u16 y = 0; y < dim.Height; y++) {
if (image->getPixel(x, y).getAlpha() < 255) {
ok = false;
goto break_loop;
}
}
}
break_loop:
image->drop();
if (ok)
continue;
warningstream << "Texture \"" << tiles[i].name << "\" of "
<< name << " has transparency, assuming "
"use_texture_alpha = \"clip\"." << std::endl;
if (!long_warning_printed) {
warningstream << " This warning can be a false-positive if "
"unused pixels in the texture are transparent. However if "
"it is meant to be transparent, you *MUST* update the "
"nodedef and set use_texture_alpha = \"clip\"! This "
"compatibility code will be removed in a few releases."
<< std::endl;
long_warning_printed = true;
}
return true;
}
return false;
}
bool isWorldAligned(AlignStyle style, WorldAlignMode mode, NodeDrawType drawtype)
{
if (style == ALIGN_STYLE_WORLD)
@ -841,11 +792,6 @@ void ContentFeatures::updateTextures(ITextureSource *tsrc, IShaderSource *shdsrc
bool is_liquid = false;
if (alpha == ALPHAMODE_LEGACY_COMPAT) {
// Before working with the alpha mode, resolve any legacy kludges
alpha = textureAlphaCheck(tsrc, tdef, 6) ? ALPHAMODE_CLIP : ALPHAMODE_OPAQUE;
}
MaterialType material_type = alpha == ALPHAMODE_OPAQUE ?
TILE_MATERIAL_OPAQUE : (alpha == ALPHAMODE_CLIP ? TILE_MATERIAL_BASIC :
TILE_MATERIAL_ALPHA);