lua_RenderState.cpp 13 KB

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