lua_Technique.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547
  1. #include "Base.h"
  2. #include "ScriptController.h"
  3. #include "lua_Technique.h"
  4. #include "Base.h"
  5. #include "Game.h"
  6. #include "Material.h"
  7. #include "Node.h"
  8. #include "Pass.h"
  9. #include "Ref.h"
  10. #include "RenderState.h"
  11. #include "Technique.h"
  12. #include "lua_RenderStateAutoBinding.h"
  13. #include "lua_RenderStateBlend.h"
  14. namespace gameplay
  15. {
  16. void luaRegister_Technique()
  17. {
  18. const luaL_Reg lua_members[] =
  19. {
  20. {"addRef", lua_Technique_addRef},
  21. {"getId", lua_Technique_getId},
  22. {"getParameter", lua_Technique_getParameter},
  23. {"getPass", lua_Technique_getPass},
  24. {"getPassByIndex", lua_Technique_getPassByIndex},
  25. {"getPassCount", lua_Technique_getPassCount},
  26. {"getRefCount", lua_Technique_getRefCount},
  27. {"getStateBlock", lua_Technique_getStateBlock},
  28. {"release", lua_Technique_release},
  29. {"setParameterAutoBinding", lua_Technique_setParameterAutoBinding},
  30. {"setStateBlock", lua_Technique_setStateBlock},
  31. {NULL, NULL}
  32. };
  33. const luaL_Reg* lua_statics = NULL;
  34. std::vector<std::string> scopePath;
  35. ScriptUtil::registerClass("Technique", lua_members, NULL, lua_Technique__gc, lua_statics, scopePath);
  36. }
  37. static Technique* getInstance(lua_State* state)
  38. {
  39. void* userdata = luaL_checkudata(state, 1, "Technique");
  40. luaL_argcheck(state, userdata != NULL, 1, "'Technique' expected.");
  41. return (Technique*)((ScriptUtil::LuaObject*)userdata)->instance;
  42. }
  43. int lua_Technique__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, "Technique");
  55. luaL_argcheck(state, userdata != NULL, 1, "'Technique' expected.");
  56. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)userdata;
  57. if (object->owns)
  58. {
  59. Technique* instance = (Technique*)object->instance;
  60. SAFE_RELEASE(instance);
  61. }
  62. return 0;
  63. }
  64. lua_pushstring(state, "lua_Technique__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_Technique_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. Technique* instance = getInstance(state);
  89. instance->addRef();
  90. return 0;
  91. }
  92. lua_pushstring(state, "lua_Technique_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_Technique_getId(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. Technique* instance = getInstance(state);
  117. const char* result = instance->getId();
  118. // Push the return value onto the stack.
  119. lua_pushstring(state, result);
  120. return 1;
  121. }
  122. lua_pushstring(state, "lua_Technique_getId - Failed to match the given parameters to a valid function signature.");
  123. lua_error(state);
  124. break;
  125. }
  126. default:
  127. {
  128. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  129. lua_error(state);
  130. break;
  131. }
  132. }
  133. return 0;
  134. }
  135. int lua_Technique_getParameter(lua_State* state)
  136. {
  137. // Get the number of parameters.
  138. int paramCount = lua_gettop(state);
  139. // Attempt to match the parameters to a valid binding.
  140. switch (paramCount)
  141. {
  142. case 2:
  143. {
  144. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  145. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL))
  146. {
  147. // Get parameter 1 off the stack.
  148. ScriptUtil::LuaArray<const char> param1 = ScriptUtil::getString(2, false);
  149. Technique* instance = getInstance(state);
  150. void* returnPtr = (void*)instance->getParameter(param1);
  151. if (returnPtr)
  152. {
  153. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  154. object->instance = returnPtr;
  155. object->owns = false;
  156. luaL_getmetatable(state, "MaterialParameter");
  157. lua_setmetatable(state, -2);
  158. }
  159. else
  160. {
  161. lua_pushnil(state);
  162. }
  163. return 1;
  164. }
  165. lua_pushstring(state, "lua_Technique_getParameter - Failed to match the given parameters to a valid function signature.");
  166. lua_error(state);
  167. break;
  168. }
  169. default:
  170. {
  171. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  172. lua_error(state);
  173. break;
  174. }
  175. }
  176. return 0;
  177. }
  178. int lua_Technique_getPass(lua_State* state)
  179. {
  180. // Get the number of parameters.
  181. int paramCount = lua_gettop(state);
  182. // Attempt to match the parameters to a valid binding.
  183. switch (paramCount)
  184. {
  185. case 2:
  186. {
  187. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  188. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL))
  189. {
  190. // Get parameter 1 off the stack.
  191. ScriptUtil::LuaArray<const char> param1 = ScriptUtil::getString(2, false);
  192. Technique* instance = getInstance(state);
  193. void* returnPtr = (void*)instance->getPass(param1);
  194. if (returnPtr)
  195. {
  196. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  197. object->instance = returnPtr;
  198. object->owns = false;
  199. luaL_getmetatable(state, "Pass");
  200. lua_setmetatable(state, -2);
  201. }
  202. else
  203. {
  204. lua_pushnil(state);
  205. }
  206. return 1;
  207. }
  208. lua_pushstring(state, "lua_Technique_getPass - Failed to match the given parameters to a valid function signature.");
  209. lua_error(state);
  210. break;
  211. }
  212. default:
  213. {
  214. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  215. lua_error(state);
  216. break;
  217. }
  218. }
  219. return 0;
  220. }
  221. int lua_Technique_getPassByIndex(lua_State* state)
  222. {
  223. // Get the number of parameters.
  224. int paramCount = lua_gettop(state);
  225. // Attempt to match the parameters to a valid binding.
  226. switch (paramCount)
  227. {
  228. case 2:
  229. {
  230. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  231. lua_type(state, 2) == LUA_TNUMBER)
  232. {
  233. // Get parameter 1 off the stack.
  234. unsigned int param1 = (unsigned int)luaL_checkunsigned(state, 2);
  235. Technique* instance = getInstance(state);
  236. void* returnPtr = (void*)instance->getPassByIndex(param1);
  237. if (returnPtr)
  238. {
  239. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  240. object->instance = returnPtr;
  241. object->owns = false;
  242. luaL_getmetatable(state, "Pass");
  243. lua_setmetatable(state, -2);
  244. }
  245. else
  246. {
  247. lua_pushnil(state);
  248. }
  249. return 1;
  250. }
  251. lua_pushstring(state, "lua_Technique_getPassByIndex - Failed to match the given parameters to a valid function signature.");
  252. lua_error(state);
  253. break;
  254. }
  255. default:
  256. {
  257. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  258. lua_error(state);
  259. break;
  260. }
  261. }
  262. return 0;
  263. }
  264. int lua_Technique_getPassCount(lua_State* state)
  265. {
  266. // Get the number of parameters.
  267. int paramCount = lua_gettop(state);
  268. // Attempt to match the parameters to a valid binding.
  269. switch (paramCount)
  270. {
  271. case 1:
  272. {
  273. if ((lua_type(state, 1) == LUA_TUSERDATA))
  274. {
  275. Technique* instance = getInstance(state);
  276. unsigned int result = instance->getPassCount();
  277. // Push the return value onto the stack.
  278. lua_pushunsigned(state, result);
  279. return 1;
  280. }
  281. lua_pushstring(state, "lua_Technique_getPassCount - Failed to match the given parameters to a valid function signature.");
  282. lua_error(state);
  283. break;
  284. }
  285. default:
  286. {
  287. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  288. lua_error(state);
  289. break;
  290. }
  291. }
  292. return 0;
  293. }
  294. int lua_Technique_getRefCount(lua_State* state)
  295. {
  296. // Get the number of parameters.
  297. int paramCount = lua_gettop(state);
  298. // Attempt to match the parameters to a valid binding.
  299. switch (paramCount)
  300. {
  301. case 1:
  302. {
  303. if ((lua_type(state, 1) == LUA_TUSERDATA))
  304. {
  305. Technique* instance = getInstance(state);
  306. unsigned int result = instance->getRefCount();
  307. // Push the return value onto the stack.
  308. lua_pushunsigned(state, result);
  309. return 1;
  310. }
  311. lua_pushstring(state, "lua_Technique_getRefCount - Failed to match the given parameters to a valid function signature.");
  312. lua_error(state);
  313. break;
  314. }
  315. default:
  316. {
  317. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  318. lua_error(state);
  319. break;
  320. }
  321. }
  322. return 0;
  323. }
  324. int lua_Technique_getStateBlock(lua_State* state)
  325. {
  326. // Get the number of parameters.
  327. int paramCount = lua_gettop(state);
  328. // Attempt to match the parameters to a valid binding.
  329. switch (paramCount)
  330. {
  331. case 1:
  332. {
  333. if ((lua_type(state, 1) == LUA_TUSERDATA))
  334. {
  335. Technique* instance = getInstance(state);
  336. void* returnPtr = (void*)instance->getStateBlock();
  337. if (returnPtr)
  338. {
  339. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  340. object->instance = returnPtr;
  341. object->owns = false;
  342. luaL_getmetatable(state, "RenderStateStateBlock");
  343. lua_setmetatable(state, -2);
  344. }
  345. else
  346. {
  347. lua_pushnil(state);
  348. }
  349. return 1;
  350. }
  351. lua_pushstring(state, "lua_Technique_getStateBlock - Failed to match the given parameters to a valid function signature.");
  352. lua_error(state);
  353. break;
  354. }
  355. default:
  356. {
  357. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  358. lua_error(state);
  359. break;
  360. }
  361. }
  362. return 0;
  363. }
  364. int lua_Technique_release(lua_State* state)
  365. {
  366. // Get the number of parameters.
  367. int paramCount = lua_gettop(state);
  368. // Attempt to match the parameters to a valid binding.
  369. switch (paramCount)
  370. {
  371. case 1:
  372. {
  373. if ((lua_type(state, 1) == LUA_TUSERDATA))
  374. {
  375. Technique* instance = getInstance(state);
  376. instance->release();
  377. return 0;
  378. }
  379. lua_pushstring(state, "lua_Technique_release - Failed to match the given parameters to a valid function signature.");
  380. lua_error(state);
  381. break;
  382. }
  383. default:
  384. {
  385. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  386. lua_error(state);
  387. break;
  388. }
  389. }
  390. return 0;
  391. }
  392. int lua_Technique_setParameterAutoBinding(lua_State* state)
  393. {
  394. // Get the number of parameters.
  395. int paramCount = lua_gettop(state);
  396. // Attempt to match the parameters to a valid binding.
  397. switch (paramCount)
  398. {
  399. case 3:
  400. {
  401. do
  402. {
  403. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  404. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
  405. (lua_type(state, 3) == LUA_TSTRING || lua_type(state, 3) == LUA_TNIL))
  406. {
  407. // Get parameter 1 off the stack.
  408. ScriptUtil::LuaArray<const char> param1 = ScriptUtil::getString(2, false);
  409. // Get parameter 2 off the stack.
  410. RenderState::AutoBinding param2 = (RenderState::AutoBinding)lua_enumFromString_RenderStateAutoBinding(luaL_checkstring(state, 3));
  411. Technique* instance = getInstance(state);
  412. instance->setParameterAutoBinding(param1, param2);
  413. return 0;
  414. }
  415. } while (0);
  416. do
  417. {
  418. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  419. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
  420. (lua_type(state, 3) == LUA_TSTRING || lua_type(state, 3) == LUA_TNIL))
  421. {
  422. // Get parameter 1 off the stack.
  423. ScriptUtil::LuaArray<const char> param1 = ScriptUtil::getString(2, false);
  424. // Get parameter 2 off the stack.
  425. ScriptUtil::LuaArray<const char> param2 = ScriptUtil::getString(3, false);
  426. Technique* instance = getInstance(state);
  427. instance->setParameterAutoBinding(param1, param2);
  428. return 0;
  429. }
  430. } while (0);
  431. lua_pushstring(state, "lua_Technique_setParameterAutoBinding - Failed to match the given parameters to a valid function signature.");
  432. lua_error(state);
  433. break;
  434. }
  435. default:
  436. {
  437. lua_pushstring(state, "Invalid number of parameters (expected 3).");
  438. lua_error(state);
  439. break;
  440. }
  441. }
  442. return 0;
  443. }
  444. int lua_Technique_setStateBlock(lua_State* state)
  445. {
  446. // Get the number of parameters.
  447. int paramCount = lua_gettop(state);
  448. // Attempt to match the parameters to a valid binding.
  449. switch (paramCount)
  450. {
  451. case 2:
  452. {
  453. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  454. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL))
  455. {
  456. // Get parameter 1 off the stack.
  457. bool param1Valid;
  458. ScriptUtil::LuaArray<RenderState::StateBlock> param1 = ScriptUtil::getObjectPointer<RenderState::StateBlock>(2, "RenderStateStateBlock", false, &param1Valid);
  459. if (!param1Valid)
  460. {
  461. lua_pushstring(state, "Failed to convert parameter 1 to type 'RenderState::StateBlock'.");
  462. lua_error(state);
  463. }
  464. Technique* instance = getInstance(state);
  465. instance->setStateBlock(param1);
  466. return 0;
  467. }
  468. lua_pushstring(state, "lua_Technique_setStateBlock - Failed to match the given parameters to a valid function signature.");
  469. lua_error(state);
  470. break;
  471. }
  472. default:
  473. {
  474. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  475. lua_error(state);
  476. break;
  477. }
  478. }
  479. return 0;
  480. }
  481. }