FramebufferManagerBase.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. // Copyright 2010 Dolphin Emulator Project
  2. // Licensed under GPLv2+
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <list>
  6. #include "VideoCommon/VideoCommon.h"
  7. inline bool AddressRangesOverlap(u32 aLower, u32 aUpper, u32 bLower, u32 bUpper)
  8. {
  9. return !((aLower >= bUpper) || (bLower >= aUpper));
  10. }
  11. struct XFBSourceBase
  12. {
  13. virtual ~XFBSourceBase() {}
  14. virtual void DecodeToTexture(u32 xfbAddr, u32 fbWidth, u32 fbHeight) = 0;
  15. virtual void CopyEFB(float Gamma) = 0;
  16. u32 srcAddr;
  17. u32 srcWidth;
  18. u32 srcHeight;
  19. unsigned int texWidth;
  20. unsigned int texHeight;
  21. // TODO: only used by OGL
  22. TargetRectangle sourceRc;
  23. };
  24. class FramebufferManagerBase
  25. {
  26. public:
  27. enum
  28. {
  29. // There may be multiple XFBs in GameCube RAM. This is the maximum number to
  30. // virtualize.
  31. MAX_VIRTUAL_XFB = 8
  32. };
  33. FramebufferManagerBase();
  34. virtual ~FramebufferManagerBase();
  35. static void CopyToXFB(u32 xfbAddr, u32 fbWidth, u32 fbHeight, const EFBRectangle& sourceRc,float Gamma);
  36. static const XFBSourceBase* const* GetXFBSource(u32 xfbAddr, u32 fbWidth, u32 fbHeight, u32* xfbCount);
  37. static void SetLastXfbWidth(unsigned int width) { s_last_xfb_width = width; }
  38. static void SetLastXfbHeight(unsigned int height) { s_last_xfb_height = height; }
  39. static unsigned int LastXfbWidth() { return s_last_xfb_width; }
  40. static unsigned int LastXfbHeight() { return s_last_xfb_height; }
  41. static int ScaleToVirtualXfbWidth(int x);
  42. static int ScaleToVirtualXfbHeight(int y);
  43. static unsigned int GetEFBLayers() { return m_EFBLayers; }
  44. protected:
  45. struct VirtualXFB
  46. {
  47. VirtualXFB()
  48. {
  49. }
  50. // Address and size in GameCube RAM
  51. u32 xfbAddr = 0;
  52. u32 xfbWidth = 0;
  53. u32 xfbHeight = 0;
  54. XFBSourceBase* xfbSource = nullptr;
  55. };
  56. typedef std::list<VirtualXFB> VirtualXFBListType;
  57. static unsigned int m_EFBLayers;
  58. private:
  59. virtual XFBSourceBase* CreateXFBSource(unsigned int target_width, unsigned int target_height, unsigned int layers) = 0;
  60. // TODO: figure out why OGL is different for this guy
  61. virtual void GetTargetSize(unsigned int *width, unsigned int *height) = 0;
  62. static VirtualXFBListType::iterator FindVirtualXFB(u32 xfbAddr, u32 width, u32 height);
  63. static void ReplaceVirtualXFB();
  64. // TODO: merge these virtual funcs, they are nearly all the same
  65. virtual void CopyToRealXFB(u32 xfbAddr, u32 fbWidth, u32 fbHeight, const EFBRectangle& sourceRc,float Gamma = 1.0f) = 0;
  66. static void CopyToVirtualXFB(u32 xfbAddr, u32 fbWidth, u32 fbHeight, const EFBRectangle& sourceRc,float Gamma = 1.0f);
  67. static const XFBSourceBase* const* GetRealXFBSource(u32 xfbAddr, u32 fbWidth, u32 fbHeight, u32* xfbCount);
  68. static const XFBSourceBase* const* GetVirtualXFBSource(u32 xfbAddr, u32 fbWidth, u32 fbHeight, u32* xfbCount);
  69. static XFBSourceBase *m_realXFBSource; // Only used in Real XFB mode
  70. static VirtualXFBListType m_virtualXFBList; // Only used in Virtual XFB mode
  71. static const XFBSourceBase* m_overlappingXFBArray[MAX_VIRTUAL_XFB];
  72. static unsigned int s_last_xfb_width;
  73. static unsigned int s_last_xfb_height;
  74. };
  75. extern FramebufferManagerBase *g_framebuffer_manager;