From b9777cc682f8aa698223bb4890315b4f373124e1 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Tue, 11 Nov 2025 17:46:38 +0300 Subject: [PATCH] add canvas:unbind_texture method --- doc/en/scripting/ui.md | 1 + doc/ru/scripting/ui.md | 1 + src/logic/scripting/lua/usertypes/lua_type_canvas.cpp | 11 +++++++++++ src/logic/scripting/lua/usertypes/lua_type_canvas.hpp | 1 + 4 files changed, 14 insertions(+) diff --git a/doc/en/scripting/ui.md b/doc/en/scripting/ui.md index 2da6843c..091d7ff8 100644 --- a/doc/en/scripting/ui.md +++ b/doc/en/scripting/ui.md @@ -196,6 +196,7 @@ Here, *color* can be specified in the following ways: | data:update() | applies changes to the canvas and uploads it to the GPU | | data:set_data(data: table) | replaces pixel data (width * height * 4 numbers) | | data:create_texture(name: str) | creates and shares texture to renderer | +| data:unbind_texture() | unbinds the texture from the canvas | ## Inline frame (iframe) diff --git a/doc/ru/scripting/ui.md b/doc/ru/scripting/ui.md index 19f1f8ab..10514edb 100644 --- a/doc/ru/scripting/ui.md +++ b/doc/ru/scripting/ui.md @@ -196,6 +196,7 @@ document["worlds-panel"]:clear() | data:update() | применяет изменения и загружает холст в видеопамять | | data:set_data(data: table) | заменяет данные пикселей (ширина * высота * 4 чисел) | | data:create_texture(name: str) | создаёт и делится текстурой с рендерером | +| data:unbind_texture() | отвязывает текстуру от холста | ## Рамка встраивания (iframe) diff --git a/src/logic/scripting/lua/usertypes/lua_type_canvas.cpp b/src/logic/scripting/lua/usertypes/lua_type_canvas.cpp index 325f916f..40af6e81 100644 --- a/src/logic/scripting/lua/usertypes/lua_type_canvas.cpp +++ b/src/logic/scripting/lua/usertypes/lua_type_canvas.cpp @@ -66,6 +66,10 @@ void LuaCanvas::createTexture() { texture->setMipMapping(false, true); } +void LuaCanvas::unbindTexture() { + texture.reset(); +} + union RGBA { struct { uint8_t r, g, b, a; @@ -99,7 +103,13 @@ static int l_at(State* L) { if (auto pixel = get_at(L, x, y)) { return pushinteger(L, pixel->rgba); } + return 0; +} +static int l_unbind_texture(State* L) { + if (auto canvas = touserdata(L, 1)) { + canvas->unbindTexture(); + } return 0; } @@ -238,6 +248,7 @@ static std::unordered_map methods { {"clear", lua::wrap}, {"update", lua::wrap}, {"create_texture", lua::wrap}, + {"unbind_texture", lua::wrap}, {"_set_data", lua::wrap}, }; diff --git a/src/logic/scripting/lua/usertypes/lua_type_canvas.hpp b/src/logic/scripting/lua/usertypes/lua_type_canvas.hpp index 198313cb..854443d1 100644 --- a/src/logic/scripting/lua/usertypes/lua_type_canvas.hpp +++ b/src/logic/scripting/lua/usertypes/lua_type_canvas.hpp @@ -40,6 +40,7 @@ namespace lua { void update(int extrusion = ATLAS_EXTRUSION); void createTexture(); + void unbindTexture(); static int createMetatable(lua::State*); inline static std::string TYPENAME = "Canvas";