lua_RenderStateStateBlock.cpp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514
  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. lua_pushstring(state, "lua_RenderStateStateBlock__gc - Failed to match the given parameters to a valid function signature.");
  69. lua_error(state);
  70. break;
  71. }
  72. default:
  73. {
  74. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  75. lua_error(state);
  76. break;
  77. }
  78. }
  79. return 0;
  80. }
  81. int lua_RenderStateStateBlock_addRef(lua_State* state)
  82. {
  83. // Get the number of parameters.
  84. int paramCount = lua_gettop(state);
  85. // Attempt to match the parameters to a valid binding.
  86. switch (paramCount)
  87. {
  88. case 1:
  89. {
  90. if ((lua_type(state, 1) == LUA_TUSERDATA))
  91. {
  92. RenderState::StateBlock* instance = getInstance(state);
  93. instance->addRef();
  94. return 0;
  95. }
  96. lua_pushstring(state, "lua_RenderStateStateBlock_addRef - Failed to match the given parameters to a valid function signature.");
  97. lua_error(state);
  98. break;
  99. }
  100. default:
  101. {
  102. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  103. lua_error(state);
  104. break;
  105. }
  106. }
  107. return 0;
  108. }
  109. int lua_RenderStateStateBlock_bind(lua_State* state)
  110. {
  111. // Get the number of parameters.
  112. int paramCount = lua_gettop(state);
  113. // Attempt to match the parameters to a valid binding.
  114. switch (paramCount)
  115. {
  116. case 1:
  117. {
  118. if ((lua_type(state, 1) == LUA_TUSERDATA))
  119. {
  120. RenderState::StateBlock* instance = getInstance(state);
  121. instance->bind();
  122. return 0;
  123. }
  124. lua_pushstring(state, "lua_RenderStateStateBlock_bind - Failed to match the given parameters to a valid function signature.");
  125. lua_error(state);
  126. break;
  127. }
  128. default:
  129. {
  130. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  131. lua_error(state);
  132. break;
  133. }
  134. }
  135. return 0;
  136. }
  137. int lua_RenderStateStateBlock_getRefCount(lua_State* state)
  138. {
  139. // Get the number of parameters.
  140. int paramCount = lua_gettop(state);
  141. // Attempt to match the parameters to a valid binding.
  142. switch (paramCount)
  143. {
  144. case 1:
  145. {
  146. if ((lua_type(state, 1) == LUA_TUSERDATA))
  147. {
  148. RenderState::StateBlock* instance = getInstance(state);
  149. unsigned int result = instance->getRefCount();
  150. // Push the return value onto the stack.
  151. lua_pushunsigned(state, result);
  152. return 1;
  153. }
  154. lua_pushstring(state, "lua_RenderStateStateBlock_getRefCount - Failed to match the given parameters to a valid function signature.");
  155. lua_error(state);
  156. break;
  157. }
  158. default:
  159. {
  160. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  161. lua_error(state);
  162. break;
  163. }
  164. }
  165. return 0;
  166. }
  167. int lua_RenderStateStateBlock_release(lua_State* state)
  168. {
  169. // Get the number of parameters.
  170. int paramCount = lua_gettop(state);
  171. // Attempt to match the parameters to a valid binding.
  172. switch (paramCount)
  173. {
  174. case 1:
  175. {
  176. if ((lua_type(state, 1) == LUA_TUSERDATA))
  177. {
  178. RenderState::StateBlock* instance = getInstance(state);
  179. instance->release();
  180. return 0;
  181. }
  182. lua_pushstring(state, "lua_RenderStateStateBlock_release - Failed to match the given parameters to a valid function signature.");
  183. lua_error(state);
  184. break;
  185. }
  186. default:
  187. {
  188. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  189. lua_error(state);
  190. break;
  191. }
  192. }
  193. return 0;
  194. }
  195. int lua_RenderStateStateBlock_setBlend(lua_State* state)
  196. {
  197. // Get the number of parameters.
  198. int paramCount = lua_gettop(state);
  199. // Attempt to match the parameters to a valid binding.
  200. switch (paramCount)
  201. {
  202. case 2:
  203. {
  204. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  205. lua_type(state, 2) == LUA_TBOOLEAN)
  206. {
  207. // Get parameter 1 off the stack.
  208. bool param1 = ScriptUtil::luaCheckBool(state, 2);
  209. RenderState::StateBlock* instance = getInstance(state);
  210. instance->setBlend(param1);
  211. return 0;
  212. }
  213. lua_pushstring(state, "lua_RenderStateStateBlock_setBlend - Failed to match the given parameters to a valid function signature.");
  214. lua_error(state);
  215. break;
  216. }
  217. default:
  218. {
  219. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  220. lua_error(state);
  221. break;
  222. }
  223. }
  224. return 0;
  225. }
  226. int lua_RenderStateStateBlock_setBlendDst(lua_State* state)
  227. {
  228. // Get the number of parameters.
  229. int paramCount = lua_gettop(state);
  230. // Attempt to match the parameters to a valid binding.
  231. switch (paramCount)
  232. {
  233. case 2:
  234. {
  235. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  236. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL))
  237. {
  238. // Get parameter 1 off the stack.
  239. RenderState::Blend param1 = (RenderState::Blend)lua_enumFromString_RenderStateBlend(luaL_checkstring(state, 2));
  240. RenderState::StateBlock* instance = getInstance(state);
  241. instance->setBlendDst(param1);
  242. return 0;
  243. }
  244. lua_pushstring(state, "lua_RenderStateStateBlock_setBlendDst - Failed to match the given parameters to a valid function signature.");
  245. lua_error(state);
  246. break;
  247. }
  248. default:
  249. {
  250. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  251. lua_error(state);
  252. break;
  253. }
  254. }
  255. return 0;
  256. }
  257. int lua_RenderStateStateBlock_setBlendSrc(lua_State* state)
  258. {
  259. // Get the number of parameters.
  260. int paramCount = lua_gettop(state);
  261. // Attempt to match the parameters to a valid binding.
  262. switch (paramCount)
  263. {
  264. case 2:
  265. {
  266. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  267. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL))
  268. {
  269. // Get parameter 1 off the stack.
  270. RenderState::Blend param1 = (RenderState::Blend)lua_enumFromString_RenderStateBlend(luaL_checkstring(state, 2));
  271. RenderState::StateBlock* instance = getInstance(state);
  272. instance->setBlendSrc(param1);
  273. return 0;
  274. }
  275. lua_pushstring(state, "lua_RenderStateStateBlock_setBlendSrc - Failed to match the given parameters to a valid function signature.");
  276. lua_error(state);
  277. break;
  278. }
  279. default:
  280. {
  281. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  282. lua_error(state);
  283. break;
  284. }
  285. }
  286. return 0;
  287. }
  288. int lua_RenderStateStateBlock_setCullFace(lua_State* state)
  289. {
  290. // Get the number of parameters.
  291. int paramCount = lua_gettop(state);
  292. // Attempt to match the parameters to a valid binding.
  293. switch (paramCount)
  294. {
  295. case 2:
  296. {
  297. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  298. lua_type(state, 2) == LUA_TBOOLEAN)
  299. {
  300. // Get parameter 1 off the stack.
  301. bool param1 = ScriptUtil::luaCheckBool(state, 2);
  302. RenderState::StateBlock* instance = getInstance(state);
  303. instance->setCullFace(param1);
  304. return 0;
  305. }
  306. lua_pushstring(state, "lua_RenderStateStateBlock_setCullFace - Failed to match the given parameters to a valid function signature.");
  307. lua_error(state);
  308. break;
  309. }
  310. default:
  311. {
  312. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  313. lua_error(state);
  314. break;
  315. }
  316. }
  317. return 0;
  318. }
  319. int lua_RenderStateStateBlock_setDepthTest(lua_State* state)
  320. {
  321. // Get the number of parameters.
  322. int paramCount = lua_gettop(state);
  323. // Attempt to match the parameters to a valid binding.
  324. switch (paramCount)
  325. {
  326. case 2:
  327. {
  328. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  329. lua_type(state, 2) == LUA_TBOOLEAN)
  330. {
  331. // Get parameter 1 off the stack.
  332. bool param1 = ScriptUtil::luaCheckBool(state, 2);
  333. RenderState::StateBlock* instance = getInstance(state);
  334. instance->setDepthTest(param1);
  335. return 0;
  336. }
  337. lua_pushstring(state, "lua_RenderStateStateBlock_setDepthTest - Failed to match the given parameters to a valid function signature.");
  338. lua_error(state);
  339. break;
  340. }
  341. default:
  342. {
  343. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  344. lua_error(state);
  345. break;
  346. }
  347. }
  348. return 0;
  349. }
  350. int lua_RenderStateStateBlock_setDepthWrite(lua_State* state)
  351. {
  352. // Get the number of parameters.
  353. int paramCount = lua_gettop(state);
  354. // Attempt to match the parameters to a valid binding.
  355. switch (paramCount)
  356. {
  357. case 2:
  358. {
  359. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  360. lua_type(state, 2) == LUA_TBOOLEAN)
  361. {
  362. // Get parameter 1 off the stack.
  363. bool param1 = ScriptUtil::luaCheckBool(state, 2);
  364. RenderState::StateBlock* instance = getInstance(state);
  365. instance->setDepthWrite(param1);
  366. return 0;
  367. }
  368. lua_pushstring(state, "lua_RenderStateStateBlock_setDepthWrite - Failed to match the given parameters to a valid function signature.");
  369. lua_error(state);
  370. break;
  371. }
  372. default:
  373. {
  374. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  375. lua_error(state);
  376. break;
  377. }
  378. }
  379. return 0;
  380. }
  381. int lua_RenderStateStateBlock_setState(lua_State* state)
  382. {
  383. // Get the number of parameters.
  384. int paramCount = lua_gettop(state);
  385. // Attempt to match the parameters to a valid binding.
  386. switch (paramCount)
  387. {
  388. case 3:
  389. {
  390. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  391. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
  392. (lua_type(state, 3) == LUA_TSTRING || lua_type(state, 3) == LUA_TNIL))
  393. {
  394. // Get parameter 1 off the stack.
  395. ScriptUtil::LuaArray<const char> param1 = ScriptUtil::getString(2, false);
  396. // Get parameter 2 off the stack.
  397. ScriptUtil::LuaArray<const char> param2 = ScriptUtil::getString(3, false);
  398. RenderState::StateBlock* instance = getInstance(state);
  399. instance->setState(param1, param2);
  400. return 0;
  401. }
  402. lua_pushstring(state, "lua_RenderStateStateBlock_setState - Failed to match the given parameters to a valid function signature.");
  403. lua_error(state);
  404. break;
  405. }
  406. default:
  407. {
  408. lua_pushstring(state, "Invalid number of parameters (expected 3).");
  409. lua_error(state);
  410. break;
  411. }
  412. }
  413. return 0;
  414. }
  415. int lua_RenderStateStateBlock_static_create(lua_State* state)
  416. {
  417. // Get the number of parameters.
  418. int paramCount = lua_gettop(state);
  419. // Attempt to match the parameters to a valid binding.
  420. switch (paramCount)
  421. {
  422. case 0:
  423. {
  424. void* returnPtr = (void*)RenderState::StateBlock::create();
  425. if (returnPtr)
  426. {
  427. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  428. object->instance = returnPtr;
  429. object->owns = true;
  430. luaL_getmetatable(state, "RenderStateStateBlock");
  431. lua_setmetatable(state, -2);
  432. }
  433. else
  434. {
  435. lua_pushnil(state);
  436. }
  437. return 1;
  438. break;
  439. }
  440. default:
  441. {
  442. lua_pushstring(state, "Invalid number of parameters (expected 0).");
  443. lua_error(state);
  444. break;
  445. }
  446. }
  447. return 0;
  448. }
  449. }