lua_Technique.cpp 19 KB

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