lua_Technique.cpp 19 KB

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