wrap_Framebuffer.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #include "wrap_Framebuffer.h"
  2. namespace love
  3. {
  4. namespace graphics
  5. {
  6. namespace opengl
  7. {
  8. Framebuffer * luax_checkfbo(lua_State * L, int idx)
  9. {
  10. return luax_checktype<Framebuffer>(L, idx, "Framebuffer", GRAPHICS_FRAMEBUFFER_T);
  11. }
  12. int w_Framebuffer_renderTo(lua_State * L)
  13. {
  14. // As startGrab() clears the framebuffer, better not allow
  15. // grabbing inside another grabbing
  16. if (Framebuffer::current != NULL) {
  17. Framebuffer::bindDefaultBuffer();
  18. return luaL_error(L, "Current render target not the default framebuffer!");
  19. }
  20. Framebuffer * fbo = luax_checkfbo(L, 1);
  21. if (!lua_isfunction(L, 2))
  22. return luaL_error(L, "Need a function to render to fbo");
  23. fbo->startGrab();
  24. lua_settop(L, 2); // make sure the function is on top of the stack
  25. lua_call(L, 0, 0);
  26. fbo->stopGrab();
  27. return 0;
  28. }
  29. int w_Framebuffer_getImageData(lua_State * L)
  30. {
  31. Framebuffer * fbo = luax_checkfbo(L, 1);
  32. love::image::Image * image = luax_getmodule<love::image::Image>(L, "image", MODULE_IMAGE_T);
  33. love::image::ImageData * img = fbo->getImageData( image );
  34. luax_newtype(L, "ImageData", IMAGE_IMAGE_DATA_T, (void *)img);
  35. return 1;
  36. }
  37. static const luaL_Reg functions[] = {
  38. { "renderTo", w_Framebuffer_renderTo },
  39. { "getImageData", w_Framebuffer_getImageData },
  40. { 0, 0 }
  41. };
  42. int luaopen_framebuffer(lua_State * L)
  43. {
  44. return luax_register_type(L, "Framebuffer", functions);
  45. }
  46. } // opengl
  47. } // graphics
  48. } // love