| 
									
										
										
										
											2014-02-10 13:54:46 -05:00
										 |  |  | #pragma once
 | 
					
						
							| 
									
										
										
										
											2010-11-14 23:56:26 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include <list>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-17 05:18:15 -05:00
										 |  |  | #include "VideoCommon/VideoCommon.h"
 | 
					
						
							| 
									
										
										
										
											2010-11-14 23:56:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-20 14:54:59 -04:00
										 |  |  | inline bool AddressRangesOverlap(u32 aLower, u32 aUpper, u32 bLower, u32 bUpper) | 
					
						
							| 
									
										
										
										
											2010-11-14 23:56:26 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	return !((aLower >= bUpper) || (bLower >= aUpper)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | struct XFBSourceBase | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	virtual ~XFBSourceBase() {} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-26 13:21:22 +00:00
										 |  |  | 	virtual void Draw(const MathUtil::Rectangle<int> &sourcerc, | 
					
						
							| 
									
										
										
										
											2014-10-18 09:32:24 +02:00
										 |  |  | 		const MathUtil::Rectangle<float> &drawrc) const {}; | 
					
						
							| 
									
										
										
										
											2010-11-14 23:56:26 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	virtual void DecodeToTexture(u32 xfbAddr, u32 fbWidth, u32 fbHeight) = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-27 03:18:01 +00:00
										 |  |  | 	virtual void CopyEFB(float Gamma) = 0; | 
					
						
							| 
									
										
										
										
											2010-11-14 23:56:26 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	u32 srcAddr; | 
					
						
							|  |  |  | 	u32 srcWidth; | 
					
						
							|  |  |  | 	u32 srcHeight; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	unsigned int texWidth; | 
					
						
							|  |  |  | 	unsigned int texHeight; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// TODO: only used by OGL
 | 
					
						
							|  |  |  | 	TargetRectangle sourceRc; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class FramebufferManagerBase | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  | 	enum | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		// There may be multiple XFBs in GameCube RAM. This is the maximum number to
 | 
					
						
							|  |  |  | 		// virtualize.
 | 
					
						
							|  |  |  | 		MAX_VIRTUAL_XFB = 8 | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	FramebufferManagerBase(); | 
					
						
							|  |  |  | 	virtual ~FramebufferManagerBase(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-27 03:18:01 +00:00
										 |  |  | 	static void CopyToXFB(u32 xfbAddr, u32 fbWidth, u32 fbHeight, const EFBRectangle& sourceRc,float Gamma); | 
					
						
							| 
									
										
										
										
											2014-10-02 02:20:46 -04:00
										 |  |  | 	static const XFBSourceBase* const* GetXFBSource(u32 xfbAddr, u32 fbWidth, u32 fbHeight, u32* xfbCount); | 
					
						
							| 
									
										
										
										
											2010-11-14 23:56:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-28 23:48:18 +02:00
										 |  |  | 	static void SetLastXfbWidth(unsigned int width) { s_last_xfb_width = width; } | 
					
						
							|  |  |  | 	static void SetLastXfbHeight(unsigned int height) { s_last_xfb_height = height; } | 
					
						
							|  |  |  | 	static unsigned int LastXfbWidth() { return s_last_xfb_width; } | 
					
						
							|  |  |  | 	static unsigned int LastXfbHeight() { return s_last_xfb_height; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-02 22:11:15 +02:00
										 |  |  | 	static int ScaleToVirtualXfbWidth(int x, unsigned int backbuffer_width); | 
					
						
							|  |  |  | 	static int ScaleToVirtualXfbHeight(int y, unsigned int backbuffer_height); | 
					
						
							| 
									
										
										
										
											2012-09-29 00:19:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-29 09:53:19 -06:00
										 |  |  | 	static unsigned int GetEFBLayers() { return m_EFBLayers; } | 
					
						
							| 
									
										
										
										
											2014-11-06 11:41:39 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-14 23:56:26 +00:00
										 |  |  | protected: | 
					
						
							|  |  |  | 	struct VirtualXFB | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2014-03-09 21:14:26 +01:00
										 |  |  | 		VirtualXFB() : xfbSource(nullptr) {} | 
					
						
							| 
									
										
										
										
											2010-11-14 23:56:26 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// Address and size in GameCube RAM
 | 
					
						
							|  |  |  | 		u32 xfbAddr; | 
					
						
							|  |  |  | 		u32 xfbWidth; | 
					
						
							|  |  |  | 		u32 xfbHeight; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		XFBSourceBase *xfbSource; | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	typedef std::list<VirtualXFB> VirtualXFBListType; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-06 11:41:39 +01:00
										 |  |  | 	static unsigned int m_EFBLayers; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-14 23:56:26 +00:00
										 |  |  | private: | 
					
						
							|  |  |  | 	virtual XFBSourceBase* CreateXFBSource(unsigned int target_width, unsigned int target_height) = 0; | 
					
						
							|  |  |  | 	// TODO: figure out why OGL is different for this guy
 | 
					
						
							|  |  |  | 	virtual void GetTargetSize(unsigned int *width, unsigned int *height, const EFBRectangle& sourceRc) = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	static VirtualXFBListType::iterator FindVirtualXFB(u32 xfbAddr, u32 width, u32 height); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	static void ReplaceVirtualXFB(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// TODO: merge these virtual funcs, they are nearly all the same
 | 
					
						
							| 
									
										
										
										
											2010-12-27 03:18:01 +00:00
										 |  |  | 	virtual void CopyToRealXFB(u32 xfbAddr, u32 fbWidth, u32 fbHeight, const EFBRectangle& sourceRc,float Gamma = 1.0f) = 0; | 
					
						
							|  |  |  | 	static void CopyToVirtualXFB(u32 xfbAddr, u32 fbWidth, u32 fbHeight, const EFBRectangle& sourceRc,float Gamma = 1.0f); | 
					
						
							| 
									
										
										
										
											2010-11-14 23:56:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-02 02:20:46 -04:00
										 |  |  | 	static const XFBSourceBase* const* GetRealXFBSource(u32 xfbAddr, u32 fbWidth, u32 fbHeight, u32* xfbCount); | 
					
						
							|  |  |  | 	static const XFBSourceBase* const* GetVirtualXFBSource(u32 xfbAddr, u32 fbWidth, u32 fbHeight, u32* xfbCount); | 
					
						
							| 
									
										
										
										
											2010-11-14 23:56:26 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	static XFBSourceBase *m_realXFBSource; // Only used in Real XFB mode
 | 
					
						
							|  |  |  | 	static VirtualXFBListType m_virtualXFBList; // Only used in Virtual XFB mode
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	static const XFBSourceBase* m_overlappingXFBArray[MAX_VIRTUAL_XFB]; | 
					
						
							| 
									
										
										
										
											2012-09-28 23:48:18 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	static unsigned int s_last_xfb_width; | 
					
						
							|  |  |  | 	static unsigned int s_last_xfb_height; | 
					
						
							| 
									
										
										
										
											2010-11-14 23:56:26 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | extern FramebufferManagerBase *g_framebuffer_manager; |