lua_Technique.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558
  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. else
  65. {
  66. lua_pushstring(state, "lua_Technique__gc - Failed to match the given parameters to a valid function signature.");
  67. lua_error(state);
  68. }
  69. break;
  70. }
  71. default:
  72. {
  73. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  74. lua_error(state);
  75. break;
  76. }
  77. }
  78. return 0;
  79. }
  80. int lua_Technique_addRef(lua_State* state)
  81. {
  82. // Get the number of parameters.
  83. int paramCount = lua_gettop(state);
  84. // Attempt to match the parameters to a valid binding.
  85. switch (paramCount)
  86. {
  87. case 1:
  88. {
  89. if ((lua_type(state, 1) == LUA_TUSERDATA))
  90. {
  91. Technique* instance = getInstance(state);
  92. instance->addRef();
  93. return 0;
  94. }
  95. else
  96. {
  97. lua_pushstring(state, "lua_Technique_addRef - Failed to match the given parameters to a valid function signature.");
  98. lua_error(state);
  99. }
  100. break;
  101. }
  102. default:
  103. {
  104. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  105. lua_error(state);
  106. break;
  107. }
  108. }
  109. return 0;
  110. }
  111. int lua_Technique_getId(lua_State* state)
  112. {
  113. // Get the number of parameters.
  114. int paramCount = lua_gettop(state);
  115. // Attempt to match the parameters to a valid binding.
  116. switch (paramCount)
  117. {
  118. case 1:
  119. {
  120. if ((lua_type(state, 1) == LUA_TUSERDATA))
  121. {
  122. Technique* instance = getInstance(state);
  123. const char* result = instance->getId();
  124. // Push the return value onto the stack.
  125. lua_pushstring(state, result);
  126. return 1;
  127. }
  128. else
  129. {
  130. lua_pushstring(state, "lua_Technique_getId - Failed to match the given parameters to a valid function signature.");
  131. lua_error(state);
  132. }
  133. break;
  134. }
  135. default:
  136. {
  137. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  138. lua_error(state);
  139. break;
  140. }
  141. }
  142. return 0;
  143. }
  144. int lua_Technique_getParameter(lua_State* state)
  145. {
  146. // Get the number of parameters.
  147. int paramCount = lua_gettop(state);
  148. // Attempt to match the parameters to a valid binding.
  149. switch (paramCount)
  150. {
  151. case 2:
  152. {
  153. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  154. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL))
  155. {
  156. // Get parameter 1 off the stack.
  157. ScriptUtil::LuaArray<const char> param1 = ScriptUtil::getString(2, false);
  158. Technique* instance = getInstance(state);
  159. void* returnPtr = (void*)instance->getParameter(param1);
  160. if (returnPtr)
  161. {
  162. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  163. object->instance = returnPtr;
  164. object->owns = false;
  165. luaL_getmetatable(state, "MaterialParameter");
  166. lua_setmetatable(state, -2);
  167. }
  168. else
  169. {
  170. lua_pushnil(state);
  171. }
  172. return 1;
  173. }
  174. else
  175. {
  176. lua_pushstring(state, "lua_Technique_getParameter - Failed to match the given parameters to a valid function signature.");
  177. lua_error(state);
  178. }
  179. break;
  180. }
  181. default:
  182. {
  183. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  184. lua_error(state);
  185. break;
  186. }
  187. }
  188. return 0;
  189. }
  190. int lua_Technique_getPass(lua_State* state)
  191. {
  192. // Get the number of parameters.
  193. int paramCount = lua_gettop(state);
  194. // Attempt to match the parameters to a valid binding.
  195. switch (paramCount)
  196. {
  197. case 2:
  198. {
  199. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  200. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL))
  201. {
  202. // Get parameter 1 off the stack.
  203. ScriptUtil::LuaArray<const char> param1 = ScriptUtil::getString(2, false);
  204. Technique* instance = getInstance(state);
  205. void* returnPtr = (void*)instance->getPass(param1);
  206. if (returnPtr)
  207. {
  208. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  209. object->instance = returnPtr;
  210. object->owns = false;
  211. luaL_getmetatable(state, "Pass");
  212. lua_setmetatable(state, -2);
  213. }
  214. else
  215. {
  216. lua_pushnil(state);
  217. }
  218. return 1;
  219. }
  220. else
  221. {
  222. lua_pushstring(state, "lua_Technique_getPass - Failed to match the given parameters to a valid function signature.");
  223. lua_error(state);
  224. }
  225. break;
  226. }
  227. default:
  228. {
  229. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  230. lua_error(state);
  231. break;
  232. }
  233. }
  234. return 0;
  235. }
  236. int lua_Technique_getPassByIndex(lua_State* state)
  237. {
  238. // Get the number of parameters.
  239. int paramCount = lua_gettop(state);
  240. // Attempt to match the parameters to a valid binding.
  241. switch (paramCount)
  242. {
  243. case 2:
  244. {
  245. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  246. lua_type(state, 2) == LUA_TNUMBER)
  247. {
  248. // Get parameter 1 off the stack.
  249. unsigned int param1 = (unsigned int)luaL_checkunsigned(state, 2);
  250. Technique* instance = getInstance(state);
  251. void* returnPtr = (void*)instance->getPassByIndex(param1);
  252. if (returnPtr)
  253. {
  254. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  255. object->instance = returnPtr;
  256. object->owns = false;
  257. luaL_getmetatable(state, "Pass");
  258. lua_setmetatable(state, -2);
  259. }
  260. else
  261. {
  262. lua_pushnil(state);
  263. }
  264. return 1;
  265. }
  266. else
  267. {
  268. lua_pushstring(state, "lua_Technique_getPassByIndex - Failed to match the given parameters to a valid function signature.");
  269. lua_error(state);
  270. }
  271. break;
  272. }
  273. default:
  274. {
  275. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  276. lua_error(state);
  277. break;
  278. }
  279. }
  280. return 0;
  281. }
  282. int lua_Technique_getPassCount(lua_State* state)
  283. {
  284. // Get the number of parameters.
  285. int paramCount = lua_gettop(state);
  286. // Attempt to match the parameters to a valid binding.
  287. switch (paramCount)
  288. {
  289. case 1:
  290. {
  291. if ((lua_type(state, 1) == LUA_TUSERDATA))
  292. {
  293. Technique* instance = getInstance(state);
  294. unsigned int result = instance->getPassCount();
  295. // Push the return value onto the stack.
  296. lua_pushunsigned(state, result);
  297. return 1;
  298. }
  299. else
  300. {
  301. lua_pushstring(state, "lua_Technique_getPassCount - Failed to match the given parameters to a valid function signature.");
  302. lua_error(state);
  303. }
  304. break;
  305. }
  306. default:
  307. {
  308. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  309. lua_error(state);
  310. break;
  311. }
  312. }
  313. return 0;
  314. }
  315. int lua_Technique_getRefCount(lua_State* state)
  316. {
  317. // Get the number of parameters.
  318. int paramCount = lua_gettop(state);
  319. // Attempt to match the parameters to a valid binding.
  320. switch (paramCount)
  321. {
  322. case 1:
  323. {
  324. if ((lua_type(state, 1) == LUA_TUSERDATA))
  325. {
  326. Technique* instance = getInstance(state);
  327. unsigned int result = instance->getRefCount();
  328. // Push the return value onto the stack.
  329. lua_pushunsigned(state, result);
  330. return 1;
  331. }
  332. else
  333. {
  334. lua_pushstring(state, "lua_Technique_getRefCount - Failed to match the given parameters to a valid function signature.");
  335. lua_error(state);
  336. }
  337. break;
  338. }
  339. default:
  340. {
  341. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  342. lua_error(state);
  343. break;
  344. }
  345. }
  346. return 0;
  347. }
  348. int lua_Technique_getStateBlock(lua_State* state)
  349. {
  350. // Get the number of parameters.
  351. int paramCount = lua_gettop(state);
  352. // Attempt to match the parameters to a valid binding.
  353. switch (paramCount)
  354. {
  355. case 1:
  356. {
  357. if ((lua_type(state, 1) == LUA_TUSERDATA))
  358. {
  359. Technique* instance = getInstance(state);
  360. void* returnPtr = (void*)instance->getStateBlock();
  361. if (returnPtr)
  362. {
  363. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  364. object->instance = returnPtr;
  365. object->owns = false;
  366. luaL_getmetatable(state, "RenderStateStateBlock");
  367. lua_setmetatable(state, -2);
  368. }
  369. else
  370. {
  371. lua_pushnil(state);
  372. }
  373. return 1;
  374. }
  375. else
  376. {
  377. lua_pushstring(state, "lua_Technique_getStateBlock - Failed to match the given parameters to a valid function signature.");
  378. lua_error(state);
  379. }
  380. break;
  381. }
  382. default:
  383. {
  384. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  385. lua_error(state);
  386. break;
  387. }
  388. }
  389. return 0;
  390. }
  391. int lua_Technique_release(lua_State* state)
  392. {
  393. // Get the number of parameters.
  394. int paramCount = lua_gettop(state);
  395. // Attempt to match the parameters to a valid binding.
  396. switch (paramCount)
  397. {
  398. case 1:
  399. {
  400. if ((lua_type(state, 1) == LUA_TUSERDATA))
  401. {
  402. Technique* instance = getInstance(state);
  403. instance->release();
  404. return 0;
  405. }
  406. else
  407. {
  408. lua_pushstring(state, "lua_Technique_release - Failed to match the given parameters to a valid function signature.");
  409. lua_error(state);
  410. }
  411. break;
  412. }
  413. default:
  414. {
  415. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  416. lua_error(state);
  417. break;
  418. }
  419. }
  420. return 0;
  421. }
  422. int lua_Technique_setParameterAutoBinding(lua_State* state)
  423. {
  424. // Get the number of parameters.
  425. int paramCount = lua_gettop(state);
  426. // Attempt to match the parameters to a valid binding.
  427. switch (paramCount)
  428. {
  429. case 3:
  430. {
  431. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  432. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
  433. (lua_type(state, 3) == LUA_TSTRING || lua_type(state, 3) == LUA_TNIL))
  434. {
  435. // Get parameter 1 off the stack.
  436. ScriptUtil::LuaArray<const char> param1 = ScriptUtil::getString(2, false);
  437. // Get parameter 2 off the stack.
  438. RenderState::AutoBinding param2 = (RenderState::AutoBinding)lua_enumFromString_RenderStateAutoBinding(luaL_checkstring(state, 3));
  439. Technique* instance = getInstance(state);
  440. instance->setParameterAutoBinding(param1, param2);
  441. return 0;
  442. }
  443. else if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  444. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
  445. (lua_type(state, 3) == LUA_TSTRING || lua_type(state, 3) == LUA_TNIL))
  446. {
  447. // Get parameter 1 off the stack.
  448. ScriptUtil::LuaArray<const char> param1 = ScriptUtil::getString(2, false);
  449. // Get parameter 2 off the stack.
  450. ScriptUtil::LuaArray<const char> param2 = ScriptUtil::getString(3, false);
  451. Technique* instance = getInstance(state);
  452. instance->setParameterAutoBinding(param1, param2);
  453. return 0;
  454. }
  455. else
  456. {
  457. lua_pushstring(state, "lua_Technique_setParameterAutoBinding - Failed to match the given parameters to a valid function signature.");
  458. lua_error(state);
  459. }
  460. break;
  461. }
  462. default:
  463. {
  464. lua_pushstring(state, "Invalid number of parameters (expected 3).");
  465. lua_error(state);
  466. break;
  467. }
  468. }
  469. return 0;
  470. }
  471. int lua_Technique_setStateBlock(lua_State* state)
  472. {
  473. // Get the number of parameters.
  474. int paramCount = lua_gettop(state);
  475. // Attempt to match the parameters to a valid binding.
  476. switch (paramCount)
  477. {
  478. case 2:
  479. {
  480. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  481. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL))
  482. {
  483. // Get parameter 1 off the stack.
  484. ScriptUtil::LuaArray<RenderState::StateBlock> param1 = ScriptUtil::getObjectPointer<RenderState::StateBlock>(2, "RenderStateStateBlock", false);
  485. Technique* instance = getInstance(state);
  486. instance->setStateBlock(param1);
  487. return 0;
  488. }
  489. else
  490. {
  491. lua_pushstring(state, "lua_Technique_setStateBlock - Failed to match the given parameters to a valid function signature.");
  492. lua_error(state);
  493. }
  494. break;
  495. }
  496. default:
  497. {
  498. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  499. lua_error(state);
  500. break;
  501. }
  502. }
  503. return 0;
  504. }
  505. }