lua_TextureSampler.cpp 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  1. #include "Base.h"
  2. #include "ScriptController.h"
  3. #include "lua_TextureSampler.h"
  4. #include "Base.h"
  5. #include "FileSystem.h"
  6. #include "Game.h"
  7. #include "Image.h"
  8. #include "Ref.h"
  9. #include "Texture.h"
  10. #include "lua_TextureFilter.h"
  11. #include "lua_TextureFormat.h"
  12. #include "lua_TextureWrap.h"
  13. namespace gameplay
  14. {
  15. void luaRegister_TextureSampler()
  16. {
  17. const luaL_Reg lua_members[] =
  18. {
  19. {"addRef", lua_TextureSampler_addRef},
  20. {"bind", lua_TextureSampler_bind},
  21. {"getRefCount", lua_TextureSampler_getRefCount},
  22. {"getTexture", lua_TextureSampler_getTexture},
  23. {"release", lua_TextureSampler_release},
  24. {"setFilterMode", lua_TextureSampler_setFilterMode},
  25. {"setWrapMode", lua_TextureSampler_setWrapMode},
  26. {NULL, NULL}
  27. };
  28. const luaL_Reg lua_statics[] =
  29. {
  30. {"create", lua_TextureSampler_static_create},
  31. {NULL, NULL}
  32. };
  33. std::vector<std::string> scopePath;
  34. scopePath.push_back("Texture");
  35. ScriptUtil::registerClass("TextureSampler", lua_members, NULL, lua_TextureSampler__gc, lua_statics, scopePath);
  36. }
  37. static Texture::Sampler* getInstance(lua_State* state)
  38. {
  39. void* userdata = luaL_checkudata(state, 1, "TextureSampler");
  40. luaL_argcheck(state, userdata != NULL, 1, "'TextureSampler' expected.");
  41. return (Texture::Sampler*)((ScriptUtil::LuaObject*)userdata)->instance;
  42. }
  43. int lua_TextureSampler__gc(lua_State* state)
  44. {
  45. // Get the number of parameters.
  46. int paramCount = lua_gettop(state);
  47. // Attempt to match the parameters to a valid binding.
  48. switch (paramCount)
  49. {
  50. case 1:
  51. {
  52. if ((lua_type(state, 1) == LUA_TUSERDATA))
  53. {
  54. void* userdata = luaL_checkudata(state, 1, "TextureSampler");
  55. luaL_argcheck(state, userdata != NULL, 1, "'TextureSampler' expected.");
  56. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)userdata;
  57. if (object->owns)
  58. {
  59. Texture::Sampler* instance = (Texture::Sampler*)object->instance;
  60. SAFE_RELEASE(instance);
  61. }
  62. return 0;
  63. }
  64. lua_pushstring(state, "lua_TextureSampler__gc - Failed to match the given parameters to a valid function signature.");
  65. lua_error(state);
  66. break;
  67. }
  68. default:
  69. {
  70. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  71. lua_error(state);
  72. break;
  73. }
  74. }
  75. return 0;
  76. }
  77. int lua_TextureSampler_addRef(lua_State* state)
  78. {
  79. // Get the number of parameters.
  80. int paramCount = lua_gettop(state);
  81. // Attempt to match the parameters to a valid binding.
  82. switch (paramCount)
  83. {
  84. case 1:
  85. {
  86. if ((lua_type(state, 1) == LUA_TUSERDATA))
  87. {
  88. Texture::Sampler* instance = getInstance(state);
  89. instance->addRef();
  90. return 0;
  91. }
  92. lua_pushstring(state, "lua_TextureSampler_addRef - Failed to match the given parameters to a valid function signature.");
  93. lua_error(state);
  94. break;
  95. }
  96. default:
  97. {
  98. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  99. lua_error(state);
  100. break;
  101. }
  102. }
  103. return 0;
  104. }
  105. int lua_TextureSampler_bind(lua_State* state)
  106. {
  107. // Get the number of parameters.
  108. int paramCount = lua_gettop(state);
  109. // Attempt to match the parameters to a valid binding.
  110. switch (paramCount)
  111. {
  112. case 1:
  113. {
  114. if ((lua_type(state, 1) == LUA_TUSERDATA))
  115. {
  116. Texture::Sampler* instance = getInstance(state);
  117. instance->bind();
  118. return 0;
  119. }
  120. lua_pushstring(state, "lua_TextureSampler_bind - Failed to match the given parameters to a valid function signature.");
  121. lua_error(state);
  122. break;
  123. }
  124. default:
  125. {
  126. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  127. lua_error(state);
  128. break;
  129. }
  130. }
  131. return 0;
  132. }
  133. int lua_TextureSampler_getRefCount(lua_State* state)
  134. {
  135. // Get the number of parameters.
  136. int paramCount = lua_gettop(state);
  137. // Attempt to match the parameters to a valid binding.
  138. switch (paramCount)
  139. {
  140. case 1:
  141. {
  142. if ((lua_type(state, 1) == LUA_TUSERDATA))
  143. {
  144. Texture::Sampler* instance = getInstance(state);
  145. unsigned int result = instance->getRefCount();
  146. // Push the return value onto the stack.
  147. lua_pushunsigned(state, result);
  148. return 1;
  149. }
  150. lua_pushstring(state, "lua_TextureSampler_getRefCount - Failed to match the given parameters to a valid function signature.");
  151. lua_error(state);
  152. break;
  153. }
  154. default:
  155. {
  156. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  157. lua_error(state);
  158. break;
  159. }
  160. }
  161. return 0;
  162. }
  163. int lua_TextureSampler_getTexture(lua_State* state)
  164. {
  165. // Get the number of parameters.
  166. int paramCount = lua_gettop(state);
  167. // Attempt to match the parameters to a valid binding.
  168. switch (paramCount)
  169. {
  170. case 1:
  171. {
  172. if ((lua_type(state, 1) == LUA_TUSERDATA))
  173. {
  174. Texture::Sampler* instance = getInstance(state);
  175. void* returnPtr = (void*)instance->getTexture();
  176. if (returnPtr)
  177. {
  178. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  179. object->instance = returnPtr;
  180. object->owns = false;
  181. luaL_getmetatable(state, "Texture");
  182. lua_setmetatable(state, -2);
  183. }
  184. else
  185. {
  186. lua_pushnil(state);
  187. }
  188. return 1;
  189. }
  190. lua_pushstring(state, "lua_TextureSampler_getTexture - Failed to match the given parameters to a valid function signature.");
  191. lua_error(state);
  192. break;
  193. }
  194. default:
  195. {
  196. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  197. lua_error(state);
  198. break;
  199. }
  200. }
  201. return 0;
  202. }
  203. int lua_TextureSampler_release(lua_State* state)
  204. {
  205. // Get the number of parameters.
  206. int paramCount = lua_gettop(state);
  207. // Attempt to match the parameters to a valid binding.
  208. switch (paramCount)
  209. {
  210. case 1:
  211. {
  212. if ((lua_type(state, 1) == LUA_TUSERDATA))
  213. {
  214. Texture::Sampler* instance = getInstance(state);
  215. instance->release();
  216. return 0;
  217. }
  218. lua_pushstring(state, "lua_TextureSampler_release - Failed to match the given parameters to a valid function signature.");
  219. lua_error(state);
  220. break;
  221. }
  222. default:
  223. {
  224. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  225. lua_error(state);
  226. break;
  227. }
  228. }
  229. return 0;
  230. }
  231. int lua_TextureSampler_setFilterMode(lua_State* state)
  232. {
  233. // Get the number of parameters.
  234. int paramCount = lua_gettop(state);
  235. // Attempt to match the parameters to a valid binding.
  236. switch (paramCount)
  237. {
  238. case 3:
  239. {
  240. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  241. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
  242. (lua_type(state, 3) == LUA_TSTRING || lua_type(state, 3) == LUA_TNIL))
  243. {
  244. // Get parameter 1 off the stack.
  245. Texture::Filter param1 = (Texture::Filter)lua_enumFromString_TextureFilter(luaL_checkstring(state, 2));
  246. // Get parameter 2 off the stack.
  247. Texture::Filter param2 = (Texture::Filter)lua_enumFromString_TextureFilter(luaL_checkstring(state, 3));
  248. Texture::Sampler* instance = getInstance(state);
  249. instance->setFilterMode(param1, param2);
  250. return 0;
  251. }
  252. lua_pushstring(state, "lua_TextureSampler_setFilterMode - Failed to match the given parameters to a valid function signature.");
  253. lua_error(state);
  254. break;
  255. }
  256. default:
  257. {
  258. lua_pushstring(state, "Invalid number of parameters (expected 3).");
  259. lua_error(state);
  260. break;
  261. }
  262. }
  263. return 0;
  264. }
  265. int lua_TextureSampler_setWrapMode(lua_State* state)
  266. {
  267. // Get the number of parameters.
  268. int paramCount = lua_gettop(state);
  269. // Attempt to match the parameters to a valid binding.
  270. switch (paramCount)
  271. {
  272. case 3:
  273. {
  274. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  275. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
  276. (lua_type(state, 3) == LUA_TSTRING || lua_type(state, 3) == LUA_TNIL))
  277. {
  278. // Get parameter 1 off the stack.
  279. Texture::Wrap param1 = (Texture::Wrap)lua_enumFromString_TextureWrap(luaL_checkstring(state, 2));
  280. // Get parameter 2 off the stack.
  281. Texture::Wrap param2 = (Texture::Wrap)lua_enumFromString_TextureWrap(luaL_checkstring(state, 3));
  282. Texture::Sampler* instance = getInstance(state);
  283. instance->setWrapMode(param1, param2);
  284. return 0;
  285. }
  286. lua_pushstring(state, "lua_TextureSampler_setWrapMode - Failed to match the given parameters to a valid function signature.");
  287. lua_error(state);
  288. break;
  289. }
  290. default:
  291. {
  292. lua_pushstring(state, "Invalid number of parameters (expected 3).");
  293. lua_error(state);
  294. break;
  295. }
  296. }
  297. return 0;
  298. }
  299. int lua_TextureSampler_static_create(lua_State* state)
  300. {
  301. // Get the number of parameters.
  302. int paramCount = lua_gettop(state);
  303. // Attempt to match the parameters to a valid binding.
  304. switch (paramCount)
  305. {
  306. case 1:
  307. {
  308. do
  309. {
  310. if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TTABLE || lua_type(state, 1) == LUA_TNIL))
  311. {
  312. // Get parameter 1 off the stack.
  313. bool param1Valid;
  314. ScriptUtil::LuaArray<Texture> param1 = ScriptUtil::getObjectPointer<Texture>(1, "Texture", false, &param1Valid);
  315. if (!param1Valid)
  316. break;
  317. void* returnPtr = (void*)Texture::Sampler::create(param1);
  318. if (returnPtr)
  319. {
  320. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  321. object->instance = returnPtr;
  322. object->owns = true;
  323. luaL_getmetatable(state, "TextureSampler");
  324. lua_setmetatable(state, -2);
  325. }
  326. else
  327. {
  328. lua_pushnil(state);
  329. }
  330. return 1;
  331. }
  332. } while (0);
  333. do
  334. {
  335. if ((lua_type(state, 1) == LUA_TSTRING || lua_type(state, 1) == LUA_TNIL))
  336. {
  337. // Get parameter 1 off the stack.
  338. ScriptUtil::LuaArray<const char> param1 = ScriptUtil::getString(1, false);
  339. void* returnPtr = (void*)Texture::Sampler::create(param1);
  340. if (returnPtr)
  341. {
  342. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  343. object->instance = returnPtr;
  344. object->owns = true;
  345. luaL_getmetatable(state, "TextureSampler");
  346. lua_setmetatable(state, -2);
  347. }
  348. else
  349. {
  350. lua_pushnil(state);
  351. }
  352. return 1;
  353. }
  354. } while (0);
  355. lua_pushstring(state, "lua_TextureSampler_static_create - Failed to match the given parameters to a valid function signature.");
  356. lua_error(state);
  357. break;
  358. }
  359. case 2:
  360. {
  361. do
  362. {
  363. if ((lua_type(state, 1) == LUA_TSTRING || lua_type(state, 1) == LUA_TNIL) &&
  364. lua_type(state, 2) == LUA_TBOOLEAN)
  365. {
  366. // Get parameter 1 off the stack.
  367. ScriptUtil::LuaArray<const char> param1 = ScriptUtil::getString(1, false);
  368. // Get parameter 2 off the stack.
  369. bool param2 = ScriptUtil::luaCheckBool(state, 2);
  370. void* returnPtr = (void*)Texture::Sampler::create(param1, param2);
  371. if (returnPtr)
  372. {
  373. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  374. object->instance = returnPtr;
  375. object->owns = true;
  376. luaL_getmetatable(state, "TextureSampler");
  377. lua_setmetatable(state, -2);
  378. }
  379. else
  380. {
  381. lua_pushnil(state);
  382. }
  383. return 1;
  384. }
  385. } while (0);
  386. lua_pushstring(state, "lua_TextureSampler_static_create - Failed to match the given parameters to a valid function signature.");
  387. lua_error(state);
  388. break;
  389. }
  390. default:
  391. {
  392. lua_pushstring(state, "Invalid number of parameters (expected 1 or 2).");
  393. lua_error(state);
  394. break;
  395. }
  396. }
  397. return 0;
  398. }
  399. }