2010-07-10 08:20:50 +00:00
|
|
|
/* ZZ Open GL graphics plugin
|
|
|
|
* Copyright (c)2009-2010 zeydlitz@gmail.com, arcum42@gmail.com
|
|
|
|
* Based on Zerofrog's ZeroGS KOSMOS (c)2005-2008
|
2010-03-19 00:31:15 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2010-07-04 22:49:00 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
2010-03-19 00:31:15 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __ZEROGS_TARGETS_H__
|
|
|
|
#define __ZEROGS_TARGETS_H__
|
|
|
|
|
|
|
|
#define TARGET_VIRTUAL_KEY 0x80000000
|
|
|
|
#include "PS2Edefs.h"
|
2010-10-18 11:24:40 +00:00
|
|
|
#include <list>
|
|
|
|
#include <map>
|
|
|
|
#include "GS.h"
|
|
|
|
#include "ZZGl.h"
|
2010-10-23 08:15:39 +00:00
|
|
|
//#include "ZZoglVB.h"
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-08-18 13:38:45 +00:00
|
|
|
#ifndef GL_TEXTURE_RECTANGLE
|
|
|
|
#define GL_TEXTURE_RECTANGLE GL_TEXTURE_RECTANGLE_NV
|
|
|
|
#endif
|
|
|
|
|
2010-10-23 23:02:19 +00:00
|
|
|
#define VB_BUFFERSIZE 0x4000
|
2010-10-17 07:57:25 +00:00
|
|
|
|
2012-04-19 21:22:08 +00:00
|
|
|
extern void FlushIfNecesary(void* ptr);
|
|
|
|
extern bool g_bSaveZUpdate;
|
|
|
|
|
2010-10-17 08:47:31 +00:00
|
|
|
// all textures have this width
|
|
|
|
extern int GPU_TEXWIDTH;
|
|
|
|
extern float g_fiGPU_TEXWIDTH;
|
|
|
|
#define MASKDIVISOR 0 // Used for decrement bitwise mask texture size if 1024 is too big
|
|
|
|
#define GPU_TEXMASKWIDTH (1024 >> MASKDIVISOR) // bitwise mask width for region repeat mode
|
|
|
|
|
2010-10-17 07:57:25 +00:00
|
|
|
// managers render-to-texture targets
|
|
|
|
class CRenderTarget
|
|
|
|
{
|
|
|
|
|
|
|
|
public:
|
|
|
|
CRenderTarget();
|
|
|
|
virtual ~CRenderTarget();
|
|
|
|
|
|
|
|
virtual bool Create(const frameInfo& frame);
|
|
|
|
virtual void Destroy();
|
|
|
|
|
|
|
|
// set the GPU_POSXY variable, scissor rect, and current render target
|
|
|
|
void SetTarget(int fbplocal, const Rect2& scissor, int context);
|
|
|
|
void SetViewport();
|
|
|
|
|
|
|
|
// copies/creates the feedback contents
|
|
|
|
inline void CreateFeedback()
|
|
|
|
{
|
|
|
|
if (ptexFeedback == 0 || !(status&TS_FeedbackReady))
|
|
|
|
_CreateFeedback();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void Resolve();
|
|
|
|
virtual void Resolve(int startrange, int endrange); // resolves only in the allowed range
|
|
|
|
virtual void Update(int context, CRenderTarget* pdepth);
|
|
|
|
virtual void ConvertTo32(); // converts a psm==2 target, to a psm==0
|
|
|
|
virtual void ConvertTo16(); // converts a psm==0 target, to a psm==2
|
|
|
|
|
|
|
|
virtual bool IsDepth() { return false; }
|
|
|
|
|
|
|
|
void SetRenderTarget(int targ);
|
|
|
|
|
|
|
|
void* psys; // system data used for comparison
|
|
|
|
u32 ptex;
|
|
|
|
|
|
|
|
int fbp, fbw, fbh, fbhCalc; // if fbp is negative, virtual target (not mapped to any real addr)
|
|
|
|
int start, end; // in bytes
|
|
|
|
u32 lastused; // time stamp since last used
|
|
|
|
float4 vposxy;
|
|
|
|
|
|
|
|
u32 fbm;
|
|
|
|
u16 status;
|
|
|
|
u8 psm;
|
|
|
|
u8 resv0;
|
|
|
|
Rect scissorrect;
|
|
|
|
|
|
|
|
u8 created; // Check for object destruction/creating for r201.
|
|
|
|
|
|
|
|
//int startresolve, endresolve;
|
|
|
|
u32 nUpdateTarg; // use this target to update the texture if non 0 (one time only)
|
|
|
|
|
|
|
|
// this is optionally used when feedback effects are used (render target is used as a texture when rendering to itself)
|
|
|
|
u32 ptexFeedback;
|
|
|
|
|
|
|
|
enum TargetStatus
|
|
|
|
{
|
|
|
|
TS_Resolved = 1,
|
|
|
|
TS_NeedUpdate = 2,
|
|
|
|
TS_Virtual = 4, // currently not mapped to memory
|
|
|
|
TS_FeedbackReady = 8, // feedback effect is ready and doesn't need to be updated
|
|
|
|
TS_NeedConvert32 = 16,
|
2012-04-19 21:22:08 +00:00
|
|
|
TS_NeedConvert16 = 32
|
2010-10-17 07:57:25 +00:00
|
|
|
};
|
2012-04-19 21:22:08 +00:00
|
|
|
float4 DefaultBitBltPos();
|
|
|
|
float4 DefaultBitBltTex();
|
2010-10-17 07:57:25 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
void _CreateFeedback();
|
|
|
|
inline bool InitialiseDefaultTexture(u32 *p_ptr, int fbw, int fbh) ;
|
|
|
|
};
|
|
|
|
|
|
|
|
// manages zbuffers
|
|
|
|
|
|
|
|
class CDepthTarget : public CRenderTarget
|
|
|
|
{
|
|
|
|
|
|
|
|
public:
|
|
|
|
CDepthTarget();
|
|
|
|
virtual ~CDepthTarget();
|
|
|
|
|
|
|
|
virtual bool Create(const frameInfo& frame);
|
|
|
|
virtual void Destroy();
|
|
|
|
|
|
|
|
virtual void Resolve();
|
|
|
|
virtual void Resolve(int startrange, int endrange); // resolves only in the allowed range
|
|
|
|
virtual void Update(int context, CRenderTarget* prndr);
|
|
|
|
|
|
|
|
virtual bool IsDepth() { return true; }
|
|
|
|
|
|
|
|
void SetDepthStencilSurface();
|
|
|
|
|
|
|
|
u32 pdepth; // 24 bit, will contain the stencil buffer if possible
|
|
|
|
u32 pstencil; // if not 0, contains the stencil buffer
|
|
|
|
int icount; // internal counter
|
|
|
|
};
|
|
|
|
|
|
|
|
// manages contiguous chunks of memory (width is always 1024)
|
|
|
|
|
|
|
|
class CMemoryTarget
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
struct TEXTURE
|
|
|
|
{
|
|
|
|
inline TEXTURE() : tex(0), memptr(NULL), ref(0) {}
|
|
|
|
inline ~TEXTURE() { glDeleteTextures(1, &tex); _aligned_free(memptr); }
|
|
|
|
|
|
|
|
u32 tex;
|
|
|
|
u8* memptr; // GPU memory used for comparison
|
|
|
|
int ref;
|
|
|
|
};
|
|
|
|
|
2010-10-26 21:14:15 +00:00
|
|
|
inline CMemoryTarget() : ptex(NULL), starty(0), height(0), realy(0), realheight(0), usedstamp(0), psm(0), cpsm(0), channels(0), clearminy(0), clearmaxy(0), validatecount(0), clut(NULL), clutsize(0) {}
|
2010-10-17 07:57:25 +00:00
|
|
|
|
|
|
|
inline CMemoryTarget(const CMemoryTarget& r)
|
|
|
|
{
|
|
|
|
ptex = r.ptex;
|
|
|
|
|
|
|
|
if (ptex != NULL) ptex->ref++;
|
|
|
|
|
|
|
|
starty = r.starty;
|
|
|
|
height = r.height;
|
|
|
|
realy = r.realy;
|
|
|
|
realheight = r.realheight;
|
|
|
|
usedstamp = r.usedstamp;
|
|
|
|
psm = r.psm;
|
|
|
|
cpsm = r.cpsm;
|
|
|
|
clut = r.clut;
|
|
|
|
clearminy = r.clearminy;
|
|
|
|
clearmaxy = r.clearmaxy;
|
|
|
|
widthmult = r.widthmult;
|
|
|
|
texH = r.texH;
|
|
|
|
texW = r.texW;
|
|
|
|
channels = r.channels;
|
|
|
|
validatecount = r.validatecount;
|
|
|
|
fmt = r.fmt;
|
|
|
|
}
|
|
|
|
|
|
|
|
~CMemoryTarget() { Destroy(); }
|
|
|
|
|
|
|
|
inline void Destroy()
|
|
|
|
{
|
|
|
|
if (ptex != NULL && ptex->ref > 0)
|
|
|
|
{
|
|
|
|
if (--ptex->ref <= 0) delete ptex;
|
|
|
|
}
|
|
|
|
|
|
|
|
ptex = NULL;
|
2010-10-19 17:53:36 +00:00
|
|
|
|
|
|
|
_aligned_free(clut);
|
|
|
|
clut = NULL;
|
|
|
|
clutsize = 0;
|
2010-10-17 07:57:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// returns true if clut data is synced
|
|
|
|
bool ValidateClut(const tex0Info& tex0);
|
|
|
|
// returns true if tex data is synced
|
|
|
|
bool ValidateTex(const tex0Info& tex0, int starttex, int endtex, bool bDeleteBadTex);
|
|
|
|
|
|
|
|
// realy is offset in pixels from start of valid region
|
|
|
|
// so texture in memory is [realy,starty+height]
|
|
|
|
// valid texture is [starty,starty+height]
|
|
|
|
// offset in mem [starty-realy, height]
|
|
|
|
TEXTURE* ptex; // can be 16bit
|
|
|
|
|
|
|
|
int starty, height; // assert(starty >= realy)
|
|
|
|
int realy, realheight; // this is never touched once allocated
|
|
|
|
// realy is start pointer of data in 4M data block (start) and size (end-start).
|
|
|
|
|
|
|
|
u32 usedstamp;
|
|
|
|
u8 psm, cpsm; // texture and clut format. For psm, only 16bit/32bit differentiation matters
|
|
|
|
|
|
|
|
u32 fmt;
|
|
|
|
|
|
|
|
int widthmult; // Either 1 or 2.
|
|
|
|
int channels; // The number of pixels per PSM format word. channels == PIXELS_PER_WORD(psm)
|
|
|
|
// This is the real drawing size in pixels of the texture in renderbuffer.
|
|
|
|
int texW; // (realheight + widthmult - 1)/widthmult == realheight or [(realheight+1)/2]
|
|
|
|
int texH; // GPU_TEXWIDTH *widthmult * channels;
|
|
|
|
|
|
|
|
int clearminy, clearmaxy; // when maxy > 0, need to check for clearing
|
|
|
|
|
|
|
|
int validatecount; // count how many times has been validated, if too many, destroy
|
|
|
|
|
2010-10-19 17:53:36 +00:00
|
|
|
u8* clut; // Clut texture data. Null otherwise
|
|
|
|
int clutsize; // size of the clut array. 0 otherwise
|
2010-10-17 07:57:25 +00:00
|
|
|
};
|
|
|
|
|
2010-10-23 08:15:39 +00:00
|
|
|
inline u32 GetFrameKey(int fbp, int fbw);
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-05-01 22:54:23 +00:00
|
|
|
// manages render targets
|
|
|
|
class CRenderTargetMngr
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
public:
|
|
|
|
typedef map<u32, CRenderTarget*> MAPTARGETS;
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-05-01 22:54:23 +00:00
|
|
|
enum TargetOptions
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
TO_DepthBuffer = 1,
|
|
|
|
TO_StrictHeight = 2, // height returned has to be the same as requested
|
|
|
|
TO_Virtual = 4
|
|
|
|
};
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
~CRenderTargetMngr() { Destroy(); }
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
void Destroy();
|
|
|
|
static MAPTARGETS::iterator GetOldestTarg(MAPTARGETS& m);
|
2010-09-25 08:57:44 +00:00
|
|
|
|
|
|
|
bool isFound(const frameInfo& frame, MAPTARGETS::iterator& it, u32 opts, u32 key, int maxposheight);
|
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
CRenderTarget* GetTarg(const frameInfo& frame, u32 Options, int maxposheight);
|
2010-10-23 08:15:39 +00:00
|
|
|
inline CRenderTarget* GetTarg(int fbp, int fbw)
|
2010-05-01 22:54:23 +00:00
|
|
|
{
|
2010-10-23 08:15:39 +00:00
|
|
|
MAPTARGETS::iterator it = mapTargets.find(GetFrameKey(fbp, fbw));
|
2010-05-01 22:54:23 +00:00
|
|
|
|
|
|
|
/* if (fbp == 0x3600 && fbw == 0x100 && it == mapTargets.end())
|
|
|
|
{
|
2010-10-23 08:15:39 +00:00
|
|
|
ZZLog::Debug_Log("%x", GetFrameKey(fbp, fbw)) ;
|
2010-10-16 11:10:48 +00:00
|
|
|
ZZLog::Debug_Log("%x %x", fbp, fbw);
|
2010-05-01 22:54:23 +00:00
|
|
|
for(MAPTARGETS::iterator it1 = mapTargets.begin(); it1 != mapTargets.end(); ++it1)
|
2010-10-16 11:10:48 +00:00
|
|
|
ZZLog::Debug_Log("\t %x %x %x %x", it1->second->fbw, it1->second->fbh, it1->second->psm, it1->second->fbp);
|
2010-05-01 22:54:23 +00:00
|
|
|
}*/
|
2010-03-19 00:31:15 +00:00
|
|
|
return it != mapTargets.end() ? it->second : NULL;
|
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
// gets all targets with a range
|
2010-10-16 11:54:46 +00:00
|
|
|
void GetTargs(int start, int end, list<CRenderTarget*>& listTargets) const;
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
// resolves all targets within a range
|
|
|
|
__forceinline void Resolve(int start, int end);
|
2010-05-01 22:54:23 +00:00
|
|
|
__forceinline void ResolveAll()
|
|
|
|
{
|
|
|
|
for (MAPTARGETS::iterator it = mapTargets.begin(); it != mapTargets.end(); ++it)
|
2010-03-19 00:31:15 +00:00
|
|
|
it->second->Resolve();
|
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
void DestroyAllTargs(int start, int end, int fbw);
|
|
|
|
void DestroyIntersecting(CRenderTarget* prndr);
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
// promotes a target from virtual to real
|
2010-05-01 22:54:23 +00:00
|
|
|
inline CRenderTarget* Promote(u32 key)
|
|
|
|
{
|
|
|
|
assert(!(key & TARGET_VIRTUAL_KEY));
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
// promote to regular targ
|
2010-05-01 22:54:23 +00:00
|
|
|
CRenderTargetMngr::MAPTARGETS::iterator it = mapTargets.find(key | TARGET_VIRTUAL_KEY);
|
|
|
|
assert(it != mapTargets.end());
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
CRenderTarget* ptarg = it->second;
|
|
|
|
mapTargets.erase(it);
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
DestroyIntersecting(ptarg);
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
it = mapTargets.find(key);
|
2010-05-01 22:54:23 +00:00
|
|
|
|
|
|
|
if (it != mapTargets.end())
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
DestroyTarg(it->second);
|
|
|
|
it->second = ptarg;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
mapTargets[key] = ptarg;
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-06-19 08:46:40 +00:00
|
|
|
if (conf.settings().resolve_promoted)
|
2010-05-01 22:54:23 +00:00
|
|
|
ptarg->status = CRenderTarget::TS_Resolved;
|
|
|
|
else
|
|
|
|
ptarg->status = CRenderTarget::TS_NeedUpdate;
|
|
|
|
|
|
|
|
return ptarg;
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2012-04-19 21:22:08 +00:00
|
|
|
void DestroyTarg(CRenderTarget* ptarg);
|
2010-06-15 10:32:22 +00:00
|
|
|
void PrintTargets();
|
2010-03-19 00:31:15 +00:00
|
|
|
MAPTARGETS mapTargets, mapDummyTargs;
|
2012-04-19 21:22:08 +00:00
|
|
|
private:
|
|
|
|
|
|
|
|
void DestroyAllTargetsHelper(void* ptr);
|
2010-05-01 22:54:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class CMemoryTargetMngr
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
public:
|
|
|
|
CMemoryTargetMngr() : curstamp(0) {}
|
2010-05-01 22:54:23 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
CMemoryTarget* GetMemoryTarget(const tex0Info& tex0, int forcevalidate); // pcbp is pointer to start of clut
|
2010-10-18 17:39:12 +00:00
|
|
|
CMemoryTarget* SearchExistTarget(int start, int end, int clutsize, const tex0Info& tex0, int forcevalidate);
|
2013-06-28 10:43:50 +00:00
|
|
|
CMemoryTarget* ClearedTargetsSearch(u32 fmt, int widthmult, int channels, int height);
|
2010-10-18 17:39:12 +00:00
|
|
|
int CompareTarget(list<CMemoryTarget>::iterator& it, const tex0Info& tex0, int clutsize);
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
void Destroy(); // destroy all targs
|
|
|
|
|
|
|
|
void ClearRange(int starty, int endy); // set all targets to cleared
|
|
|
|
void DestroyCleared(); // flush all cleared targes
|
|
|
|
void DestroyOldest();
|
2010-05-01 22:54:23 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
list<CMemoryTarget> listTargets, listClearedTargets;
|
|
|
|
u32 curstamp;
|
|
|
|
|
|
|
|
private:
|
|
|
|
list<CMemoryTarget>::iterator DestroyTargetIter(list<CMemoryTarget>::iterator& it);
|
2010-10-18 17:39:12 +00:00
|
|
|
void GetClutVariables(int& clutsize, const tex0Info& tex0);
|
2010-09-25 13:33:58 +00:00
|
|
|
void GetMemAddress(int& start, int& end, const tex0Info& tex0);
|
2010-05-01 22:54:23 +00:00
|
|
|
};
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-05-01 22:54:23 +00:00
|
|
|
class CBitwiseTextureMngr
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
public:
|
|
|
|
~CBitwiseTextureMngr() { Destroy(); }
|
|
|
|
|
|
|
|
void Destroy();
|
|
|
|
|
|
|
|
// since GetTex can delete textures to free up mem, it is dangerous if using that texture, so specify at least one other tex to save
|
2010-05-01 22:54:23 +00:00
|
|
|
__forceinline u32 GetTex(u32 bitvalue, u32 ptexDoNotDelete)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
map<u32, u32>::iterator it = mapTextures.find(bitvalue);
|
2010-05-01 22:54:23 +00:00
|
|
|
|
|
|
|
if (it != mapTextures.end()) return it->second;
|
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
return GetTexInt(bitvalue, ptexDoNotDelete);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
u32 GetTexInt(u32 bitvalue, u32 ptexDoNotDelete);
|
|
|
|
|
|
|
|
map<u32, u32> mapTextures;
|
2010-05-01 22:54:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// manages
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-05-01 22:54:23 +00:00
|
|
|
class CRangeManager
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
public:
|
2010-05-01 22:54:23 +00:00
|
|
|
CRangeManager()
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
ranges.reserve(16);
|
|
|
|
}
|
|
|
|
|
|
|
|
// [start, end)
|
2010-05-01 22:54:23 +00:00
|
|
|
|
|
|
|
struct RANGE
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
RANGE() {}
|
2010-05-01 22:54:23 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
inline RANGE(int start, int end) : start(start), end(end) {}
|
2010-05-01 22:54:23 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
int start, end;
|
|
|
|
};
|
|
|
|
|
|
|
|
// works in semi logN
|
|
|
|
void Insert(int start, int end);
|
2010-04-25 07:21:29 +00:00
|
|
|
void RangeSanityCheck();
|
2010-05-01 22:54:23 +00:00
|
|
|
inline void Clear()
|
|
|
|
{
|
2010-04-25 00:31:27 +00:00
|
|
|
ranges.resize(0);
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
vector<RANGE> ranges; // organized in ascending order, non-intersecting
|
2010-05-01 22:54:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
extern CRenderTargetMngr s_RTs, s_DepthRTs;
|
|
|
|
extern CBitwiseTextureMngr s_BitwiseTextures;
|
|
|
|
extern CMemoryTargetMngr g_MemTargs;
|
2010-10-23 04:14:19 +00:00
|
|
|
extern CRangeManager s_RangeMngr; // manages overwritten memory
|
2010-05-01 22:54:23 +00:00
|
|
|
|
2010-09-15 16:54:19 +00:00
|
|
|
//extern u8 s_AAx, s_AAy;
|
|
|
|
extern Point AA;
|
2010-05-01 22:54:23 +00:00
|
|
|
|
2010-09-15 16:54:19 +00:00
|
|
|
// Real rendered width, depends on AA.
|
2010-05-01 22:54:23 +00:00
|
|
|
inline int RW(int tbw)
|
|
|
|
{
|
2010-09-15 16:54:19 +00:00
|
|
|
return (tbw << AA.x);
|
2010-05-01 22:54:23 +00:00
|
|
|
}
|
|
|
|
|
2010-09-15 16:54:19 +00:00
|
|
|
// Real rendered height, depends on AA.
|
2010-05-01 22:54:23 +00:00
|
|
|
inline int RH(int tbh)
|
|
|
|
{
|
2010-09-15 16:54:19 +00:00
|
|
|
return (tbh << AA.y);
|
2010-05-01 22:54:23 +00:00
|
|
|
}
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-10-16 11:54:46 +00:00
|
|
|
/* inline void CreateTargetsList(int start, int end, list<CRenderTarget*>& listTargs) {
|
2010-03-19 00:31:15 +00:00
|
|
|
s_DepthRTs.GetTargs(start, end, listTargs);
|
|
|
|
s_RTs.GetTargs(start, end, listTargs);
|
|
|
|
}*/
|
|
|
|
|
2010-05-01 22:54:23 +00:00
|
|
|
// This pattern of functions is called 3 times, so I add creating Targets list into one.
|
2010-10-16 11:54:46 +00:00
|
|
|
inline list<CRenderTarget*> CreateTargetsList(int start, int end)
|
2010-05-01 22:54:23 +00:00
|
|
|
{
|
2010-10-16 11:54:46 +00:00
|
|
|
list<CRenderTarget*> listTargs;
|
2010-05-01 22:54:23 +00:00
|
|
|
s_DepthRTs.GetTargs(start, end, listTargs);
|
|
|
|
s_RTs.GetTargs(start, end, listTargs);
|
|
|
|
return listTargs;
|
|
|
|
}
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-05-01 22:54:23 +00:00
|
|
|
extern int icurctx;
|
|
|
|
extern GLuint vboRect;
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
// Unworking
|
|
|
|
#define PSMPOSITION 28
|
|
|
|
|
|
|
|
// Code width and height of frame into key, that used in targetmanager
|
|
|
|
// This is 3 variants of one function, Key dependant on fbp and fbw.
|
2010-05-01 22:54:23 +00:00
|
|
|
inline u32 GetFrameKey(const frameInfo& frame)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
return (((frame.fbw) << 16) | (frame.fbp));
|
|
|
|
}
|
2010-05-01 22:54:23 +00:00
|
|
|
|
|
|
|
inline u32 GetFrameKey(CRenderTarget* frame)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
return (((frame->fbw) << 16) | (frame->fbp));
|
|
|
|
}
|
|
|
|
|
2010-10-23 08:15:39 +00:00
|
|
|
inline u32 GetFrameKey(int fbp, int fbw)
|
2010-05-01 22:54:23 +00:00
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
return (((fbw) << 16) | (fbp));
|
|
|
|
}
|
|
|
|
|
2010-05-01 22:54:23 +00:00
|
|
|
inline u16 ShiftHeight(int fbh, int fbp, int fbhCalc)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
return fbh;
|
2010-04-25 00:31:27 +00:00
|
|
|
}
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-06-15 10:32:22 +00:00
|
|
|
//#define FRAME_KEY_BY_FBH
|
|
|
|
|
2010-05-01 22:54:23 +00:00
|
|
|
//FIXME: this code is for P4 and KH1. It should not be so strange!
|
2010-03-19 00:31:15 +00:00
|
|
|
//Dummy targets was deleted from mapTargets, but not erased.
|
2010-06-15 10:32:22 +00:00
|
|
|
inline u32 GetFrameKeyDummy(int fbp, int fbw, int fbh, int psm)
|
2010-05-01 22:54:23 +00:00
|
|
|
{
|
2010-06-15 10:32:22 +00:00
|
|
|
// if (fbp > 0x2000 && ZZOgl_fbh_Calc(fbp, fbw, psm) < 0x400 && ZZOgl_fbh_Calc(fbp, fbw, psm) != fbh)
|
|
|
|
// ZZLog::Debug_Log("Z %x %x %x %x\n", fbh, fbhCalc, fbp, ZZOgl_fbh_Calc(fbp, fbw, psm));
|
2010-04-25 00:31:27 +00:00
|
|
|
// height over 1024 would shrink to 1024, so dummy targets with calculated size more than 0x400 should be
|
2010-06-15 10:32:22 +00:00
|
|
|
// distinct by real height. But in FFX there is 3e0 height target, so I put 0x300 as limit.
|
|
|
|
|
|
|
|
#ifndef FRAME_KEY_BY_FBH
|
|
|
|
int calc = ZZOgl_fbh_Calc(fbp, fbw, psm);
|
2010-06-19 22:32:53 +00:00
|
|
|
if (/*fbp > 0x2000 && */calc < /*0x300*/0x2E0)
|
2010-06-15 10:32:22 +00:00
|
|
|
return ((fbw << 16) | calc);
|
2010-03-19 00:31:15 +00:00
|
|
|
else
|
2010-06-15 10:32:22 +00:00
|
|
|
#endif
|
|
|
|
return ((fbw << 16) | fbh);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline u32 GetFrameKeyDummy(const frameInfo& frame)
|
|
|
|
{
|
|
|
|
return GetFrameKeyDummy(frame.fbp, frame.fbw, frame.fbh, frame.psm);
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
|
|
|
|
2010-05-01 22:54:23 +00:00
|
|
|
inline u32 GetFrameKeyDummy(CRenderTarget* frame)
|
|
|
|
{
|
2010-06-15 10:32:22 +00:00
|
|
|
return GetFrameKeyDummy(frame->fbp, frame->fbw, frame->fbh, frame->psm);
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
|
|
|
|
2010-10-17 08:47:31 +00:00
|
|
|
//------------------------ Inlines -------------------------
|
|
|
|
|
|
|
|
// Calculate maximum height for target
|
|
|
|
inline int get_maxheight(int fbp, int fbw, int psm)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (fbw == 0) return 0;
|
|
|
|
|
|
|
|
ret = (((0x00100000 - 64 * fbp) / fbw) & ~0x1f);
|
|
|
|
if (PSMT_ISHALF(psm)) ret *= 2;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-04-19 21:22:08 +00:00
|
|
|
// memory size for one row of texture. It depends on width of texture and number of bytes
|
|
|
|
// per pixel
|
|
|
|
inline u32 Pitch(int fbw) { return (RW(fbw) * 4) ; }
|
|
|
|
|
|
|
|
// memory size of whole texture. It is number of rows multiplied by memory size of row
|
|
|
|
inline u32 Tex_Memory_Size(int fbw, int fbh) { return (RH(fbh) * Pitch(fbw)); }
|
|
|
|
|
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
#endif
|