lua_RenderStateStateBlock.cpp 16 KB

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