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__H
|
|
|
|
#define __ZEROGS__H
|
|
|
|
|
2010-04-03 12:48:27 +00:00
|
|
|
#ifdef _MSC_VER
|
2010-03-19 00:31:15 +00:00
|
|
|
#pragma warning(disable:4200) // nonstandard extension used : zero-sized array in struct/union
|
2010-04-03 12:48:27 +00:00
|
|
|
#endif
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
// ----------------------------- Includes
|
|
|
|
#include <list>
|
|
|
|
#include <vector>
|
|
|
|
#include <map>
|
|
|
|
#include <string>
|
2010-09-20 13:03:40 +00:00
|
|
|
#include <math.h>
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-07-03 06:16:28 +00:00
|
|
|
#include "ZZGl.h"
|
2010-03-19 00:31:15 +00:00
|
|
|
#include "GS.h"
|
2010-06-11 11:48:07 +00:00
|
|
|
#include "CRC.h"
|
2010-03-19 00:31:15 +00:00
|
|
|
#include "rasterfont.h" // simple font
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
//------------------------ Constants ----------------------
|
|
|
|
#define VB_BUFFERSIZE 0x400
|
|
|
|
|
2010-07-03 06:34:27 +00:00
|
|
|
// Used in a logarithmic Z-test, as (1-o(1))/log(MAX_U32).
|
2010-04-25 00:31:27 +00:00
|
|
|
const float g_filog32 = 0.999f / (32.0f * logf(2.0f));
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
//------------------------ Inlines -------------------------
|
|
|
|
|
2010-03-19 04:36:28 +00:00
|
|
|
// Calculate maximum height for target
|
2010-05-01 22:54:23 +00:00
|
|
|
inline int get_maxheight(int fbp, int fbw, int psm)
|
2010-03-19 04:36:28 +00:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
if (fbw == 0) return 0;
|
2010-05-01 22:54:23 +00:00
|
|
|
|
2010-06-11 11:48:07 +00:00
|
|
|
ret = (((0x00100000 - 64 * fbp) / fbw) & ~0x1f);
|
|
|
|
if (PSMT_ISHALF(psm)) ret *= 2;
|
2010-03-19 04:36:28 +00:00
|
|
|
|
|
|
|
return ret;
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------ Variables -------------------------
|
2010-09-15 16:54:19 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
// all textures have this width
|
|
|
|
extern int GPU_TEXWIDTH;
|
|
|
|
extern float g_fiGPU_TEXWIDTH;
|
2010-09-15 16:54:19 +00:00
|
|
|
#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-03-19 00:31:15 +00:00
|
|
|
|
2010-09-19 08:01:48 +00:00
|
|
|
extern u32 ptexBlocks; // holds information on block tiling. It's texture number in OpenGL -- if 0 than such texture
|
|
|
|
extern u32 ptexConv16to32; // does not exists. This textures should be created on start and released on finish.
|
2010-03-19 00:31:15 +00:00
|
|
|
extern u32 ptexBilinearBlocks;
|
2010-09-19 08:01:48 +00:00
|
|
|
extern u32 ptexConv32to16;
|
2010-07-03 07:57:56 +00:00
|
|
|
|
|
|
|
// this is currently *not* used as a bool, in spite of its moniker --air
|
|
|
|
// Actually, the only thing written to it is 1 or 0, which makes the (g_bSaveFlushedFrame & 0x80000000) check rather bizzare.
|
2010-07-04 03:53:01 +00:00
|
|
|
//extern u32 g_bSaveFlushedFrame;
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
//////////////////////////
|
|
|
|
// State parameters
|
2010-07-03 07:57:56 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-07-16 03:48:13 +00:00
|
|
|
#ifdef ZEROGS_DEVBUILD
|
2010-03-19 00:31:15 +00:00
|
|
|
extern char* EFFECT_NAME;
|
|
|
|
extern char* EFFECT_DIR;
|
|
|
|
extern u32 g_nGenVars, g_nTexVars, g_nAlphaVars, g_nResolve;
|
|
|
|
extern bool g_bSaveTrans, g_bUpdateEffect, g_bSaveTex, g_bSaveResolved;
|
2010-04-25 00:31:27 +00:00
|
|
|
#endif
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
extern u32 s_uFramebuffer;
|
|
|
|
extern int g_nPixelShaderVer;
|
2010-07-03 07:57:56 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
extern bool s_bWriteDepth;
|
|
|
|
|
|
|
|
extern u32 ptexLogo;
|
|
|
|
extern int nLogoWidth, nLogoHeight;
|
|
|
|
extern int nBackbufferWidth, nBackbufferHeight;
|
2010-07-03 07:57:56 +00:00
|
|
|
|
2010-05-01 22:54:23 +00:00
|
|
|
typedef void (*DrawFn)();
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-05-01 22:54:23 +00:00
|
|
|
// managers render-to-texture targets
|
|
|
|
|
|
|
|
class CRenderTarget
|
|
|
|
{
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
public:
|
|
|
|
CRenderTarget();
|
|
|
|
virtual ~CRenderTarget();
|
|
|
|
|
|
|
|
virtual bool Create(const frameInfo& frame);
|
|
|
|
virtual void Destroy();
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
// set the GPU_POSXY variable, scissor rect, and current render target
|
|
|
|
void SetTarget(int fbplocal, const Rect2& scissor, int context);
|
|
|
|
void SetViewport();
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
// copies/creates the feedback contents
|
2010-05-01 22:54:23 +00:00
|
|
|
inline void CreateFeedback()
|
|
|
|
{
|
|
|
|
if (ptexFeedback == 0 || !(status&TS_FeedbackReady))
|
2010-03-19 00:31:15 +00:00
|
|
|
_CreateFeedback();
|
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
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
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
virtual bool IsDepth() { return false; }
|
2010-05-01 22:54:23 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
void SetRenderTarget(int targ);
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
void* psys; // system data used for comparison
|
|
|
|
u32 ptex;
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
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
|
2010-09-19 08:01:48 +00:00
|
|
|
float4 vposxy;
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
u32 fbm;
|
|
|
|
u16 status;
|
|
|
|
u8 psm;
|
|
|
|
u8 resv0;
|
|
|
|
Rect scissorrect;
|
|
|
|
|
2010-04-25 00:31:27 +00:00
|
|
|
u8 created; // Check for object destruction/creating for r201.
|
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
//int startresolve, endresolve;
|
|
|
|
u32 nUpdateTarg; // use this target to update the texture if non 0 (one time only)
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
// this is optionally used when feedback effects are used (render target is used as a texture when rendering to itself)
|
|
|
|
u32 ptexFeedback;
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-05-01 22:54:23 +00:00
|
|
|
enum TargetStatus
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
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,
|
|
|
|
TS_NeedConvert16 = 32,
|
|
|
|
};
|
2010-09-19 08:01:48 +00:00
|
|
|
inline float4 DefaultBitBltPos();
|
|
|
|
inline float4 DefaultBitBltTex();
|
2010-05-01 22:54:23 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
private:
|
|
|
|
void _CreateFeedback();
|
2010-05-01 22:54:23 +00:00
|
|
|
inline bool InitialiseDefaultTexture(u32 *p_ptr, int fbw, int fbh) ;
|
|
|
|
};
|
|
|
|
|
|
|
|
// manages zbuffers
|
|
|
|
|
|
|
|
class CDepthTarget : public CRenderTarget
|
|
|
|
{
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
public:
|
|
|
|
CDepthTarget();
|
|
|
|
virtual ~CDepthTarget();
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
virtual bool Create(const frameInfo& frame);
|
|
|
|
virtual void Destroy();
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
virtual void Resolve();
|
|
|
|
virtual void Resolve(int startrange, int endrange); // resolves only in the allowed range
|
|
|
|
virtual void Update(int context, CRenderTarget* prndr);
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
virtual bool IsDepth() { return true; }
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
void SetDepthStencilSurface();
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
u32 pdepth; // 24 bit, will contain the stencil buffer if possible
|
|
|
|
u32 pstencil; // if not 0, contains the stencil buffer
|
|
|
|
int icount; // internal counter
|
2010-05-01 22:54:23 +00:00
|
|
|
};
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-05-01 22:54:23 +00:00
|
|
|
// manages contiguous chunks of memory (width is always 1024)
|
|
|
|
|
|
|
|
class CMemoryTarget
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
public:
|
|
|
|
struct TEXTURE
|
|
|
|
{
|
|
|
|
inline TEXTURE() : tex(0), memptr(NULL), ref(0) {}
|
|
|
|
inline ~TEXTURE() { glDeleteTextures(1, &tex); _aligned_free(memptr); }
|
2010-05-01 22:54:23 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
u32 tex;
|
2010-04-25 00:31:27 +00:00
|
|
|
u8* memptr; // GPU memory used for comparison
|
2010-03-19 00:31:15 +00:00
|
|
|
int ref;
|
|
|
|
};
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-03-19 00:31: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) {}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-05-01 22:54:23 +00:00
|
|
|
inline CMemoryTarget(const CMemoryTarget& r)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
ptex = r.ptex;
|
2010-05-01 22:54:23 +00:00
|
|
|
|
|
|
|
if (ptex != NULL) ptex->ref++;
|
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
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;
|
2010-09-20 10:09:46 +00:00
|
|
|
texH = r.texH;
|
|
|
|
texW = r.texW;
|
2010-03-19 00:31:15 +00:00
|
|
|
channels = r.channels;
|
|
|
|
validatecount = r.validatecount;
|
|
|
|
fmt = r.fmt;
|
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
~CMemoryTarget() { Destroy(); }
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-05-01 22:54:23 +00:00
|
|
|
inline void Destroy()
|
|
|
|
{
|
|
|
|
if (ptex != NULL && ptex->ref > 0)
|
|
|
|
{
|
|
|
|
if (--ptex->ref <= 0) delete ptex;
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
ptex = NULL;
|
2010-05-01 22:54:23 +00:00
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-03-19 00:31:15 +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);
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
// 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
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
int starty, height; // assert(starty >= realy)
|
|
|
|
int realy, realheight; // this is never touched once allocated
|
2010-09-20 10:09:46 +00:00
|
|
|
// realy is start pointer of data in 4M data block (start) and size (end-start).
|
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
u32 usedstamp;
|
|
|
|
u8 psm, cpsm; // texture and clut format. For psm, only 16bit/32bit differentiation matters
|
|
|
|
|
|
|
|
u32 fmt;
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-09-20 10:09:46 +00:00
|
|
|
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
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
int validatecount; // count how many times has been validated, if too many, destroy
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
vector<u8> clut; // if nonzero, texture uses CLUT
|
2010-05-01 22:54:23 +00:00
|
|
|
};
|
2010-04-25 00:31:27 +00:00
|
|
|
|
|
|
|
|
2010-05-01 22:54:23 +00:00
|
|
|
struct VB
|
|
|
|
{
|
|
|
|
VB();
|
|
|
|
~VB();
|
|
|
|
|
|
|
|
void Destroy();
|
|
|
|
|
|
|
|
inline bool CheckPrim()
|
2010-03-19 00:31:15 +00:00
|
|
|
{
|
2010-05-01 22:54:23 +00:00
|
|
|
static const int PRIMMASK = 0x0e; // for now ignore 0x10 (AA)
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-05-01 22:54:23 +00:00
|
|
|
if ((PRIMMASK & prim->_val) != (PRIMMASK & curprim._val) || primtype[prim->prim] != primtype[curprim.prim])
|
|
|
|
return nCount > 0;
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-05-01 22:54:23 +00:00
|
|
|
return false;
|
|
|
|
}
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-05-01 22:54:23 +00:00
|
|
|
void CheckFrame(int tbp);
|
|
|
|
|
|
|
|
// context specific state
|
|
|
|
Point offset;
|
|
|
|
Rect2 scissor;
|
|
|
|
tex0Info tex0;
|
|
|
|
tex1Info tex1;
|
|
|
|
miptbpInfo miptbp0;
|
|
|
|
miptbpInfo miptbp1;
|
|
|
|
alphaInfo alpha;
|
|
|
|
fbaInfo fba;
|
|
|
|
clampInfo clamp;
|
|
|
|
pixTest test;
|
|
|
|
u32 ptexClamp[2]; // textures for x and y dir region clamping
|
|
|
|
|
|
|
|
public:
|
|
|
|
void FlushTexData();
|
|
|
|
inline int CheckFrameAddConstraints(int tbp);
|
|
|
|
inline void CheckScissors(int maxpos);
|
|
|
|
inline void CheckFrame32bitRes(int maxpos);
|
|
|
|
inline int FindMinimalMemoryConstrain(int tbp, int maxpos);
|
|
|
|
inline int FindZbufferMemoryConstrain(int tbp, int maxpos);
|
|
|
|
inline int FindMinimalHeightConstrain(int maxpos);
|
|
|
|
|
|
|
|
inline int CheckFrameResolveRender(int tbp);
|
|
|
|
inline void CheckFrame16vs32Conversion();
|
|
|
|
inline int CheckFrameResolveDepth(int tbp);
|
|
|
|
|
|
|
|
inline void FlushTexUnchangedClutDontUpdate() ;
|
|
|
|
inline void FlushTexClutDontUpdate() ;
|
|
|
|
inline void FlushTexClutting() ;
|
|
|
|
inline void FlushTexSetNewVars(u32 psm) ;
|
|
|
|
|
|
|
|
// notify VB that nVerts need to be written to pbuf
|
|
|
|
inline void NotifyWrite(int nVerts)
|
|
|
|
{
|
|
|
|
assert(pBufferData != NULL && nCount <= nNumVertices && nVerts > 0);
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-05-01 22:54:23 +00:00
|
|
|
if (nCount + nVerts > nNumVertices)
|
|
|
|
{
|
|
|
|
// recreate except with a bigger count
|
|
|
|
VertexGPU* ptemp = (VertexGPU*)_aligned_malloc(sizeof(VertexGPU) * nNumVertices * 2, 256);
|
|
|
|
memcpy_amd(ptemp, pBufferData, sizeof(VertexGPU) * nCount);
|
|
|
|
nNumVertices *= 2;
|
|
|
|
assert(nCount + nVerts <= nNumVertices);
|
|
|
|
_aligned_free(pBufferData);
|
|
|
|
pBufferData = ptemp;
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
2010-05-01 22:54:23 +00:00
|
|
|
}
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-05-01 22:54:23 +00:00
|
|
|
void Init(int nVerts)
|
|
|
|
{
|
|
|
|
if (pBufferData == NULL && nVerts > 0)
|
|
|
|
{
|
|
|
|
pBufferData = (VertexGPU*)_aligned_malloc(sizeof(VertexGPU) * nVerts, 256);
|
|
|
|
nNumVertices = nVerts;
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
|
|
|
|
2010-05-01 22:54:23 +00:00
|
|
|
nCount = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
u8 bNeedFrameCheck;
|
|
|
|
u8 bNeedZCheck;
|
|
|
|
u8 bNeedTexCheck;
|
|
|
|
u8 dummy0;
|
|
|
|
|
|
|
|
union
|
|
|
|
{
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
u8 bTexConstsSync; // only pixel shader constants that context owns
|
|
|
|
u8 bVarsTexSync; // texture info
|
|
|
|
u8 bVarsSetTarg;
|
|
|
|
u8 dummy1;
|
2010-03-19 00:31:15 +00:00
|
|
|
};
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-05-01 22:54:23 +00:00
|
|
|
u32 bSyncVars;
|
|
|
|
};
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-05-01 22:54:23 +00:00
|
|
|
int ictx;
|
|
|
|
VertexGPU* pBufferData; // current allocated data
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-05-01 22:54:23 +00:00
|
|
|
int nNumVertices; // size of pBufferData in terms of VertexGPU objects
|
|
|
|
int nCount;
|
|
|
|
primInfo curprim; // the previous prim the current buffers are set to
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-05-01 22:54:23 +00:00
|
|
|
zbufInfo zbuf;
|
|
|
|
frameInfo gsfb; // the real info set by FRAME cmd
|
|
|
|
frameInfo frame;
|
|
|
|
int zprimmask; // zmask for incoming points
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-07-10 06:04:32 +00:00
|
|
|
union
|
|
|
|
{
|
2010-05-01 22:54:23 +00:00
|
|
|
u32 uCurTex0Data[2]; // current tex0 data
|
2010-07-10 06:04:32 +00:00
|
|
|
GIFRegTEX0 uCurTex0;
|
|
|
|
};
|
2010-05-01 22:54:23 +00:00
|
|
|
u32 uNextTex0Data[2]; // tex0 data that has to be applied if bNeedTexCheck is 1
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-05-01 22:54:23 +00:00
|
|
|
//int nFrameHeights[8]; // frame heights for the past frame changes
|
|
|
|
int nNextFrameHeight;
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-05-01 22:54:23 +00:00
|
|
|
CMemoryTarget* pmemtarg; // the current mem target set
|
|
|
|
CRenderTarget* prndr;
|
|
|
|
CDepthTarget* pdepth;
|
2010-08-17 13:38:57 +00:00
|
|
|
|
2010-05-01 22:54:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// visible members
|
|
|
|
extern DrawFn drawfn[8];
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-05-01 22:54:23 +00:00
|
|
|
// VB variables
|
|
|
|
extern VB vb[2];
|
|
|
|
extern float fiTexWidth[2], fiTexHeight[2]; // current tex width and height
|
|
|
|
extern vector<GLuint> g_vboBuffers; // VBOs for all drawing commands
|
|
|
|
extern GLuint vboRect;
|
|
|
|
extern int g_nCurVBOIndex;
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-10-16 11:54:46 +00:00
|
|
|
void ZZAddMessage(const char* pstr, u32 ms = 5000);
|
2010-05-01 22:54:23 +00:00
|
|
|
void DrawText(const char* pstr, int left, int top, u32 color);
|
|
|
|
void ChangeWindowSize(int nNewWidth, int nNewHeight);
|
|
|
|
void SetChangeDeviceSize(int nNewWidth, int nNewHeight);
|
|
|
|
void ChangeDeviceSize(int nNewWidth, int nNewHeight);
|
|
|
|
void SetAA(int mode);
|
|
|
|
void SetCRC(int crc);
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-05-01 22:54:23 +00:00
|
|
|
void ReloadEffects();
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-05-01 22:54:23 +00:00
|
|
|
// Methods //
|
|
|
|
bool IsGLExt(const char* szTargetExtension); ///< returns true if the the opengl extension is supported
|
|
|
|
inline bool Create_Window(int _width, int _height);
|
2010-10-16 11:54:46 +00:00
|
|
|
bool ZZCreate(int width, int height);
|
|
|
|
void ZZDestroy(bool bD3D);
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-10-16 11:54:46 +00:00
|
|
|
void ZZReset(); // call to destroy video resources
|
|
|
|
void ZZGSStateReset();
|
|
|
|
void ZZGSReset();
|
|
|
|
void ZZGSSoftReset(u32 mask);
|
2010-07-02 12:10:40 +00:00
|
|
|
|
2010-05-01 22:54:23 +00:00
|
|
|
void HandleGLError();
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-05-01 22:54:23 +00:00
|
|
|
// called on a primitive switch
|
|
|
|
void Prim();
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-05-01 22:54:23 +00:00
|
|
|
void SetTexFlush();
|
|
|
|
// flush current vertices, call before setting new registers (the main render method)
|
|
|
|
void Flush(int context);
|
2010-06-19 05:41:06 +00:00
|
|
|
void FlushBoth();
|
2010-05-01 22:54:23 +00:00
|
|
|
void ExtWrite();
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-05-01 22:54:23 +00:00
|
|
|
void SetWriteDepth();
|
|
|
|
bool IsWriteDepth();
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-05-01 22:54:23 +00:00
|
|
|
void SetDestAlphaTest();
|
|
|
|
bool IsWriteDestAlphaTest();
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-05-01 22:54:23 +00:00
|
|
|
void SetFogColor(u32 fog);
|
2010-07-09 09:26:35 +00:00
|
|
|
void SetFogColor(GIFRegFOGCOL* fog);
|
2010-05-01 22:54:23 +00:00
|
|
|
void SaveTex(tex0Info* ptex, int usevid);
|
|
|
|
char* NamedSaveTex(tex0Info* ptex, int usevid);
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-05-01 22:54:23 +00:00
|
|
|
// called when trxdir is accessed. If host is involved, transfers memory to temp buffer byTransferBuf.
|
|
|
|
// Otherwise performs the transfer. TODO: Perhaps divide the transfers into chunks?
|
|
|
|
void InitTransferHostLocal();
|
|
|
|
void TransferHostLocal(const void* pbyMem, u32 nQWordSize);
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-05-01 22:54:23 +00:00
|
|
|
void InitTransferLocalHost();
|
|
|
|
void TransferLocalHost(void* pbyMem, u32 nQWordSize);
|
|
|
|
inline void TerminateLocalHost() {}
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-05-01 22:54:23 +00:00
|
|
|
void TransferLocalLocal();
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-05-01 22:54:23 +00:00
|
|
|
// switches the render target to the real target, flushes the current render targets and renders the real image
|
|
|
|
void RenderCRTC(int interlace);
|
|
|
|
void ResetRenderTarget(int index);
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-05-01 22:54:23 +00:00
|
|
|
bool CheckChangeInClut(u32 highdword, u32 psm); // returns true if clut will change after this tex0 op
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-05-01 22:54:23 +00:00
|
|
|
// call to load CLUT data (depending on CLD)
|
|
|
|
void texClutWrite(int ctx);
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-10-16 11:54:46 +00:00
|
|
|
int ZZSave(s8* pbydata);
|
|
|
|
bool ZZLoad(s8* pbydata);
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-05-01 22:54:23 +00:00
|
|
|
void SaveSnapshot(const char* filename);
|
|
|
|
bool SaveRenderTarget(const char* filename, int width, int height, int jpeg);
|
|
|
|
bool SaveTexture(const char* filename, u32 textarget, u32 tex, int width, int height);
|
|
|
|
bool SaveJPEG(const char* filename, int width, int height, const void* pdata, int quality);
|
|
|
|
bool SaveTGA(const char* filename, int width, int height, void* pdata);
|
|
|
|
void Stop_Avi();
|
2010-07-03 07:57:56 +00:00
|
|
|
void Delete_Avi_Capture();
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-05-01 22:54:23 +00:00
|
|
|
// private methods
|
|
|
|
void FlushSysMem(const RECT* prc);
|
|
|
|
void _Resolve(const void* psrc, int fbp, int fbw, int fbh, int psm, u32 fbm, bool mode);
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-05-01 22:54:23 +00:00
|
|
|
// returns the first and last addresses aligned to a page that cover
|
|
|
|
void GetRectMemAddress(int& start, int& end, int psm, int x, int y, int w, int h, int bp, int bw);
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-05-01 22:54:23 +00:00
|
|
|
// inits the smallest rectangle in ptexMem that covers this region in ptexMem
|
|
|
|
// returns the offset that needs to be added to the locked rect to get the beginning of the buffer
|
|
|
|
//void GetMemRect(RECT& rc, int psm, int x, int y, int w, int h, int bp, int bw);
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-05-01 22:54:23 +00:00
|
|
|
void SetContextTarget(int context) ;
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-05-01 22:54:23 +00:00
|
|
|
void NeedFactor(int w);
|
|
|
|
void ResetAlphaVariables();
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-05-01 22:54:23 +00:00
|
|
|
void StartCapture();
|
|
|
|
void StopCapture();
|
|
|
|
void CaptureFrame();
|
|
|
|
|
|
|
|
// Perform clutting for flushed texture. Better check if it needs a prior call.
|
|
|
|
inline void CluttingForFlushedTex(tex0Info* tex0, u32 Data, int ictx)
|
|
|
|
{
|
|
|
|
tex0->cbp = ZZOglGet_cbp_TexBits(Data);
|
|
|
|
tex0->cpsm = ZZOglGet_cpsm_TexBits(Data);
|
|
|
|
tex0->csm = ZZOglGet_csm_TexBits(Data);
|
|
|
|
tex0->csa = ZZOglGet_csa_TexBits(Data);
|
|
|
|
tex0->cld = ZZOglGet_cld_TexBits(Data);
|
|
|
|
|
2010-10-16 11:54:46 +00:00
|
|
|
texClutWrite(ictx);
|
2010-09-20 10:09:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// The size in bytes of x strings (of texture).
|
|
|
|
inline int MemorySize(int x)
|
|
|
|
{
|
|
|
|
return 4 * GPU_TEXWIDTH * x;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return the address in memory of data block for string x.
|
|
|
|
inline u8* MemoryAddress(int x)
|
|
|
|
{
|
|
|
|
return g_pbyGSMemory + MemorySize(x);
|
2010-05-01 22:54:23 +00:00
|
|
|
}
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-09-20 10:09:46 +00:00
|
|
|
template <u32 mult>
|
|
|
|
inline u8* _MemoryAddress(int x)
|
|
|
|
{
|
|
|
|
return g_pbyGSMemory + mult * x;
|
|
|
|
}
|
2010-03-19 00:31:15 +00:00
|
|
|
#endif
|