summaryrefslogtreecommitdiff
path: root/Source/Core/VideoCommon/FramebufferManagerBase.h
blob: 03581468f78286316b6ff17d7714166b22e4ef2e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#pragma once

#include <list>

#include "VideoCommon/VideoCommon.h"

inline bool AddressRangesOverlap(u32 aLower, u32 aUpper, u32 bLower, u32 bUpper)
{
	return !((aLower >= bUpper) || (bLower >= aUpper));
}

struct XFBSourceBase
{
	virtual ~XFBSourceBase() {}

	virtual void DecodeToTexture(u32 xfbAddr, u32 fbWidth, u32 fbHeight) = 0;

	virtual void CopyEFB(float Gamma) = 0;

	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();

	static void CopyToXFB(u32 xfbAddr, u32 fbWidth, u32 fbHeight, const EFBRectangle& sourceRc,float Gamma);
	static const XFBSourceBase* const* GetXFBSource(u32 xfbAddr, u32 fbWidth, u32 fbHeight, u32* xfbCount);

	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; }

	static int ScaleToVirtualXfbWidth(int x);
	static int ScaleToVirtualXfbHeight(int y);

	static unsigned int GetEFBLayers() { return m_EFBLayers; }

protected:
	struct VirtualXFB
	{
		VirtualXFB()
		{
		}

		// Address and size in GameCube RAM
		u32 xfbAddr = 0;
		u32 xfbWidth = 0;
		u32 xfbHeight = 0;

		XFBSourceBase* xfbSource = nullptr;
	};

	typedef std::list<VirtualXFB> VirtualXFBListType;

	static unsigned int m_EFBLayers;

private:
	virtual XFBSourceBase* CreateXFBSource(unsigned int target_width, unsigned int target_height, unsigned int layers) = 0;
	// TODO: figure out why OGL is different for this guy
	virtual void GetTargetSize(unsigned int *width, unsigned int *height) = 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
	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);

	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);

	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];

	static unsigned int s_last_xfb_width;
	static unsigned int s_last_xfb_height;
};

extern FramebufferManagerBase *g_framebuffer_manager;