lua_RenderState.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590
  1. #include "Base.h"
  2. #include "ScriptController.h"
  3. #include "lua_RenderState.h"
  4. #include "Base.h"
  5. #include "Game.h"
  6. #include "Node.h"
  7. #include "Pass.h"
  8. #include "Ref.h"
  9. #include "RenderState.h"
  10. #include "Scene.h"
  11. #include "Technique.h"
  12. #include "lua_RenderStateAutoBinding.h"
  13. #include "lua_RenderStateBlend.h"
  14. #include "lua_RenderStateCullFaceSide.h"
  15. #include "lua_RenderStateDepthFunction.h"
  16. #include "lua_RenderStateFrontFace.h"
  17. #include "lua_RenderStateStencilFunction.h"
  18. #include "lua_RenderStateStencilOperation.h"
  19. namespace gameplay
  20. {
  21. void luaRegister_RenderState()
  22. {
  23. const luaL_Reg lua_members[] =
  24. {
  25. {"addParameter", lua_RenderState_addParameter},
  26. {"addRef", lua_RenderState_addRef},
  27. {"getParameter", lua_RenderState_getParameter},
  28. {"getParameterByIndex", lua_RenderState_getParameterByIndex},
  29. {"getParameterCount", lua_RenderState_getParameterCount},
  30. {"getRefCount", lua_RenderState_getRefCount},
  31. {"getStateBlock", lua_RenderState_getStateBlock},
  32. {"release", lua_RenderState_release},
  33. {"removeParameter", lua_RenderState_removeParameter},
  34. {"setNodeBinding", lua_RenderState_setNodeBinding},
  35. {"setParameterAutoBinding", lua_RenderState_setParameterAutoBinding},
  36. {"setStateBlock", lua_RenderState_setStateBlock},
  37. {NULL, NULL}
  38. };
  39. const luaL_Reg* lua_statics = NULL;
  40. std::vector<std::string> scopePath;
  41. gameplay::ScriptUtil::registerClass("RenderState", lua_members, NULL, lua_RenderState__gc, lua_statics, scopePath);
  42. }
  43. static RenderState* getInstance(lua_State* state)
  44. {
  45. void* userdata = luaL_checkudata(state, 1, "RenderState");
  46. luaL_argcheck(state, userdata != NULL, 1, "'RenderState' expected.");
  47. return (RenderState*)((gameplay::ScriptUtil::LuaObject*)userdata)->instance;
  48. }
  49. int lua_RenderState__gc(lua_State* state)
  50. {
  51. // Get the number of parameters.
  52. int paramCount = lua_gettop(state);
  53. // Attempt to match the parameters to a valid binding.
  54. switch (paramCount)
  55. {
  56. case 1:
  57. {
  58. if ((lua_type(state, 1) == LUA_TUSERDATA))
  59. {
  60. void* userdata = luaL_checkudata(state, 1, "RenderState");
  61. luaL_argcheck(state, userdata != NULL, 1, "'RenderState' expected.");
  62. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)userdata;
  63. if (object->owns)
  64. {
  65. RenderState* instance = (RenderState*)object->instance;
  66. SAFE_RELEASE(instance);
  67. }
  68. return 0;
  69. }
  70. lua_pushstring(state, "lua_RenderState__gc - Failed to match the given parameters to a valid function signature.");
  71. lua_error(state);
  72. break;
  73. }
  74. default:
  75. {
  76. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  77. lua_error(state);
  78. break;
  79. }
  80. }
  81. return 0;
  82. }
  83. int lua_RenderState_addParameter(lua_State* state)
  84. {
  85. // Get the number of parameters.
  86. int paramCount = lua_gettop(state);
  87. // Attempt to match the parameters to a valid binding.
  88. switch (paramCount)
  89. {
  90. case 2:
  91. {
  92. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  93. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL))
  94. {
  95. // Get parameter 1 off the stack.
  96. bool param1Valid;
  97. gameplay::ScriptUtil::LuaArray<MaterialParameter> param1 = gameplay::ScriptUtil::getObjectPointer<MaterialParameter>(2, "MaterialParameter", false, &param1Valid);
  98. if (!param1Valid)
  99. {
  100. lua_pushstring(state, "Failed to convert parameter 1 to type 'MaterialParameter'.");
  101. lua_error(state);
  102. }
  103. RenderState* instance = getInstance(state);
  104. instance->addParameter(param1);
  105. return 0;
  106. }
  107. lua_pushstring(state, "lua_RenderState_addParameter - Failed to match the given parameters to a valid function signature.");
  108. lua_error(state);
  109. break;
  110. }
  111. default:
  112. {
  113. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  114. lua_error(state);
  115. break;
  116. }
  117. }
  118. return 0;
  119. }
  120. int lua_RenderState_addRef(lua_State* state)
  121. {
  122. // Get the number of parameters.
  123. int paramCount = lua_gettop(state);
  124. // Attempt to match the parameters to a valid binding.
  125. switch (paramCount)
  126. {
  127. case 1:
  128. {
  129. if ((lua_type(state, 1) == LUA_TUSERDATA))
  130. {
  131. RenderState* instance = getInstance(state);
  132. instance->addRef();
  133. return 0;
  134. }
  135. lua_pushstring(state, "lua_RenderState_addRef - Failed to match the given parameters to a valid function signature.");
  136. lua_error(state);
  137. break;
  138. }
  139. default:
  140. {
  141. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  142. lua_error(state);
  143. break;
  144. }
  145. }
  146. return 0;
  147. }
  148. int lua_RenderState_getParameter(lua_State* state)
  149. {
  150. // Get the number of parameters.
  151. int paramCount = lua_gettop(state);
  152. // Attempt to match the parameters to a valid binding.
  153. switch (paramCount)
  154. {
  155. case 2:
  156. {
  157. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  158. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL))
  159. {
  160. // Get parameter 1 off the stack.
  161. const char* param1 = gameplay::ScriptUtil::getString(2, false);
  162. RenderState* instance = getInstance(state);
  163. void* returnPtr = (void*)instance->getParameter(param1);
  164. if (returnPtr)
  165. {
  166. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
  167. object->instance = returnPtr;
  168. object->owns = false;
  169. luaL_getmetatable(state, "MaterialParameter");
  170. lua_setmetatable(state, -2);
  171. }
  172. else
  173. {
  174. lua_pushnil(state);
  175. }
  176. return 1;
  177. }
  178. lua_pushstring(state, "lua_RenderState_getParameter - Failed to match the given parameters to a valid function signature.");
  179. lua_error(state);
  180. break;
  181. }
  182. default:
  183. {
  184. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  185. lua_error(state);
  186. break;
  187. }
  188. }
  189. return 0;
  190. }
  191. int lua_RenderState_getParameterByIndex(lua_State* state)
  192. {
  193. // Get the number of parameters.
  194. int paramCount = lua_gettop(state);
  195. // Attempt to match the parameters to a valid binding.
  196. switch (paramCount)
  197. {
  198. case 2:
  199. {
  200. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  201. lua_type(state, 2) == LUA_TNUMBER)
  202. {
  203. // Get parameter 1 off the stack.
  204. unsigned int param1 = (unsigned int)luaL_checkunsigned(state, 2);
  205. RenderState* instance = getInstance(state);
  206. void* returnPtr = (void*)instance->getParameterByIndex(param1);
  207. if (returnPtr)
  208. {
  209. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
  210. object->instance = returnPtr;
  211. object->owns = false;
  212. luaL_getmetatable(state, "MaterialParameter");
  213. lua_setmetatable(state, -2);
  214. }
  215. else
  216. {
  217. lua_pushnil(state);
  218. }
  219. return 1;
  220. }
  221. lua_pushstring(state, "lua_RenderState_getParameterByIndex - Failed to match the given parameters to a valid function signature.");
  222. lua_error(state);
  223. break;
  224. }
  225. default:
  226. {
  227. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  228. lua_error(state);
  229. break;
  230. }
  231. }
  232. return 0;
  233. }
  234. int lua_RenderState_getParameterCount(lua_State* state)
  235. {
  236. // Get the number of parameters.
  237. int paramCount = lua_gettop(state);
  238. // Attempt to match the parameters to a valid binding.
  239. switch (paramCount)
  240. {
  241. case 1:
  242. {
  243. if ((lua_type(state, 1) == LUA_TUSERDATA))
  244. {
  245. RenderState* instance = getInstance(state);
  246. unsigned int result = instance->getParameterCount();
  247. // Push the return value onto the stack.
  248. lua_pushunsigned(state, result);
  249. return 1;
  250. }
  251. lua_pushstring(state, "lua_RenderState_getParameterCount - 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 1).");
  258. lua_error(state);
  259. break;
  260. }
  261. }
  262. return 0;
  263. }
  264. int lua_RenderState_getRefCount(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. RenderState* instance = getInstance(state);
  276. unsigned int result = instance->getRefCount();
  277. // Push the return value onto the stack.
  278. lua_pushunsigned(state, result);
  279. return 1;
  280. }
  281. lua_pushstring(state, "lua_RenderState_getRefCount - 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_RenderState_getStateBlock(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. RenderState* instance = getInstance(state);
  306. void* returnPtr = (void*)instance->getStateBlock();
  307. if (returnPtr)
  308. {
  309. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
  310. object->instance = returnPtr;
  311. object->owns = false;
  312. luaL_getmetatable(state, "RenderStateStateBlock");
  313. lua_setmetatable(state, -2);
  314. }
  315. else
  316. {
  317. lua_pushnil(state);
  318. }
  319. return 1;
  320. }
  321. lua_pushstring(state, "lua_RenderState_getStateBlock - Failed to match the given parameters to a valid function signature.");
  322. lua_error(state);
  323. break;
  324. }
  325. default:
  326. {
  327. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  328. lua_error(state);
  329. break;
  330. }
  331. }
  332. return 0;
  333. }
  334. int lua_RenderState_release(lua_State* state)
  335. {
  336. // Get the number of parameters.
  337. int paramCount = lua_gettop(state);
  338. // Attempt to match the parameters to a valid binding.
  339. switch (paramCount)
  340. {
  341. case 1:
  342. {
  343. if ((lua_type(state, 1) == LUA_TUSERDATA))
  344. {
  345. RenderState* instance = getInstance(state);
  346. instance->release();
  347. return 0;
  348. }
  349. lua_pushstring(state, "lua_RenderState_release - 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_RenderState_removeParameter(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 2:
  370. {
  371. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  372. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL))
  373. {
  374. // Get parameter 1 off the stack.
  375. const char* param1 = gameplay::ScriptUtil::getString(2, false);
  376. RenderState* instance = getInstance(state);
  377. instance->removeParameter(param1);
  378. return 0;
  379. }
  380. lua_pushstring(state, "lua_RenderState_removeParameter - Failed to match the given parameters to a valid function signature.");
  381. lua_error(state);
  382. break;
  383. }
  384. default:
  385. {
  386. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  387. lua_error(state);
  388. break;
  389. }
  390. }
  391. return 0;
  392. }
  393. int lua_RenderState_setNodeBinding(lua_State* state)
  394. {
  395. // Get the number of parameters.
  396. int paramCount = lua_gettop(state);
  397. // Attempt to match the parameters to a valid binding.
  398. switch (paramCount)
  399. {
  400. case 2:
  401. {
  402. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  403. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL))
  404. {
  405. // Get parameter 1 off the stack.
  406. bool param1Valid;
  407. gameplay::ScriptUtil::LuaArray<Node> param1 = gameplay::ScriptUtil::getObjectPointer<Node>(2, "Node", false, &param1Valid);
  408. if (!param1Valid)
  409. {
  410. lua_pushstring(state, "Failed to convert parameter 1 to type 'Node'.");
  411. lua_error(state);
  412. }
  413. RenderState* instance = getInstance(state);
  414. instance->setNodeBinding(param1);
  415. return 0;
  416. }
  417. lua_pushstring(state, "lua_RenderState_setNodeBinding - 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 2).");
  424. lua_error(state);
  425. break;
  426. }
  427. }
  428. return 0;
  429. }
  430. int lua_RenderState_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. RenderState* 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. RenderState* instance = getInstance(state);
  465. instance->setParameterAutoBinding(param1, param2);
  466. return 0;
  467. }
  468. } while (0);
  469. lua_pushstring(state, "lua_RenderState_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_RenderState_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. RenderState* instance = getInstance(state);
  503. instance->setStateBlock(param1);
  504. return 0;
  505. }
  506. lua_pushstring(state, "lua_RenderState_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. }