renderer_base.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. // SPDX-FileCopyrightText: 2014 Citra Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. #include <atomic>
  5. #include <functional>
  6. #include <memory>
  7. #include "common/common_funcs.h"
  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. // Screenshot
  19. std::atomic<bool> screenshot_requested{false};
  20. void* screenshot_bits{};
  21. std::function<void(bool)> screenshot_complete_callback;
  22. Layout::FramebufferLayout screenshot_framebuffer_layout;
  23. };
  24. class RendererBase {
  25. public:
  26. YUZU_NON_COPYABLE(RendererBase);
  27. YUZU_NON_MOVEABLE(RendererBase);
  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. [[nodiscard]] virtual std::string GetDeviceVendor() const = 0;
  35. // Getter/setter functions:
  36. // ------------------------
  37. [[nodiscard]] f32 GetCurrentFPS() const {
  38. return m_current_fps;
  39. }
  40. [[nodiscard]] int GetCurrentFrame() const {
  41. return m_current_frame;
  42. }
  43. [[nodiscard]] Core::Frontend::GraphicsContext& Context() {
  44. return *context;
  45. }
  46. [[nodiscard]] const Core::Frontend::GraphicsContext& Context() const {
  47. return *context;
  48. }
  49. [[nodiscard]] Core::Frontend::EmuWindow& GetRenderWindow() {
  50. return render_window;
  51. }
  52. [[nodiscard]] const Core::Frontend::EmuWindow& GetRenderWindow() const {
  53. return render_window;
  54. }
  55. [[nodiscard]] RendererSettings& Settings() {
  56. return renderer_settings;
  57. }
  58. [[nodiscard]] const RendererSettings& Settings() const {
  59. return renderer_settings;
  60. }
  61. /// Refreshes the settings common to all renderers
  62. void RefreshBaseSettings();
  63. /// Returns true if a screenshot is being processed
  64. bool IsScreenshotPending() const;
  65. /// Request a screenshot of the next frame
  66. void RequestScreenshot(void* data, std::function<void(bool)> callback,
  67. const Layout::FramebufferLayout& layout);
  68. protected:
  69. Core::Frontend::EmuWindow& render_window; ///< Reference to the render window handle.
  70. std::unique_ptr<Core::Frontend::GraphicsContext> context;
  71. f32 m_current_fps = 0.0f; ///< Current framerate, should be set by the renderer
  72. int m_current_frame = 0; ///< Current frame, should be set by the renderer
  73. RendererSettings renderer_settings;
  74. private:
  75. /// Updates the framebuffer layout of the contained render window handle.
  76. void UpdateCurrentFramebufferLayout();
  77. };
  78. } // namespace VideoCore