lua_RenderState.cpp 13 KB

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