2015-05-24 04:32:32 +00:00
|
|
|
// Copyright 2010 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2+
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2014-02-10 18:54:46 +00:00
|
|
|
#pragma once
|
2010-11-14 23:56:26 +00:00
|
|
|
|
2015-12-21 19:11:01 +00:00
|
|
|
#include <array>
|
2010-11-14 23:56:26 +00:00
|
|
|
#include <list>
|
2015-12-21 19:11:01 +00:00
|
|
|
#include <memory>
|
2010-11-14 23:56:26 +00:00
|
|
|
|
2016-01-17 21:54:31 +00:00
|
|
|
#include "Common/CommonTypes.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "VideoCommon/VideoCommon.h"
|
2010-11-14 23:56:26 +00:00
|
|
|
|
2014-09-20 18:54:59 +00:00
|
|
|
inline bool AddressRangesOverlap(u32 aLower, u32 aUpper, u32 bLower, u32 bUpper)
|
2010-11-14 23:56:26 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
return !((aLower >= bUpper) || (bLower >= aUpper));
|
2010-11-14 23:56:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct XFBSourceBase
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
virtual ~XFBSourceBase() {}
|
|
|
|
virtual void DecodeToTexture(u32 xfbAddr, u32 fbWidth, u32 fbHeight) = 0;
|
2010-11-14 23:56:26 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
virtual void CopyEFB(float Gamma) = 0;
|
2010-11-14 23:56:26 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
u32 srcAddr;
|
|
|
|
u32 srcWidth;
|
|
|
|
u32 srcHeight;
|
2010-11-14 23:56:26 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
unsigned int texWidth;
|
|
|
|
unsigned int texHeight;
|
2010-11-14 23:56:26 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
// TODO: only used by OGL
|
|
|
|
TargetRectangle sourceRc;
|
2010-11-14 23:56:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class FramebufferManagerBase
|
|
|
|
{
|
|
|
|
public:
|
2016-06-24 08:43:46 +00:00
|
|
|
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 fbStride, 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; }
|
2010-11-14 23:56:26 +00:00
|
|
|
protected:
|
2016-06-24 08:43:46 +00:00
|
|
|
struct VirtualXFB
|
|
|
|
{
|
|
|
|
VirtualXFB() {}
|
|
|
|
// Address and size in GameCube RAM
|
|
|
|
u32 xfbAddr = 0;
|
|
|
|
u32 xfbWidth = 0;
|
|
|
|
u32 xfbHeight = 0;
|
2010-11-14 23:56:26 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
std::unique_ptr<XFBSourceBase> xfbSource;
|
|
|
|
};
|
2010-11-14 23:56:26 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
typedef std::list<VirtualXFB> VirtualXFBListType;
|
2010-11-14 23:56:26 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
static unsigned int m_EFBLayers;
|
2014-11-06 10:41:39 +00:00
|
|
|
|
2010-11-14 23:56:26 +00:00
|
|
|
private:
|
2016-06-24 08:43:46 +00:00
|
|
|
virtual std::unique_ptr<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;
|
2010-11-14 23:56:26 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
static VirtualXFBListType::iterator FindVirtualXFB(u32 xfbAddr, u32 width, u32 height);
|
2010-11-14 23:56:26 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
static void ReplaceVirtualXFB();
|
2010-11-14 23:56:26 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
// TODO: merge these virtual funcs, they are nearly all the same
|
|
|
|
virtual void CopyToRealXFB(u32 xfbAddr, u32 fbStride, 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
|
|
|
|
2016-06-24 08:43:46 +00: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
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
static std::unique_ptr<XFBSourceBase> m_realXFBSource; // Only used in Real XFB mode
|
|
|
|
static VirtualXFBListType m_virtualXFBList; // Only used in Virtual XFB mode
|
2010-11-14 23:56:26 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
static std::array<const XFBSourceBase*, MAX_VIRTUAL_XFB> m_overlappingXFBArray;
|
2012-09-28 21:48:18 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
static unsigned int s_last_xfb_width;
|
|
|
|
static unsigned int s_last_xfb_height;
|
2010-11-14 23:56:26 +00:00
|
|
|
};
|
|
|
|
|
2015-12-22 23:47:20 +00:00
|
|
|
extern std::unique_ptr<FramebufferManagerBase> g_framebuffer_manager;
|