renderer_base.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 "core/frontend/emu_window.h"
  10. #include "video_core/gpu.h"
  11. #include "video_core/rasterizer_interface.h"
  12. namespace Core::Frontend {
  13. class EmuWindow;
  14. class GraphicsContext;
  15. } // namespace Core::Frontend
  16. namespace VideoCore {
  17. struct RendererSettings {
  18. std::atomic_bool use_framelimiter{false};
  19. std::atomic_bool set_background_color{false};
  20. // Screenshot
  21. std::atomic<bool> screenshot_requested{false};
  22. void* screenshot_bits{};
  23. std::function<void()> screenshot_complete_callback;
  24. Layout::FramebufferLayout screenshot_framebuffer_layout;
  25. };
  26. class RendererBase : NonCopyable {
  27. public:
  28. explicit RendererBase(Core::Frontend::EmuWindow& window,
  29. std::unique_ptr<Core::Frontend::GraphicsContext> context);
  30. virtual ~RendererBase();
  31. /// Initialize the renderer
  32. virtual bool Init() = 0;
  33. /// Shutdown the renderer
  34. virtual void ShutDown() = 0;
  35. /// Finalize rendering the guest frame and draw into the presentation texture
  36. virtual void SwapBuffers(const Tegra::FramebufferConfig* framebuffer) = 0;
  37. // Getter/setter functions:
  38. // ------------------------
  39. f32 GetCurrentFPS() const {
  40. return m_current_fps;
  41. }
  42. int GetCurrentFrame() const {
  43. return m_current_frame;
  44. }
  45. RasterizerInterface& Rasterizer() {
  46. return *rasterizer;
  47. }
  48. const RasterizerInterface& Rasterizer() const {
  49. return *rasterizer;
  50. }
  51. Core::Frontend::GraphicsContext& Context() {
  52. return *context;
  53. }
  54. const Core::Frontend::GraphicsContext& Context() const {
  55. return *context;
  56. }
  57. Core::Frontend::EmuWindow& GetRenderWindow() {
  58. return render_window;
  59. }
  60. const Core::Frontend::EmuWindow& GetRenderWindow() const {
  61. return render_window;
  62. }
  63. RendererSettings& Settings() {
  64. return renderer_settings;
  65. }
  66. const RendererSettings& Settings() const {
  67. return renderer_settings;
  68. }
  69. /// Refreshes the settings common to all renderers
  70. void RefreshBaseSettings();
  71. /// Request a screenshot of the next frame
  72. void RequestScreenshot(void* data, std::function<void()> callback,
  73. const Layout::FramebufferLayout& layout);
  74. protected:
  75. Core::Frontend::EmuWindow& render_window; ///< Reference to the render window handle.
  76. std::unique_ptr<RasterizerInterface> rasterizer;
  77. std::unique_ptr<Core::Frontend::GraphicsContext> context;
  78. f32 m_current_fps = 0.0f; ///< Current framerate, should be set by the renderer
  79. int m_current_frame = 0; ///< Current frame, should be set by the renderer
  80. RendererSettings renderer_settings;
  81. private:
  82. /// Updates the framebuffer layout of the contained render window handle.
  83. void UpdateCurrentFramebufferLayout();
  84. };
  85. } // namespace VideoCore