|
7 | 7 | #include "ui_local.h"
|
8 | 8 |
|
9 | 9 | #include <filesystem>
|
| 10 | +#include <fstream> |
10 | 11 | #include <zlib.h>
|
11 | 12 |
|
| 13 | +#include "core/core_tex_manipulation.h" |
| 14 | + |
12 | 15 | /* OnFrame()
|
13 | 16 | ** OnChar("<char>")
|
14 | 17 | ** OnKeyDown("<keyName>")
|
|
36 | 39 | ** imgHandle:SetLoadingPriority(pri)
|
37 | 40 | ** width, height = imgHandle:ImageSize()
|
38 | 41 | **
|
| 42 | +** texHandle = NewTexHandle() |
| 43 | +** texHandle:Allocate(format, width, height, layerCount, mipCount) |
| 44 | +** texHandle:Load("<fileName>") |
| 45 | +** texHandle:Save("<fileName>") |
| 46 | +** info = texHandle:Info() |
| 47 | +** isvalid = texHandle:IsValid() |
| 48 | +** texHandle:StackTextures({tex1, tex2, .. texN}) -- all textures must be same shape and format |
| 49 | +** -- texHandle:SetLayer(srcTexHandle, layer) |
| 50 | +** -- texHandle:CopyImage(srcTexHandle, targetX, targetY) |
| 51 | +** -- texHandle:Transcode(newFormat) |
| 52 | +** -- texHandle:GenerateMipmaps() |
| 53 | +** |
39 | 54 | ** RenderInit(["flag1"[, "flag2"...]]) flag:{"DPI_AWARE"}
|
40 | 55 | ** width, height = GetScreenSize()
|
41 | 56 | ** scaleFactor = GetScreenScale()
|
|
94 | 109 | // Grab UI main pointer from the registry
|
95 | 110 | static ui_main_c* GetUIPtr(lua_State* L)
|
96 | 111 | {
|
97 |
| - lua_rawgeti(L, LUA_REGISTRYINDEX, 0); |
| 112 | + lua_geti(L, LUA_REGISTRYINDEX, ui_main_c::REGISTRY_KEY); |
98 | 113 | ui_main_c* ui = (ui_main_c*)lua_touserdata(L, -1);
|
99 | 114 | lua_pop(L, 1);
|
100 | 115 | return ui;
|
@@ -296,7 +311,7 @@ SG_LUA_CPP_FUN_BEGIN(NewArtHandle)
|
296 | 311 | return 0;
|
297 | 312 |
|
298 | 313 | const auto comp = component_count(format);
|
299 |
| - if (comp != 1 || comp != 3 || comp != 4) |
| 314 | + if (comp != 1 && comp != 3 && comp != 4) |
300 | 315 | return 0;
|
301 | 316 |
|
302 | 317 | artHandle_s* artHandle = (artHandle_s*)lua_newuserdata(L, sizeof(artHandle_s));
|
@@ -1751,6 +1766,7 @@ static int l_Exit(lua_State* L)
|
1751 | 1766 |
|
1752 | 1767 | int ui_main_c::InitAPI(lua_State* L)
|
1753 | 1768 | {
|
| 1769 | + sol::state_view lua(L); |
1754 | 1770 | luaL_openlibs(L);
|
1755 | 1771 |
|
1756 | 1772 | // Add "lua/" subdir for non-JIT Lua
|
@@ -1814,6 +1830,33 @@ int ui_main_c::InitAPI(lua_State* L)
|
1814 | 1830 | lua_setfield(L, -2, "Size");
|
1815 | 1831 | lua_setfield(L, LUA_REGISTRYINDEX, "uiarthandlemeta");
|
1816 | 1832 |
|
| 1833 | + sol::usertype<Texture_c> textureType = lua.new_usertype<Texture_c>("Texture", |
| 1834 | + sol::constructors<Texture_c()>()); |
| 1835 | + |
| 1836 | + textureType["Allocate"] = sol::overload( |
| 1837 | + sol::resolve<bool(gli::format,int,int,int,int)>(&Texture_c::Allocate), |
| 1838 | + sol::resolve<bool(std::string_view,int,int,int,int)>(&Texture_c::Allocate)); |
| 1839 | + textureType["Load"] = &Texture_c::Load; |
| 1840 | + textureType["Save"] = &Texture_c::Save; |
| 1841 | + textureType["Info"] = &Texture_c::Info; |
| 1842 | + textureType["IsValid"] = &Texture_c::IsValid; |
| 1843 | + |
| 1844 | + //textureType["SetLayer"] = &Texture_c::SetLayer; |
| 1845 | + //textureType["CopyImage"] = &Texture_c::CopyImage; |
| 1846 | + //textureType["Transcode"] = &Texture_c::Transcode; |
| 1847 | + //textureType["GenerateMipmaps"] = &Texture_c::Transcode; |
| 1848 | + |
| 1849 | + textureType["StackTextures"] = &Texture_c::StackTextures; |
| 1850 | + |
| 1851 | + sol::usertype<TextureInfo_s> textureInfoType = lua.new_usertype<TextureInfo_s>("TextureInfo"); |
| 1852 | + |
| 1853 | + textureInfoType["formatId"] = &TextureInfo_s::formatId; |
| 1854 | + textureInfoType["formatStr"] = &TextureInfo_s::formatStr; |
| 1855 | + textureInfoType["width"] = &TextureInfo_s::width; |
| 1856 | + textureInfoType["height"] = &TextureInfo_s::height; |
| 1857 | + textureInfoType["layerCount"] = &TextureInfo_s::layerCount; |
| 1858 | + textureInfoType["mipCount"] = &TextureInfo_s::mipCount; |
| 1859 | + |
1817 | 1860 | // Rendering
|
1818 | 1861 | ADDFUNC(RenderInit);
|
1819 | 1862 | ADDFUNC(GetScreenSize);
|
|
0 commit comments