Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove use_texture_alpha compatibility code for nodeboxes & meshes #13929

Merged
merged 1 commit into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions doc/lua_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -8822,8 +8822,8 @@ Used by `minetest.register_node`.
-- depending on the alpha channel being below/above 50% in value
-- * "blend": The alpha channel specifies how transparent a given pixel
-- of the rendered node is
-- The default is "opaque" for drawtypes normal, liquid and flowingliquid;
-- "clip" otherwise.
-- The default is "opaque" for drawtypes normal, liquid and flowingliquid,
-- mesh and nodebox or "clip" otherwise.
-- If set to a boolean value (deprecated): true either sets it to blend
-- or clip, false sets it to clip or opaque mode depending on the drawtype.

Expand Down
58 changes: 2 additions & 56 deletions src/nodedef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down
16 changes: 2 additions & 14 deletions src/nodedef.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ enum AlphaMode : u8 {
ALPHAMODE_BLEND,
ALPHAMODE_CLIP,
ALPHAMODE_OPAQUE,
ALPHAMODE_LEGACY_COMPAT, /* means either opaque or clip */
ALPHAMODE_LEGACY_COMPAT, /* only sent by old servers, equals OPAQUE */
};


Expand Down Expand Up @@ -466,11 +466,9 @@ struct ContentFeatures
case NDT_NORMAL:
case NDT_LIQUID:
case NDT_FLOWINGLIQUID:
alpha = ALPHAMODE_OPAQUE;
break;
case NDT_NODEBOX:
case NDT_MESH:
alpha = ALPHAMODE_LEGACY_COMPAT; // this should eventually be OPAQUE
alpha = ALPHAMODE_OPAQUE;
break;
default:
alpha = ALPHAMODE_CLIP;
Expand Down Expand Up @@ -529,16 +527,6 @@ struct ContentFeatures
#endif

private:
#ifndef SERVER
/*
* Checks if any tile texture has any transparent pixels.
* Prints a warning and returns true if that is the case, false otherwise.
* This is supposed to be used for use_texture_alpha backwards compatibility.
*/
bool textureAlphaCheck(ITextureSource *tsrc, const TileDef *tiles,
int length);
#endif

void setAlphaFromLegacy(u8 legacy_alpha);

u8 getAlphaForLegacy() const;
Expand Down