renderer_base.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. /// Finalize rendering the guest frame and draw into the presentation texture
  32. virtual void SwapBuffers(const Tegra::FramebufferConfig* framebuffer) = 0;
  33. [[nodiscard]] virtual RasterizerInterface* ReadRasterizer() = 0;
  34. // Getter/setter functions:
  35. // ------------------------
  36. [[nodiscard]] f32 GetCurrentFPS() const {
  37. return m_current_fps;
  38. }
  39. [[nodiscard]] int GetCurrentFrame() const {
  40. return m_current_frame;
  41. }
  42. [[nodiscard]] Core::Frontend::GraphicsContext& Context() {
  43. return *context;
  44. }
  45. [[nodiscard]] const Core::Frontend::GraphicsContext& Context() const {
  46. return *context;
  47. }
  48. [[nodiscard]] Core::Frontend::EmuWindow& GetRenderWindow() {
  49. return render_window;
  50. }
  51. [[nodiscard]] const Core::Frontend::EmuWindow& GetRenderWindow() const {
  52. return render_window;
  53. }
  54. [[nodiscard]] RendererSettings& Settings() {
  55. return renderer_settings;
  56. }
  57. [[nodiscard]] const RendererSettings& Settings() const {
  58. return renderer_settings;
  59. }
  60. /// Refreshes the settings common to all renderers
  61. void RefreshBaseSettings();
  62. /// Request a screenshot of the next frame
  63. void RequestScreenshot(void* data, std::function<void()> callback,
  64. const Layout::FramebufferLayout& layout);
  65. protected:
  66. Core::Frontend::EmuWindow& render_window; ///< Reference to the render window handle.
  67. std::unique_ptr<Core::Frontend::GraphicsContext> context;
  68. f32 m_current_fps = 0.0f; ///< Current framerate, should be set by the renderer
  69. int m_current_frame = 0; ///< Current frame, should be set by the renderer
  70. RendererSettings renderer_settings;
  71. private:
  72. /// Updates the framebuffer layout of the contained render window handle.
  73. void UpdateCurrentFramebufferLayout();
  74. };
  75. } // namespace VideoCore