feat: update atlas texture extrusion on its reload
This commit is contained in:
@@ -184,7 +184,7 @@ assetload::postfunc assetload::atlas(
|
|||||||
if (!append_atlas(builder, file)) continue;
|
if (!append_atlas(builder, file)) continue;
|
||||||
}
|
}
|
||||||
std::set<std::string> names = builder.getNames();
|
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) {
|
return [=](auto assets) {
|
||||||
atlas->prepare();
|
atlas->prepare();
|
||||||
assets->store(std::unique_ptr<Atlas>(atlas), name);
|
assets->store(std::unique_ptr<Atlas>(atlas), name);
|
||||||
@@ -501,7 +501,7 @@ static bool load_animation(
|
|||||||
}
|
}
|
||||||
if (!append_atlas(builder, file)) continue;
|
if (!append_atlas(builder, file)) continue;
|
||||||
}
|
}
|
||||||
auto srcAtlas = builder.build(2, true);
|
auto srcAtlas = builder.build(ATLAS_EXTRUSION, true);
|
||||||
if (frameList.empty()) {
|
if (frameList.empty()) {
|
||||||
for (const auto& frameName : builder.getNames()) {
|
for (const auto& frameName : builder.getNames()) {
|
||||||
frameList.emplace_back(frameName, 0);
|
frameList.emplace_back(frameName, 0);
|
||||||
|
|||||||
@@ -61,6 +61,8 @@ inline constexpr int ITEM_ICON_SIZE = 48;
|
|||||||
|
|
||||||
inline constexpr int TRANSLUCENT_BLOCKS_SORT_INTERVAL = 8;
|
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 SHADERS_FOLDER = "shaders";
|
||||||
inline const std::string TEXTURES_FOLDER = "textures";
|
inline const std::string TEXTURES_FOLDER = "textures";
|
||||||
inline const std::string FONTS_FOLDER = "fonts";
|
inline const std::string FONTS_FOLDER = "fonts";
|
||||||
|
|||||||
@@ -137,5 +137,5 @@ std::unique_ptr<Atlas> BlocksPreview::build(
|
|||||||
builder.add(def.name, draw(cache, shader, fbo, batch, def, iconSize));
|
builder.add(def.name, draw(cache, shader, fbo, batch, def, iconSize));
|
||||||
}
|
}
|
||||||
fbo.unbind();
|
fbo.unbind();
|
||||||
return builder.build(2);
|
return builder.build(ATLAS_EXTRUSION);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
#include <random>
|
#include <random>
|
||||||
|
|
||||||
#include "lua_commons.hpp"
|
#include "lua_commons.hpp"
|
||||||
|
#include "constants.hpp"
|
||||||
#include "maths/UVRegion.hpp"
|
#include "maths/UVRegion.hpp"
|
||||||
|
|
||||||
struct fnl_state;
|
struct fnl_state;
|
||||||
@@ -108,7 +109,7 @@ namespace lua {
|
|||||||
return texture;
|
return texture;
|
||||||
}
|
}
|
||||||
|
|
||||||
void update();
|
void update(int extrusion = ATLAS_EXTRUSION);
|
||||||
|
|
||||||
void createTexture();
|
void createTexture();
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ LuaCanvas::LuaCanvas(
|
|||||||
region(std::move(region)) {
|
region(std::move(region)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void LuaCanvas::update() {
|
void LuaCanvas::update(int extrusion) {
|
||||||
if (!hasTexture()) {
|
if (!hasTexture()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -39,7 +39,24 @@ void LuaCanvas::update() {
|
|||||||
w = std::min<uint>(w, imgWidth);
|
w = std::min<uint>(w, imgWidth);
|
||||||
h = std::min<uint>(h, imgHeight);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user