renderer_base.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 <memory>
  6. #include "common/common_types.h"
  7. #include "video_core/rasterizer_interface.h"
  8. class EmuWindow;
  9. class RendererBase : NonCopyable {
  10. public:
  11. /// Used to reference a framebuffer
  12. enum kFramebuffer { kFramebuffer_VirtualXFB = 0, kFramebuffer_EFB, kFramebuffer_Texture };
  13. /**
  14. * Struct describing framebuffer metadata
  15. * TODO(bunnei): This struct belongs in the GPU code, but we don't have a good place for it yet.
  16. */
  17. struct FramebufferInfo {
  18. enum class PixelFormat : u32 {
  19. ABGR8 = 1,
  20. };
  21. /**
  22. * Returns the number of bytes per pixel.
  23. */
  24. static u32 BytesPerPixel(PixelFormat format) {
  25. switch (format) {
  26. case PixelFormat::ABGR8:
  27. return 4;
  28. }
  29. UNREACHABLE();
  30. }
  31. VAddr address;
  32. u32 offset;
  33. u32 width;
  34. u32 height;
  35. u32 stride;
  36. PixelFormat pixel_format;
  37. };
  38. virtual ~RendererBase() {}
  39. /// Swap buffers (render frame)
  40. virtual void SwapBuffers(const FramebufferInfo& framebuffer_info) = 0;
  41. /**
  42. * Set the emulator window to use for renderer
  43. * @param window EmuWindow handle to emulator window to use for rendering
  44. */
  45. virtual void SetWindow(EmuWindow* window) = 0;
  46. /// Initialize the renderer
  47. virtual bool Init() = 0;
  48. /// Shutdown the renderer
  49. virtual void ShutDown() = 0;
  50. // Getter/setter functions:
  51. // ------------------------
  52. f32 GetCurrentFPS() const {
  53. return m_current_fps;
  54. }
  55. int GetCurrentFrame() const {
  56. return m_current_frame;
  57. }
  58. VideoCore::RasterizerInterface* Rasterizer() const {
  59. return rasterizer.get();
  60. }
  61. void RefreshRasterizerSetting();
  62. protected:
  63. std::unique_ptr<VideoCore::RasterizerInterface> rasterizer;
  64. f32 m_current_fps = 0.0f; ///< Current framerate, should be set by the renderer
  65. int m_current_frame = 0; ///< Current frame, should be set by the renderer
  66. private:
  67. bool opengl_rasterizer_active = false;
  68. };