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
+2 -1
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();
@@ -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);
}
}
}