lua_Pass.cpp 19 KB

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