renderer.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /* renderer.h - Renderer interface
  2. * Copyright (C) 2017 caryoscelus
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #ifndef CORE_RENDERER_H_E606EAD3_30E1_5114_9BF6_6D4FD2810CAA
  18. #define CORE_RENDERER_H_E606EAD3_30E1_5114_9BF6_6D4FD2810CAA
  19. #include <stdexcept>
  20. #include <boost/signals2/signal.hpp>
  21. #include <core/std/memory.h>
  22. #include <core/std/string.h>
  23. #include <core/time/time.h>
  24. namespace rainynite::core {
  25. class Context;
  26. class RenderFailure : public std::runtime_error {
  27. public:
  28. RenderFailure(string const& msg) :
  29. std::runtime_error(msg)
  30. {}
  31. };
  32. /**
  33. * Interface for Context/Document renderer.
  34. *
  35. * TODO: better control.
  36. */
  37. class Renderer {
  38. public:
  39. /// Render context
  40. virtual void render(Context&& context) = 0;
  41. /// Return true if rendering is done
  42. virtual bool is_finished() const = 0;
  43. /// Stop any rendering
  44. virtual void stop() = 0;
  45. /// Get finished frame signal that is called when a frame is rendered.
  46. inline boost::signals2::signal<void(Time)>& finished_frame() {
  47. return finished_frame_signal;
  48. }
  49. private:
  50. boost::signals2::signal<void(Time)> finished_frame_signal;
  51. };
  52. } // namespace rainynite::core
  53. #endif