lua_RenderState.cpp 12 KB

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