feat: update atlas texture extrusion on its reload

This commit is contained in:
MihailRis 2025-11-05 12:25:50 +03:00
parent b89888969f
commit 28dd2f38d2
5 changed files with 26 additions and 6 deletions

View File

@ -184,7 +184,7 @@ assetload::postfunc assetload::atlas(
if (!append_atlas(builder, file)) continue;
}
std::set<std::string> names = builder.getNames();
Atlas* atlas = builder.build(2, false).release();
Atlas* atlas = builder.build(ATLAS_EXTRUSION, false).release();
return [=](auto assets) {
atlas->prepare();
assets->store(std::unique_ptr<Atlas>(atlas), name);
@ -501,7 +501,7 @@ static bool load_animation(
}
if (!append_atlas(builder, file)) continue;
}
auto srcAtlas = builder.build(2, true);
auto srcAtlas = builder.build(ATLAS_EXTRUSION, true);
if (frameList.empty()) {
for (const auto& frameName : builder.getNames()) {
frameList.emplace_back(frameName, 0);

View File

@ -61,6 +61,8 @@ inline constexpr int ITEM_ICON_SIZE = 48;
inline constexpr int TRANSLUCENT_BLOCKS_SORT_INTERVAL = 8;
inline constexpr int ATLAS_EXTRUSION = 2;
inline const std::string SHADERS_FOLDER = "shaders";
inline const std::string TEXTURES_FOLDER = "textures";
inline const std::string FONTS_FOLDER = "fonts";

View File

@ -137,5 +137,5 @@ std::unique_ptr<Atlas> BlocksPreview::build(
builder.add(def.name, draw(cache, shader, fbo, batch, def, iconSize));
}
fbo.unbind();
return builder.build(2);
return builder.build(ATLAS_EXTRUSION);
}

View File

@ -6,6 +6,7 @@
#include <random>
#include "lua_commons.hpp"
#include "constants.hpp"
#include "maths/UVRegion.hpp"
struct fnl_state;
@ -108,7 +109,7 @@ namespace lua {
return texture;
}
void update();
void update(int extrusion = ATLAS_EXTRUSION);
void createTexture();

View File

@ -19,7 +19,7 @@ LuaCanvas::LuaCanvas(
region(std::move(region)) {
}
void LuaCanvas::update() {
void LuaCanvas::update(int extrusion) {
if (!hasTexture()) {
return;
}
@ -39,7 +39,24 @@ void LuaCanvas::update() {
w = std::min<uint>(w, imgWidth);
h = std::min<uint>(h, imgHeight);
texture->reloadPartial(*data, x, y, w, h);
if (extrusion > 0) {
auto extruded = std::make_unique<ImageData>(
data->getFormat(),
w + extrusion * 2,
h + extrusion * 2
);
extruded->blit(*data, extrusion, extrusion);
extruded->extrude(0, 0, w + extrusion * 2, h + extrusion * 2);
texture->reloadPartial(
*extruded,
x - extrusion,
y - extrusion,
w + extrusion * 2,
h + extrusion * 2
);
} else {
texture->reloadPartial(*data, x, y, w, h);
}
}
}