mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-13 23:11:49 +00:00
add assets.request_texture
This commit is contained in:
parent
5ca0891c3d
commit
6afb5c8c0f
3 changed files with 26 additions and 1 deletions
|
|
@ -5,6 +5,13 @@ A library for working with audio/visual assets.
|
||||||
## Functions
|
## Functions
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
|
-- Requests background texture loading
|
||||||
|
assets.request_texture(
|
||||||
|
-- Image file
|
||||||
|
filename: string,
|
||||||
|
-- Texture name after loading
|
||||||
|
name: string,
|
||||||
|
)
|
||||||
-- Loads a texture
|
-- Loads a texture
|
||||||
assets.load_texture(
|
assets.load_texture(
|
||||||
-- Array of bytes of an image file
|
-- Array of bytes of an image file
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,14 @@
|
||||||
## Функции
|
## Функции
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
|
-- Запрашивает фоновую загрузку текстуры
|
||||||
|
assets.request_texture(
|
||||||
|
-- Файла изображения
|
||||||
|
filename: string,
|
||||||
|
-- Имя текстуры после загрузки
|
||||||
|
name: string,
|
||||||
|
)
|
||||||
|
|
||||||
-- Загружает текстуру
|
-- Загружает текстуру
|
||||||
assets.load_texture(
|
assets.load_texture(
|
||||||
-- Массив байт файла изображения
|
-- Массив байт файла изображения
|
||||||
|
|
@ -33,4 +41,4 @@ assets.to_canvas(
|
||||||
-- так и находящиеся в атласе ("атлас:имя_текстуры").
|
-- так и находящиеся в атласе ("атлас:имя_текстуры").
|
||||||
name: string
|
name: string
|
||||||
) -> Canvas
|
) -> Canvas
|
||||||
```
|
```
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
#include "api_lua.hpp"
|
#include "api_lua.hpp"
|
||||||
|
|
||||||
#include "assets/Assets.hpp"
|
#include "assets/Assets.hpp"
|
||||||
|
#include "assets/AssetsLoader.hpp"
|
||||||
#include "coders/png.hpp"
|
#include "coders/png.hpp"
|
||||||
#include "coders/vcm.hpp"
|
#include "coders/vcm.hpp"
|
||||||
#include "debug/Logger.hpp"
|
#include "debug/Logger.hpp"
|
||||||
|
|
@ -24,6 +25,14 @@ static void load_texture(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int l_request_texture(lua::State* L) {
|
||||||
|
std::string filename = lua::require_string(L, 1);
|
||||||
|
std::string alias = lua::require_string(L, 2);
|
||||||
|
auto& loader = engine->acquireBackgroundLoader();
|
||||||
|
loader.add(AssetType::TEXTURE, filename, alias);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int l_load_texture(lua::State* L) {
|
static int l_load_texture(lua::State* L) {
|
||||||
if (lua::isstring(L, 3) && lua::require_lstring(L, 3) != "png") {
|
if (lua::isstring(L, 3) && lua::require_lstring(L, 3) != "png") {
|
||||||
throw std::runtime_error("unsupportd image format");
|
throw std::runtime_error("unsupportd image format");
|
||||||
|
|
@ -108,6 +117,7 @@ static int l_to_canvas(lua::State* L) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const luaL_Reg assetslib[] = {
|
const luaL_Reg assetslib[] = {
|
||||||
|
{"request_texture", lua::wrap<l_request_texture>},
|
||||||
{"load_texture", lua::wrap<l_load_texture>},
|
{"load_texture", lua::wrap<l_load_texture>},
|
||||||
{"parse_model", lua::wrap<l_parse_model>},
|
{"parse_model", lua::wrap<l_parse_model>},
|
||||||
{"to_canvas", lua::wrap<l_to_canvas>},
|
{"to_canvas", lua::wrap<l_to_canvas>},
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue