summaryrefslogtreecommitdiff
path: root/Runtime/Scripting/Resource/Resource.bind.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Runtime/Scripting/Resource/Resource.bind.cpp')
-rw-r--r--Runtime/Scripting/Resource/Resource.bind.cpp25
1 files changed, 23 insertions, 2 deletions
diff --git a/Runtime/Scripting/Resource/Resource.bind.cpp b/Runtime/Scripting/Resource/Resource.bind.cpp
index 785115a..6f9c0bb 100644
--- a/Runtime/Scripting/Resource/Resource.bind.cpp
+++ b/Runtime/Scripting/Resource/Resource.bind.cpp
@@ -1,11 +1,14 @@
#include "Runtime/Lua/LuaHelper.h"
#include "Runtime/Debug/Log.h"
#include "Runtime/FileSystem/ImageJobs.h"
+#include "Runtime/Graphics/ImageData.h"
+#define STB_IMAGE_IMPLEMENTATION
+#include "ThirdParty/stb/stb_image.h"
using namespace LuaBind;
// Resource.LoadImageDataAsync(path, callback)
-int ReadImageDataAsync(lua_State* L)
+int LoadImageDataJob(lua_State* L)
{
LUA_BIND_STATE(L);
LUA_BIND_CHECK(L, "SF");
@@ -19,8 +22,26 @@ int ReadImageDataAsync(lua_State* L)
return 0;
}
+int LoadImageData(lua_State* L)
+{
+ LUA_BIND_STATE(L);
+
+ const char* path = state.GetValue<const char*>(1, "");
+
+ stbi_set_flip_vertically_on_load(true);
+ ImageData* data = new ImageData(state.GetVM());
+ int channels;
+ data->pixels = stbi_load(path, &data->width, &data->height, &channels, 0);
+ data->format = ImageData::EPixelFormat::RGB;
+ data->type = ImageData::EPixelElementType::UNSIGNED_BYTE;
+
+ data->PushUserdata(state);
+ return 1;
+}
+
static luaL_Reg funcs[] = {
- {"ReadImageDataAsync", ReadImageDataAsync},
+ { "LoadImageData", LoadImageData },
+ { "LoadImageDataJob", LoadImageDataJob },
{0, 0}
};