diff options
Diffstat (limited to 'Runtime/Scripting/Rendering/Texture.bind.cpp')
-rw-r--r-- | Runtime/Scripting/Rendering/Texture.bind.cpp | 143 |
1 files changed, 143 insertions, 0 deletions
diff --git a/Runtime/Scripting/Rendering/Texture.bind.cpp b/Runtime/Scripting/Rendering/Texture.bind.cpp new file mode 100644 index 0000000..061a303 --- /dev/null +++ b/Runtime/Scripting/Rendering/Texture.bind.cpp @@ -0,0 +1,143 @@ +#include "Runtime/Graphics/Texture.h"
+
+using namespace LuaBind;
+
+LUA_BIND_REGISTRY(Texture) +{ + LUA_BIND_REGISTER_METHODS(state, + { "New", _New }, + { "GetWidth", _GetWidth }, + { "GetHeight", _GetHeight }, + { "GetSize", _GetSize }, + { "GetType", _GetType }, + { "GetFormat", _GetFormat }, + { "GetWrapMode", _GetWrapMode }, + { "GetImageData", _GetImageData }, + { "IsKeepImageData", _IsKeepImageData }, + { "GetFilterMode", _GetFilterMode } + ); +} + +LUA_BIND_POSTPROCESS(Texture) +{
+ LUA_BIND_REGISTER_ENUM(state, "ETextureType",
+ { "TEX_2D", ETextureType::TEX_2D },
+ { "TEX_CUBE", ETextureType::TEX_CUBE }
+ );
+ LUA_BIND_REGISTER_ENUM(state, "ETextureFormat",
+ { "RGBA32", ETextureFormat::RGBA32 },
+ { "RGB24", ETextureFormat::RGB24 },
+ { "RGB16", ETextureFormat::RGB16 },
+ { "R8", ETextureFormat::R8 },
+ { "A8", ETextureFormat::A8 }
+ );
+ LUA_BIND_REGISTER_ENUM(state, "ETextureWrapMode",
+ { "Clamp", ETextureWrapMode::Clamp },
+ { "Repeat", ETextureWrapMode::Repeat },
+ { "Mirror", ETextureWrapMode::Mirror }
+ );
+ LUA_BIND_REGISTER_ENUM(state, "ETextureFilterMode",
+ { "Nearest", ETextureFilterMode::Nearest },
+ { "Linear", ETextureFilterMode::Linear }
+ );
+}
+
+// Texture.New(imgData, keepImgData, type, format, wrapMode, filterMode)
+LUA_BIND_IMPL_METHOD(Texture, _New)
+{
+ LUA_BIND_STATE(L);
+ LUA_BIND_CHECK(L, "U");
+
+ ImageData* imgData = state.GetUserdata<ImageData>(1);
+
+ TextureSetting setting;
+ setting.keepImageData = state.GetValue(2, false);
+ setting.type = state.GetValue<int>(3, (int)ETextureType::TEX_2D);
+ setting.format = state.GetValue(4, (int)ETextureFormat::RGBA32);
+ setting.wrapMode = state.GetValue(5, (int)ETextureWrapMode::Clamp);
+ setting.filterMode = state.GetValue(6, (int)ETextureFilterMode::Linear);
+
+ try
+ {
+ Texture* tex = new Texture(state.GetVM(), setting, imgData);
+ tex->PushUserdata(state);
+ return 1;
+ }
+ catch (TextureException e)
+ {
+ luaL_error(L, "Failed to create texture.");
+ return 0;
+ }
+ return 0;
+}
+
+LUA_BIND_IMPL_METHOD(Texture, _GetWidth)
+{
+ LUA_BIND_PREPARE(L, Texture);
+ state.Push(self->m_Width);
+ return 1;
+}
+
+LUA_BIND_IMPL_METHOD(Texture, _GetHeight)
+{
+ LUA_BIND_PREPARE(L, Texture);
+ state.Push(self->m_Height);
+ return 1;
+}
+
+LUA_BIND_IMPL_METHOD(Texture, _GetSize)
+{
+ LUA_BIND_PREPARE(L, Texture);
+ state.Push(self->m_Width);
+ state.Push(self->m_Height);
+ return 2;
+}
+
+LUA_BIND_IMPL_METHOD(Texture, _GetType)
+{
+ LUA_BIND_PREPARE(L, Texture);
+ state.Push(self->m_Type);
+ return 1;
+}
+
+LUA_BIND_IMPL_METHOD(Texture, _GetFormat)
+{
+ LUA_BIND_PREPARE(L, Texture);
+ state.Push(self->m_Format);
+ return 1;
+}
+
+LUA_BIND_IMPL_METHOD(Texture, _GetWrapMode)
+{
+ LUA_BIND_PREPARE(L, Texture);
+ state.Push(self->m_WrapMode);
+ return 1;
+}
+
+LUA_BIND_IMPL_METHOD(Texture, _GetFilterMode)
+{
+ LUA_BIND_PREPARE(L, Texture);
+ state.Push(self->m_FilterMode);
+ return 1;
+}
+
+LUA_BIND_IMPL_METHOD(Texture, _IsKeepImageData)
+{
+ LUA_BIND_PREPARE(L, Texture);
+ state.Push(self->m_KeepPixelData);
+ return 1;
+}
+
+LUA_BIND_IMPL_METHOD(Texture, _GetImageData)
+{
+ LUA_BIND_PREPARE(L, Texture);
+ if (self->m_KeepPixelData)
+ {
+ self->PushMemberRef(state, self->m_ImageData);
+ }
+ else
+ {
+ state.PushNil();
+ }
+ return 1;
+}
|