renderer_base.h 2.1 KB

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