wrap_Geometry.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /**
  2. * Copyright (c) 2006-2013 LOVE Development Team
  3. *
  4. * This software is provided 'as-is', without any express or implied
  5. * warranty. In no event will the authors be held liable for any damages
  6. * arising from the use of this software.
  7. *
  8. * Permission is granted to anyone to use this software for any purpose,
  9. * including commercial applications, and to alter it and redistribute it
  10. * freely, subject to the following restrictions:
  11. *
  12. * 1. The origin of this software must not be misrepresented; you must not
  13. * claim that you wrote the original software. If you use this software
  14. * in a product, an acknowledgment in the product documentation would be
  15. * appreciated but is not required.
  16. * 2. Altered source versions must be plainly marked as such, and must not be
  17. * misrepresented as being the original software.
  18. * 3. This notice may not be removed or altered from any source distribution.
  19. **/
  20. // LOVE
  21. #include "wrap_Geometry.h"
  22. #include "common/Exception.h"
  23. namespace love
  24. {
  25. namespace graphics
  26. {
  27. namespace opengl
  28. {
  29. Geometry *luax_checkgeometry(lua_State *L, int idx)
  30. {
  31. return luax_checktype<Geometry>(L, idx, "Geometry", GRAPHICS_GEOMETRY_T);
  32. }
  33. // different name than in Geometry.cpp to make the triangulation transparent
  34. int w_Geometry_getVertexCount(lua_State *L)
  35. {
  36. Geometry *geom = luax_checktype<Geometry>(L, 1, "Geometry", GRAPHICS_GEOMETRY_T);
  37. lua_pushinteger(L, geom->getNumVertices());
  38. return 1;
  39. }
  40. int w_Geometry_getVertex(lua_State *L)
  41. {
  42. Geometry *geom = luax_checktype<Geometry>(L, 1, "Geometry", GRAPHICS_GEOMETRY_T);
  43. size_t i = size_t(luaL_checkint(L, 2));
  44. try
  45. {
  46. const vertex &v = geom->getVertex(i-1);
  47. lua_pushnumber(L, v.x);
  48. lua_pushnumber(L, v.y);
  49. lua_pushnumber(L, v.s);
  50. lua_pushnumber(L, v.t);
  51. lua_pushnumber(L, v.r);
  52. lua_pushnumber(L, v.g);
  53. lua_pushnumber(L, v.b);
  54. lua_pushnumber(L, v.a);
  55. }
  56. catch (Exception &e)
  57. {
  58. return luaL_error(L, e.what());
  59. }
  60. return 8;
  61. }
  62. int w_Geometry_setVertex(lua_State *L)
  63. {
  64. Geometry *geom = luax_checktype<Geometry>(L, 1, "Geometry", GRAPHICS_GEOMETRY_T);
  65. size_t i = size_t(luaL_checkint(L, 2));
  66. vertex v;
  67. v.x = luaL_checknumber(L, 3);
  68. v.y = luaL_checknumber(L, 4);
  69. v.s = luaL_checknumber(L, 5);
  70. v.t = luaL_checknumber(L, 6);
  71. v.r = luaL_optint(L, 7, 255);
  72. v.g = luaL_optint(L, 8, 255);
  73. v.b = luaL_optint(L, 9, 255);
  74. v.a = luaL_optint(L, 10, 255);
  75. try
  76. {
  77. geom->setVertex(i-1, v);
  78. }
  79. catch (Exception &e)
  80. {
  81. return luaL_error(L, e.what());
  82. }
  83. return 0;
  84. }
  85. int w_Geometry_flip(lua_State *L)
  86. {
  87. Geometry *geom = luax_checktype<Geometry>(L, 1, "Geometry", GRAPHICS_GEOMETRY_T);
  88. geom->flip(luax_toboolean(L, 2), luax_toboolean(L, 3));
  89. return 0;
  90. }
  91. static const luaL_Reg w_Geometry_functions[] =
  92. {
  93. { "getVertexCount", w_Geometry_getVertexCount },
  94. { "getVertex", w_Geometry_getVertex },
  95. { "setVertex", w_Geometry_setVertex },
  96. { "flip", w_Geometry_flip },
  97. { 0, 0 }
  98. };
  99. extern "C" int luaopen_geometry(lua_State *L)
  100. {
  101. return luax_register_type(L, "Geometry", w_Geometry_functions);
  102. }
  103. } // opengl
  104. } // graphics
  105. } // love