lua_RenderState.cpp 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  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_RenderStateStencilFunction.h"
  17. #include "lua_RenderStateStencilOperation.h"
  18. namespace gameplay
  19. {
  20. void luaRegister_RenderState()
  21. {
  22. const luaL_Reg lua_members[] =
  23. {
  24. {"addRef", lua_RenderState_addRef},
  25. {"clearParameter", lua_RenderState_clearParameter},
  26. {"getParameter", lua_RenderState_getParameter},
  27. {"getRefCount", lua_RenderState_getRefCount},
  28. {"getStateBlock", lua_RenderState_getStateBlock},
  29. {"release", lua_RenderState_release},
  30. {"setParameterAutoBinding", lua_RenderState_setParameterAutoBinding},
  31. {"setStateBlock", lua_RenderState_setStateBlock},
  32. {NULL, NULL}
  33. };
  34. const luaL_Reg* lua_statics = NULL;
  35. std::vector<std::string> scopePath;
  36. gameplay::ScriptUtil::registerClass("RenderState", lua_members, NULL, lua_RenderState__gc, lua_statics, scopePath);
  37. }
  38. static RenderState* getInstance(lua_State* state)
  39. {
  40. void* userdata = luaL_checkudata(state, 1, "RenderState");
  41. luaL_argcheck(state, userdata != NULL, 1, "'RenderState' expected.");
  42. return (RenderState*)((gameplay::ScriptUtil::LuaObject*)userdata)->instance;
  43. }
  44. int lua_RenderState__gc(lua_State* state)
  45. {
  46. // Get the number of parameters.
  47. int paramCount = lua_gettop(state);
  48. // Attempt to match the parameters to a valid binding.
  49. switch (paramCount)
  50. {
  51. case 1:
  52. {
  53. if ((lua_type(state, 1) == LUA_TUSERDATA))
  54. {
  55. void* userdata = luaL_checkudata(state, 1, "RenderState");
  56. luaL_argcheck(state, userdata != NULL, 1, "'RenderState' expected.");
  57. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)userdata;
  58. if (object->owns)
  59. {
  60. RenderState* instance = (RenderState*)object->instance;
  61. SAFE_RELEASE(instance);
  62. }
  63. return 0;
  64. }
  65. lua_pushstring(state, "lua_RenderState__gc - Failed to match the given parameters to a valid function signature.");
  66. lua_error(state);
  67. break;
  68. }
  69. default:
  70. {
  71. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  72. lua_error(state);
  73. break;
  74. }
  75. }
  76. return 0;
  77. }
  78. int lua_RenderState_addRef(lua_State* state)
  79. {
  80. // Get the number of parameters.
  81. int paramCount = lua_gettop(state);
  82. // Attempt to match the parameters to a valid binding.
  83. switch (paramCount)
  84. {
  85. case 1:
  86. {
  87. if ((lua_type(state, 1) == LUA_TUSERDATA))
  88. {
  89. RenderState* instance = getInstance(state);
  90. instance->addRef();
  91. return 0;
  92. }
  93. lua_pushstring(state, "lua_RenderState_addRef - Failed to match the given parameters to a valid function signature.");
  94. lua_error(state);
  95. break;
  96. }
  97. default:
  98. {
  99. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  100. lua_error(state);
  101. break;
  102. }
  103. }
  104. return 0;
  105. }
  106. int lua_RenderState_clearParameter(lua_State* state)
  107. {
  108. // Get the number of parameters.
  109. int paramCount = lua_gettop(state);
  110. // Attempt to match the parameters to a valid binding.
  111. switch (paramCount)
  112. {
  113. case 2:
  114. {
  115. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  116. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL))
  117. {
  118. // Get parameter 1 off the stack.
  119. const char* param1 = gameplay::ScriptUtil::getString(2, false);
  120. RenderState* instance = getInstance(state);
  121. instance->clearParameter(param1);
  122. return 0;
  123. }
  124. lua_pushstring(state, "lua_RenderState_clearParameter - 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 2).");
  131. lua_error(state);
  132. break;
  133. }
  134. }
  135. return 0;
  136. }
  137. int lua_RenderState_getParameter(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 2:
  145. {
  146. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  147. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL))
  148. {
  149. // Get parameter 1 off the stack.
  150. const char* param1 = gameplay::ScriptUtil::getString(2, false);
  151. RenderState* instance = getInstance(state);
  152. void* returnPtr = (void*)instance->getParameter(param1);
  153. if (returnPtr)
  154. {
  155. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
  156. object->instance = returnPtr;
  157. object->owns = false;
  158. luaL_getmetatable(state, "MaterialParameter");
  159. lua_setmetatable(state, -2);
  160. }
  161. else
  162. {
  163. lua_pushnil(state);
  164. }
  165. return 1;
  166. }
  167. lua_pushstring(state, "lua_RenderState_getParameter - Failed to match the given parameters to a valid function signature.");
  168. lua_error(state);
  169. break;
  170. }
  171. default:
  172. {
  173. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  174. lua_error(state);
  175. break;
  176. }
  177. }
  178. return 0;
  179. }
  180. int lua_RenderState_getRefCount(lua_State* state)
  181. {
  182. // Get the number of parameters.
  183. int paramCount = lua_gettop(state);
  184. // Attempt to match the parameters to a valid binding.
  185. switch (paramCount)
  186. {
  187. case 1:
  188. {
  189. if ((lua_type(state, 1) == LUA_TUSERDATA))
  190. {
  191. RenderState* instance = getInstance(state);
  192. unsigned int result = instance->getRefCount();
  193. // Push the return value onto the stack.
  194. lua_pushunsigned(state, result);
  195. return 1;
  196. }
  197. lua_pushstring(state, "lua_RenderState_getRefCount - Failed to match the given parameters to a valid function signature.");
  198. lua_error(state);
  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_RenderState_getStateBlock(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 1:
  218. {
  219. if ((lua_type(state, 1) == LUA_TUSERDATA))
  220. {
  221. RenderState* instance = getInstance(state);
  222. void* returnPtr = (void*)instance->getStateBlock();
  223. if (returnPtr)
  224. {
  225. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
  226. object->instance = returnPtr;
  227. object->owns = false;
  228. luaL_getmetatable(state, "RenderStateStateBlock");
  229. lua_setmetatable(state, -2);
  230. }
  231. else
  232. {
  233. lua_pushnil(state);
  234. }
  235. return 1;
  236. }
  237. lua_pushstring(state, "lua_RenderState_getStateBlock - Failed to match the given parameters to a valid function signature.");
  238. lua_error(state);
  239. break;
  240. }
  241. default:
  242. {
  243. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  244. lua_error(state);
  245. break;
  246. }
  247. }
  248. return 0;
  249. }
  250. int lua_RenderState_release(lua_State* state)
  251. {
  252. // Get the number of parameters.
  253. int paramCount = lua_gettop(state);
  254. // Attempt to match the parameters to a valid binding.
  255. switch (paramCount)
  256. {
  257. case 1:
  258. {
  259. if ((lua_type(state, 1) == LUA_TUSERDATA))
  260. {
  261. RenderState* instance = getInstance(state);
  262. instance->release();
  263. return 0;
  264. }
  265. lua_pushstring(state, "lua_RenderState_release - 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_RenderState_setParameterAutoBinding(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 3:
  286. {
  287. do
  288. {
  289. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  290. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
  291. (lua_type(state, 3) == LUA_TSTRING || lua_type(state, 3) == LUA_TNIL))
  292. {
  293. // Get parameter 1 off the stack.
  294. const char* param1 = gameplay::ScriptUtil::getString(2, false);
  295. // Get parameter 2 off the stack.
  296. RenderState::AutoBinding param2 = (RenderState::AutoBinding)lua_enumFromString_RenderStateAutoBinding(luaL_checkstring(state, 3));
  297. RenderState* instance = getInstance(state);
  298. instance->setParameterAutoBinding(param1, param2);
  299. return 0;
  300. }
  301. } while (0);
  302. do
  303. {
  304. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  305. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
  306. (lua_type(state, 3) == LUA_TSTRING || lua_type(state, 3) == LUA_TNIL))
  307. {
  308. // Get parameter 1 off the stack.
  309. const char* param1 = gameplay::ScriptUtil::getString(2, false);
  310. // Get parameter 2 off the stack.
  311. const char* param2 = gameplay::ScriptUtil::getString(3, false);
  312. RenderState* instance = getInstance(state);
  313. instance->setParameterAutoBinding(param1, param2);
  314. return 0;
  315. }
  316. } while (0);
  317. lua_pushstring(state, "lua_RenderState_setParameterAutoBinding - Failed to match the given parameters to a valid function signature.");
  318. lua_error(state);
  319. break;
  320. }
  321. default:
  322. {
  323. lua_pushstring(state, "Invalid number of parameters (expected 3).");
  324. lua_error(state);
  325. break;
  326. }
  327. }
  328. return 0;
  329. }
  330. int lua_RenderState_setStateBlock(lua_State* state)
  331. {
  332. // Get the number of parameters.
  333. int paramCount = lua_gettop(state);
  334. // Attempt to match the parameters to a valid binding.
  335. switch (paramCount)
  336. {
  337. case 2:
  338. {
  339. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  340. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL))
  341. {
  342. // Get parameter 1 off the stack.
  343. bool param1Valid;
  344. gameplay::ScriptUtil::LuaArray<RenderState::StateBlock> param1 = gameplay::ScriptUtil::getObjectPointer<RenderState::StateBlock>(2, "RenderStateStateBlock", false, &param1Valid);
  345. if (!param1Valid)
  346. {
  347. lua_pushstring(state, "Failed to convert parameter 1 to type 'RenderState::StateBlock'.");
  348. lua_error(state);
  349. }
  350. RenderState* instance = getInstance(state);
  351. instance->setStateBlock(param1);
  352. return 0;
  353. }
  354. lua_pushstring(state, "lua_RenderState_setStateBlock - Failed to match the given parameters to a valid function signature.");
  355. lua_error(state);
  356. break;
  357. }
  358. default:
  359. {
  360. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  361. lua_error(state);
  362. break;
  363. }
  364. }
  365. return 0;
  366. }
  367. }