1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
#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);
Texture* tex = nullptr;
try
{
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;
}
|