renderer_base.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // Copyright 2014 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <atomic>
  6. #include <memory>
  7. #include <optional>
  8. #include "common/common_types.h"
  9. #include "video_core/gpu.h"
  10. #include "video_core/rasterizer_interface.h"
  11. namespace Core::Frontend {
  12. class EmuWindow;
  13. }
  14. namespace VideoCore {
  15. struct RendererSettings {
  16. std::atomic_bool use_framelimiter{false};
  17. std::atomic_bool set_background_color{false};
  18. };
  19. class RendererBase : NonCopyable {
  20. public:
  21. explicit RendererBase(Core::Frontend::EmuWindow& window);
  22. virtual ~RendererBase();
  23. /// Swap buffers (render frame)
  24. virtual void SwapBuffers(
  25. std::optional<std::reference_wrapper<const Tegra::FramebufferConfig>> framebuffer) = 0;
  26. /// Initialize the renderer
  27. virtual bool Init() = 0;
  28. /// Shutdown the renderer
  29. virtual void ShutDown() = 0;
  30. // Getter/setter functions:
  31. // ------------------------
  32. f32 GetCurrentFPS() const {
  33. return m_current_fps;
  34. }
  35. int GetCurrentFrame() const {
  36. return m_current_frame;
  37. }
  38. RasterizerInterface& Rasterizer() {
  39. return *rasterizer;
  40. }
  41. const RasterizerInterface& Rasterizer() const {
  42. return *rasterizer;
  43. }
  44. /// Refreshes the settings common to all renderers
  45. void RefreshBaseSettings();
  46. protected:
  47. Core::Frontend::EmuWindow& render_window; ///< Reference to the render window handle.
  48. std::unique_ptr<RasterizerInterface> rasterizer;
  49. f32 m_current_fps = 0.0f; ///< Current framerate, should be set by the renderer
  50. int m_current_frame = 0; ///< Current frame, should be set by the renderer
  51. RendererSettings renderer_settings;
  52. private:
  53. /// Updates the framebuffer layout of the contained render window handle.
  54. void UpdateCurrentFramebufferLayout();
  55. };
  56. } // namespace VideoCore