renderer_base.h 3.0 KB

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