renderer_base.h 2.8 KB

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