wrap_Video.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /**
  2. * Copyright (c) 2006-2016 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. #include "wrap_Video.h"
  21. // Shove the wrap_Video.lua code directly into a raw string literal.
  22. static const char video_lua[] =
  23. #include "wrap_Video.lua"
  24. ;
  25. namespace love
  26. {
  27. namespace graphics
  28. {
  29. namespace opengl
  30. {
  31. Video *luax_checkvideo(lua_State *L, int idx)
  32. {
  33. return luax_checktype<Video>(L, idx);
  34. }
  35. int w_Video_getStream(lua_State *L)
  36. {
  37. Video *video = luax_checkvideo(L, 1);
  38. luax_pushtype(L, video->getStream());
  39. return 1;
  40. }
  41. int w_Video_getSource(lua_State *L)
  42. {
  43. Video *video = luax_checkvideo(L, 1);
  44. auto source = video->getSource();
  45. if (source)
  46. luax_pushtype(L, video->getSource());
  47. else
  48. lua_pushnil(L);
  49. return 1;
  50. }
  51. int w_Video_setSource(lua_State *L)
  52. {
  53. Video *video = luax_checkvideo(L, 1);
  54. if (lua_isnoneornil(L, 2))
  55. video->setSource(nullptr);
  56. else
  57. {
  58. auto source = luax_checktype<love::audio::Source>(L, 2);
  59. video->setSource(source);
  60. }
  61. return 0;
  62. }
  63. int w_Video_getWidth(lua_State *L)
  64. {
  65. Video *video = luax_checkvideo(L, 1);
  66. lua_pushnumber(L, video->getWidth());
  67. return 1;
  68. }
  69. int w_Video_getHeight(lua_State *L)
  70. {
  71. Video *video = luax_checkvideo(L, 1);
  72. lua_pushnumber(L, video->getHeight());
  73. return 1;
  74. }
  75. int w_Video_getDimensions(lua_State *L)
  76. {
  77. Video *video = luax_checkvideo(L, 1);
  78. lua_pushnumber(L, video->getWidth());
  79. lua_pushnumber(L, video->getHeight());
  80. return 2;
  81. }
  82. int w_Video_setFilter(lua_State *L)
  83. {
  84. Video *video = luax_checkvideo(L, 1);
  85. Texture::Filter f = video->getFilter();
  86. const char *minstr = luaL_checkstring(L, 2);
  87. const char *magstr = luaL_optstring(L, 3, minstr);
  88. if (!Texture::getConstant(minstr, f.min))
  89. return luaL_error(L, "Invalid filter mode: %s", minstr);
  90. if (!Texture::getConstant(magstr, f.mag))
  91. return luaL_error(L, "Invalid filter mode: %s", magstr);
  92. f.anisotropy = (float) luaL_optnumber(L, 4, 1.0);
  93. luax_catchexcept(L, [&](){ video->setFilter(f); });
  94. return 0;
  95. }
  96. int w_Video_getFilter(lua_State *L)
  97. {
  98. Video *video = luax_checkvideo(L, 1);
  99. const Texture::Filter f = video->getFilter();
  100. const char *minstr = nullptr;
  101. const char *magstr = nullptr;
  102. if (!Texture::getConstant(f.min, minstr))
  103. return luaL_error(L, "Unknown filter mode.");
  104. if (!Texture::getConstant(f.mag, magstr))
  105. return luaL_error(L, "Unknown filter mode.");
  106. lua_pushstring(L, minstr);
  107. lua_pushstring(L, magstr);
  108. lua_pushnumber(L, f.anisotropy);
  109. return 3;
  110. }
  111. static const luaL_Reg functions[] =
  112. {
  113. { "getStream", w_Video_getStream },
  114. { "getSource", w_Video_getSource },
  115. { "_setSource", w_Video_setSource },
  116. { "getWidth", w_Video_getWidth },
  117. { "getHeight", w_Video_getHeight },
  118. { "getDimensions", w_Video_getDimensions },
  119. { "setFilter", w_Video_setFilter },
  120. { "getFilter", w_Video_getFilter },
  121. { 0, 0 }
  122. };
  123. int luaopen_video(lua_State *L)
  124. {
  125. int ret = luax_register_type(L, Video::type, functions, nullptr);
  126. luaL_loadbuffer(L, video_lua, sizeof(video_lua), "Video.lua");
  127. luax_gettypemetatable(L, Video::type);
  128. lua_call(L, 1, 0);
  129. return ret;
  130. }
  131. } // opengl
  132. } // graphics
  133. } // love