summaryrefslogtreecommitdiff
path: root/Runtime/Scripting/Resource
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-11-03 18:52:30 +0800
committerchai <chaifix@163.com>2021-11-03 18:52:30 +0800
commit08ddd44b634d4da78edd0964f539a310544c7883 (patch)
tree108317d9138c3e8a19f3cc3f2ffcfba4768f22d5 /Runtime/Scripting/Resource
parent6f62a3d5ad405dbab5ac031fb8eeb03bdb395904 (diff)
! UI9Slicing
Diffstat (limited to 'Runtime/Scripting/Resource')
-rw-r--r--Runtime/Scripting/Resource/Resource.bind.cpp21
1 files changed, 19 insertions, 2 deletions
diff --git a/Runtime/Scripting/Resource/Resource.bind.cpp b/Runtime/Scripting/Resource/Resource.bind.cpp
index a09460e..a10ed69 100644
--- a/Runtime/Scripting/Resource/Resource.bind.cpp
+++ b/Runtime/Scripting/Resource/Resource.bind.cpp
@@ -32,8 +32,25 @@ int LoadImageData(lua_State* L)
ImageData* data = new ImageData(state.GetVM());
int channels;
data->pixels = stbi_load(path, &data->width, &data->height, &channels, 0);
- data->format = EPixelFormat::PixelFormat_RGB;
- data->type = EPixelElementType::PixelType_UNSIGNED_BYTE;
+ if (channels == 1)
+ {
+ data->format = EPixelFormat::PixelFormat_R;
+ data->type = EPixelElementType::PixelType_UNSIGNED_BYTE;
+ }
+ else if (channels == 3)
+ {
+ data->format = EPixelFormat::PixelFormat_RGB;
+ data->type = EPixelElementType::PixelType_UNSIGNED_BYTE;
+ }
+ else if(channels == 4)
+ {
+ data->format = EPixelFormat::PixelFormat_RGBA;
+ data->type = EPixelElementType::PixelType_UNSIGNED_BYTE;
+ }
+ else
+ {
+ Assert(false); // 暂时不支持其他格式
+ }
data->PushUserdata(state);
return 1;