2010-03-19 00:31:15 +00:00
|
|
|
/* ZZ Open GL graphics plugin
|
|
|
|
* Copyright (c)2009 zeydlitz@gmail.com
|
|
|
|
* Based on Zerofrog's ZeroGS KOSMOS (c)2005-2006
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Zerogs:VB implementation.
|
|
|
|
// VB stands for Visual Buffer, as I think
|
|
|
|
|
|
|
|
//------------------- Includes
|
|
|
|
#include "zerogs.h"
|
|
|
|
#include "targets.h"
|
|
|
|
#include "GS.h"
|
|
|
|
#include "Mem.h"
|
|
|
|
|
|
|
|
using namespace ZeroGS;
|
|
|
|
// ----------------- Defines
|
|
|
|
#define MINMAX_SHIFT 3
|
|
|
|
|
|
|
|
//------------------ Constants
|
|
|
|
|
2010-04-25 00:31:27 +00:00
|
|
|
// ----------------- Global Variables
|
2010-03-19 00:31:15 +00:00
|
|
|
int maxmin = 608;
|
|
|
|
// ----------------- Code
|
|
|
|
|
|
|
|
// Constructor. Set width and height to 1
|
|
|
|
ZeroGS::VB::VB()
|
|
|
|
{
|
|
|
|
memset(this, 0, sizeof(ZeroGS::VB));
|
|
|
|
tex0.tw = 1;
|
|
|
|
tex0.th = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Destructor
|
|
|
|
ZeroGS::VB::~VB()
|
|
|
|
{
|
|
|
|
Destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ZeroGS::VB::Destroy()
|
|
|
|
{
|
2010-05-01 20:33:53 +00:00
|
|
|
_aligned_free(pBufferData);
|
|
|
|
pBufferData = NULL;
|
|
|
|
nNumVertices = 0;
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
prndr = NULL;
|
|
|
|
pdepth = NULL;
|
|
|
|
}
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
int ConstraintReason;
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
// Return number of 64-pixels block, that guaranted could be hold in memory
|
2010-04-25 00:31:27 +00:00
|
|
|
// from gsfb.fbp and tbp (textrure pase), zbuf.zbp (Z-buffer), frame.fbp
|
|
|
|
// (previous frame).
|
2010-05-01 20:33:53 +00:00
|
|
|
inline int ZeroGS::VB::FindMinimalMemoryConstrain(int tbp, int maxpos)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
int MinConstraint = maxpos;
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
// make sure texture is far away from tbp
|
2010-04-25 00:31:27 +00:00
|
|
|
{
|
|
|
|
int Constraint = tbp - gsfb.fbp;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
|
|
|
if ((0 < Constraint) && (Constraint < MinConstraint))
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
MinConstraint = Constraint;
|
2010-05-01 20:33:53 +00:00
|
|
|
ConstraintReason = 1;
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// offroad uses 0x80 fbp which messes up targets
|
|
|
|
// special case when double buffering (hamsterball)
|
|
|
|
// Suikoden 3 require e00 have this issue too. P3 - 0x1000.
|
2010-05-01 20:33:53 +00:00
|
|
|
|
|
|
|
if (prndr != NULL)
|
|
|
|
{
|
2010-04-25 00:31:27 +00:00
|
|
|
int Constraint = frame.fbp - gsfb.fbp;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
|
|
|
if ((0x0 < Constraint) && (Constraint < MinConstraint))
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
MinConstraint = Constraint;
|
2010-05-01 20:33:53 +00:00
|
|
|
ConstraintReason = 2;
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// old caching method
|
|
|
|
// zmsk necessary for KH movie
|
2010-05-01 20:33:53 +00:00
|
|
|
if (!zbuf.zmsk)
|
|
|
|
{
|
2010-04-25 00:31:27 +00:00
|
|
|
int Constraint = zbuf.zbp - gsfb.fbp;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
|
|
|
if ((0 < Constraint) && (Constraint < MinConstraint))
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
MinConstraint = Constraint;
|
2010-05-01 20:33:53 +00:00
|
|
|
ConstraintReason = 3;
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
// In 16Bit mode in one Word frame stored 2 pixels
|
|
|
|
if (PSMT_ISHALF(gsfb.psm)) MinConstraint *= 2;
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
return MinConstraint ;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return number of 64 pizel words that could be placed in Z-Buffer
|
|
|
|
// If no Z-buffer present return old constraint
|
2010-05-01 20:33:53 +00:00
|
|
|
inline int ZeroGS::VB::FindZbufferMemoryConstrain(int tbp, int maxpos)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
int MinConstraint = maxpos;
|
|
|
|
|
|
|
|
// Check tbp / zbuffer constraint
|
2010-05-01 20:33:53 +00:00
|
|
|
if (!zbuf.zmsk)
|
|
|
|
{
|
|
|
|
int Constraint = (tbp - zbuf.zbp) * (PSMT_ISHALF(zbuf.psm) ? 2 : 1);
|
|
|
|
|
|
|
|
if ((0 < Constraint) && (Constraint < MinConstraint))
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
MinConstraint = Constraint;
|
2010-05-01 20:33:53 +00:00
|
|
|
ConstraintReason = 4;
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return MinConstraint;
|
|
|
|
}
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
// Return heights limiter from scissor...
|
|
|
|
inline int GetScissorY(int y)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
int fbh = (y >> MINMAX_SHIFT) + 1;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
|
|
|
if (fbh > 2 && (fbh & 1)) fbh -= 1;
|
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
return fbh;
|
|
|
|
}
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
//There is several reasons to limit a height of frame: maximum buffer size, calculated size
|
2010-03-19 00:31:15 +00:00
|
|
|
//from fbw and fbh and scissoring.
|
2010-05-01 20:33:53 +00:00
|
|
|
inline int ZeroGS::VB::FindMinimalHeightConstrain(int maxpos)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
int MinConstraint = maxpos;
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
if (maxmin < MinConstraint)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
MinConstraint = maxmin;
|
2010-05-01 20:33:53 +00:00
|
|
|
ConstraintReason = 5;
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
if (gsfb.fbh < MinConstraint)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
MinConstraint = gsfb.fbh;
|
2010-05-01 20:33:53 +00:00
|
|
|
ConstraintReason = 6;
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int ScissorConstraint = GetScissorY(scissor.y1) ;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
|
|
|
if (ScissorConstraint < MinConstraint)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
MinConstraint = ScissorConstraint;
|
2010-05-01 20:33:53 +00:00
|
|
|
ConstraintReason = 7;
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return MinConstraint;
|
|
|
|
}
|
|
|
|
|
2010-04-25 00:31:27 +00:00
|
|
|
// 32 bit frames have additional constraints to frame
|
2010-03-19 00:31:15 +00:00
|
|
|
// maxpos was maximum length of frame at normal constraints
|
2010-05-01 20:33:53 +00:00
|
|
|
inline void ZeroGS::VB::CheckFrame32bitRes(int maxpos)
|
2010-04-25 00:31:27 +00:00
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
int fbh = frame.fbh;
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
if (frame.fbh >= 512)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
// neopets hack
|
|
|
|
maxmin = min(maxmin, frame.fbh);
|
|
|
|
frame.fbh = maxmin;
|
2010-05-01 20:33:53 +00:00
|
|
|
ConstraintReason = 8;
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
// ffxii hack to stop resolving
|
2010-05-01 20:33:53 +00:00
|
|
|
if (frame.fbp >= 0x3000 && fbh >= 0x1a0)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
int endfbp = frame.fbp + frame.fbw * fbh / (PSMT_ISHALF(gsfb.psm) ? 128 : 64);
|
|
|
|
|
|
|
|
// see if there is a previous render target in the way, reduce
|
2010-05-01 20:33:53 +00:00
|
|
|
|
|
|
|
for (CRenderTargetMngr::MAPTARGETS::iterator itnew = s_RTs.mapTargets.begin(); itnew != s_RTs.mapTargets.end(); ++itnew)
|
|
|
|
{
|
|
|
|
if (itnew->second->fbp > frame.fbp && endfbp > itnew->second->fbp)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
endfbp = itnew->second->fbp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
frame.fbh = (endfbp - frame.fbp) * (PSMT_ISHALF(gsfb.psm) ? 128 : 64) / frame.fbw;
|
|
|
|
|
|
|
|
if (frame.fbh < fbh) ConstraintReason = 9;
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
|
|
|
|
2010-04-25 11:14:37 +00:00
|
|
|
// This is the main code for frame resizing.
|
|
|
|
// It checks for several reasons to resize and resizes if it needs to.
|
2010-04-25 00:31:27 +00:00
|
|
|
// 4Mb memory in 64 bit (4 bytes) words.
|
2010-03-19 00:31:15 +00:00
|
|
|
// |------------------------|---------------------|----------|----------|---------------------|
|
|
|
|
// 0 gsfb.fbp zbuff.zpb tbp frame.fbp 2^20/64
|
2010-05-01 20:33:53 +00:00
|
|
|
inline int ZeroGS::VB::CheckFrameAddConstraints(int tbp)
|
2010-03-19 00:31:15 +00:00
|
|
|
{
|
2010-05-01 20:33:53 +00:00
|
|
|
if (gsfb.fbw <= 0)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
ERROR_LOG_SPAM("render target null, no constraints. Ignoring\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Memory region after fbp
|
|
|
|
int maxmemorypos = 0x4000 - gsfb.fbp;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
|
|
|
ConstraintReason = 0;
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-04-25 00:31:27 +00:00
|
|
|
maxmemorypos = FindMinimalMemoryConstrain(tbp, maxmemorypos);
|
2010-03-19 00:31:15 +00:00
|
|
|
maxmemorypos = FindZbufferMemoryConstrain(tbp, maxmemorypos);
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
int maxpos = 64 * maxmemorypos ;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
maxpos /= gsfb.fbw;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
//? atelier iris crashes without it
|
2010-05-01 20:33:53 +00:00
|
|
|
if (maxpos > 256) maxpos &= ~0x1f;
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-04-25 11:14:37 +00:00
|
|
|
#ifdef DEVBUILD
|
|
|
|
int noscissorpos = maxpos;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
|
|
|
int ConstrainR1 = ConstraintReason;
|
2010-04-25 11:14:37 +00:00
|
|
|
#endif
|
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
maxpos = FindMinimalHeightConstrain(maxpos);
|
|
|
|
|
|
|
|
frame = gsfb;
|
|
|
|
frame.fbh = maxpos;
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
if (!PSMT_ISHALF(frame.psm) || !(g_GameSettings&GAME_FULL16BITRES))
|
|
|
|
CheckFrame32bitRes(maxpos);
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
#ifdef DEVBUILD
|
|
|
|
if (frame.fbh == 0xe2)
|
2010-05-01 20:33:53 +00:00
|
|
|
ZZLog::Error_Log("Const: %x %x %d| %x %d %x %x", frame.fbh, frame.fbw, ConstraintReason, noscissorpos, ConstrainR1, tbp, frame.fbp);
|
|
|
|
|
2010-04-25 00:31:27 +00:00
|
|
|
#endif
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-04-25 00:31:27 +00:00
|
|
|
// Fixme: Reserved psm for framebuffers
|
2010-03-19 00:31:15 +00:00
|
|
|
// gsfb.psm &= 0xf; // shadow tower
|
|
|
|
|
|
|
|
return 0 ;
|
|
|
|
}
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
// Check if after resizing new depth target is needed to be used.
|
|
|
|
// it returns 2 if a new depth target is used.
|
|
|
|
inline int ZeroGS::VB::CheckFrameResolveDepth(int tbp)
|
2010-03-19 00:31:15 +00:00
|
|
|
{
|
|
|
|
int result = 0 ;
|
|
|
|
CDepthTarget* pprevdepth = pdepth;
|
|
|
|
pdepth = NULL;
|
|
|
|
|
|
|
|
// just z changed
|
|
|
|
frameInfo f = CreateFrame(zbuf.zbp, prndr->fbw, prndr->fbh, zbuf.psm, (zbuf.psm == 0x31) ? 0xff000000 : 0);
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
CDepthTarget* pnewdepth = (CDepthTarget*)s_DepthRTs.GetTarg(f, CRenderTargetMngr::TO_DepthBuffer | CRenderTargetMngr::TO_StrictHeight |
|
|
|
|
(zbuf.zmsk ? CRenderTargetMngr::TO_Virtual : 0), get_maxheight(zbuf.zbp, gsfb.fbw, 0));
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
assert(pnewdepth != NULL && prndr != NULL);
|
|
|
|
assert(pnewdepth->fbh == prndr->fbh);
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
if ((pprevdepth != pnewdepth) || (pprevdepth != NULL && (pprevdepth->status & CRenderTarget::TS_NeedUpdate)))
|
2010-03-19 00:31:15 +00:00
|
|
|
result = 2;
|
|
|
|
|
|
|
|
pdepth = pnewdepth;
|
|
|
|
|
|
|
|
return result ;
|
|
|
|
}
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
// Check if after resizing, a new render target is needed to be used. Also perform deptarget check.
|
|
|
|
// Returns 1 if only 1 render target is changed and 3 -- if both.
|
|
|
|
inline int ZeroGS::VB::CheckFrameResolveRender(int tbp)
|
|
|
|
{
|
|
|
|
int result = 0;
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
CRenderTarget* pprevrndr = prndr;
|
|
|
|
prndr = NULL;
|
|
|
|
CDepthTarget* pprevdepth = pdepth;
|
|
|
|
pdepth = NULL;
|
|
|
|
// Set renderes to NULL to prevent Flushing.
|
|
|
|
|
|
|
|
CRenderTarget* pnewtarg = s_RTs.GetTarg(frame, 0, maxmin);
|
2010-05-01 20:33:53 +00:00
|
|
|
assert(pnewtarg != NULL);
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
// pnewtarg->fbh >= 0x1c0 needed for ffx
|
2010-05-01 20:33:53 +00:00
|
|
|
|
|
|
|
if ((pnewtarg->fbh >= 0x1c0) && pnewtarg->fbh > frame.fbh && zbuf.zbp < tbp && !zbuf.zmsk)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
// check if zbuf is in the way of the texture (suikoden5)
|
2010-05-01 20:33:53 +00:00
|
|
|
int maxallowedfbh = (tbp - zbuf.zbp) * (PSMT_ISHALF(zbuf.psm) ? 128 : 64) / gsfb.fbw;
|
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
if (PSMT_ISHALF(gsfb.psm)) maxallowedfbh *= 2;
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
if (pnewtarg->fbh > maxallowedfbh + 32) // +32 needed for ffx2
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
// destroy and recreate
|
|
|
|
s_RTs.DestroyAllTargs(0, 0x100, pnewtarg->fbw);
|
|
|
|
pnewtarg = s_RTs.GetTarg(frame, 0, maxmin);
|
2010-05-01 20:33:53 +00:00
|
|
|
assert(pnewtarg != NULL);
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-25 08:33:05 +00:00
|
|
|
ZZLog::Prim_Log("frame_%d: fbp=0x%x fbw=%d fbh=%d(%d) psm=0x%x fbm=0x%x\n", ictx, gsfb.fbp, gsfb.fbw, gsfb.fbh, pnewtarg->fbh, gsfb.psm, gsfb.fbm);
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
if ((pprevrndr != pnewtarg) || (pprevrndr != NULL && (pprevrndr->status & CRenderTarget::TS_NeedUpdate)))
|
2010-03-19 00:31:15 +00:00
|
|
|
result = 1;
|
|
|
|
|
|
|
|
prndr = pnewtarg;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
pdepth = pprevdepth ;
|
|
|
|
|
|
|
|
result |= CheckFrameResolveDepth(tbp) ;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
return result ;
|
|
|
|
}
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
// After frame resetting, it is possible that 16 to 32 or 32 to 16 (color bits) conversion should be made.
|
2010-05-01 22:54:23 +00:00
|
|
|
inline void ZeroGS::VB::CheckFrame16vs32Conversion()
|
2010-03-19 00:31:15 +00:00
|
|
|
{
|
2010-05-01 20:33:53 +00:00
|
|
|
if (prndr->status & CRenderTarget::TS_NeedConvert32)
|
|
|
|
{
|
|
|
|
if (pdepth->pdepth != 0) pdepth->SetDepthStencilSurface();
|
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
prndr->fbh *= 2;
|
|
|
|
prndr->ConvertTo32();
|
|
|
|
prndr->status &= ~CRenderTarget::TS_NeedConvert32;
|
|
|
|
}
|
2010-05-01 20:33:53 +00:00
|
|
|
else if (prndr->status & CRenderTarget::TS_NeedConvert16)
|
|
|
|
{
|
|
|
|
if (pdepth->pdepth != 0) pdepth->SetDepthStencilSurface();
|
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
prndr->fbh /= 2;
|
|
|
|
prndr->ConvertTo16();
|
|
|
|
prndr->status &= ~CRenderTarget::TS_NeedConvert16;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
// A lot of times, the target is too big and overwrites the texture.
|
|
|
|
// If tbp != 0, use it to bound.
|
2010-03-19 00:31:15 +00:00
|
|
|
void ZeroGS::VB::CheckFrame(int tbp)
|
|
|
|
{
|
|
|
|
static int bChanged;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
|
|
|
if (bNeedZCheck)
|
|
|
|
{
|
2010-04-25 08:33:05 +00:00
|
|
|
ZZLog::Prim_Log("zbuf_%d: zbp=0x%x psm=0x%x, zmsk=%d\n", ictx, zbuf.zbp, zbuf.psm, zbuf.zmsk);
|
2010-03-19 00:31:15 +00:00
|
|
|
//zbuf = *zb;
|
|
|
|
}
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
if (m_Blocks[gsfb.psm].bpp == 0)
|
|
|
|
{
|
2010-04-25 08:33:05 +00:00
|
|
|
ZZLog::Error_Log("CheckFrame invalid bpp %d.", gsfb.psm);
|
2010-03-19 00:31:15 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bChanged = 0;
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
if (bNeedFrameCheck)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
// important to set before calling GetTarg
|
|
|
|
bNeedFrameCheck = 0;
|
|
|
|
bNeedZCheck = 0;
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
if (CheckFrameAddConstraints(tbp) == -1) return ;
|
|
|
|
|
|
|
|
if ((prndr != NULL) && (prndr->psm != gsfb.psm))
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
// behavior for dest alpha varies
|
|
|
|
ResetAlphaVariables();
|
2010-05-01 20:33:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bChanged = CheckFrameResolveRender(tbp);
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-05-01 22:54:23 +00:00
|
|
|
CheckFrame16vs32Conversion();
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
2010-05-01 20:33:53 +00:00
|
|
|
else if (bNeedZCheck)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
bNeedZCheck = 0;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
|
|
|
if (prndr != NULL && gsfb.fbw > 0)
|
2010-03-19 00:31:15 +00:00
|
|
|
CheckFrameResolveDepth(tbp);
|
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
if (prndr != NULL) SetContextTarget(ictx);
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// This is the case, most easy to perform, when nothinh was changed
|
2010-05-01 20:33:53 +00:00
|
|
|
inline void ZeroGS::VB::FlushTexUnchangedClutDontUpdate()
|
|
|
|
{
|
|
|
|
if (ZZOglGet_cld_TexBits(uNextTex0Data[1]))
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
ZeroGS::texClutWrite(ictx);
|
|
|
|
// invalidate to make sure target didn't change!
|
2010-05-01 23:34:44 +00:00
|
|
|
bVarsTexSync = false;
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// The second of easy branch. We does not change storage model, so we don't need to
|
|
|
|
// update anything except texture itself
|
2010-05-01 20:33:53 +00:00
|
|
|
inline void ZeroGS::VB::FlushTexClutDontUpdate()
|
|
|
|
{
|
2010-04-25 00:31:27 +00:00
|
|
|
if (!ZZOglClutStorageUnchanged(uCurTex0Data, uNextTex0Data))
|
2010-03-19 00:31:15 +00:00
|
|
|
ZeroGS::Flush(ictx);
|
|
|
|
|
|
|
|
// clut memory isn't going to be loaded so can ignore, but at least update CSA and CPSM!
|
|
|
|
uCurTex0Data[1] = (uCurTex0Data[1] & CPSM_CSA_NOTMASK) | (uNextTex0Data[1] & CPSM_CSA_BITMASK);
|
|
|
|
|
|
|
|
tex0.csa = ZZOglGet_csa_TexBits(uNextTex0Data[1]);
|
|
|
|
tex0.cpsm = ZZOglGet_cpsm_TexBits(uNextTex0Data[1]);
|
|
|
|
|
|
|
|
ZeroGS::texClutWrite(ictx);
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-05-01 23:34:44 +00:00
|
|
|
bVarsTexSync = false;
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
|
|
|
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
// Set texture variables after big change
|
2010-05-01 20:33:53 +00:00
|
|
|
inline void ZeroGS::VB::FlushTexSetNewVars(u32 psm)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
tex0.tbp0 = ZZOglGet_tbp0_TexBits(uNextTex0Data[0]);
|
|
|
|
tex0.tbw = ZZOglGet_tbw_TexBitsMult(uNextTex0Data[0]);
|
|
|
|
tex0.psm = psm;
|
|
|
|
tex0.tw = ZZOglGet_tw_TexBitsExp(uNextTex0Data[0]);
|
|
|
|
tex0.th = ZZOglGet_th_TexBitsExp(uNextTex0Data[0], uNextTex0Data[1]);
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
tex0.tcc = ZZOglGet_tcc_TexBits(uNextTex0Data[1]);
|
|
|
|
tex0.tfx = ZZOglGet_tfx_TexBits(uNextTex0Data[1]);
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
ZeroGS::fiTexWidth[ictx] = (1 / 16.0f) / tex0.tw;
|
|
|
|
ZeroGS::fiTexHeight[ictx] = (1 / 16.0f) / tex0.th;
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Flush == draw on screen
|
|
|
|
// This function made VB state consistant before real Flush.
|
|
|
|
void ZeroGS::VB::FlushTexData()
|
|
|
|
{
|
2010-05-01 20:33:53 +00:00
|
|
|
assert(bNeedTexCheck);
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
bNeedTexCheck = 0;
|
|
|
|
|
|
|
|
u32 psm = ZZOglGet_psm_TexBitsFix(uNextTex0Data[0]);
|
|
|
|
|
|
|
|
// don't update unless necessary
|
2010-05-01 20:33:53 +00:00
|
|
|
|
|
|
|
if (ZZOglAllExceptClutIsSame(uCurTex0Data, uNextTex0Data))
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
// Don't need to do anything if there is no clutting and VB tex data was not changed
|
2010-05-01 20:33:53 +00:00
|
|
|
if (!PSMT_ISCLUT(psm)) return ;
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
// have to write the CLUT again if only CLD was changed
|
2010-05-01 20:33:53 +00:00
|
|
|
if (ZZOglClutMinusCLDunchanged(uCurTex0Data, uNextTex0Data))
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
FlushTexUnchangedClutDontUpdate();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Cld bit is 0 means that clut buffer stay unchanged
|
2010-05-01 20:33:53 +00:00
|
|
|
if (ZZOglGet_cld_TexBits(uNextTex0Data[1]) == 0)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
FlushTexClutDontUpdate();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Made the full update
|
|
|
|
ZeroGS::Flush(ictx);
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-05-01 23:34:44 +00:00
|
|
|
bVarsTexSync = false;
|
|
|
|
bTexConstsSync = false;
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
uCurTex0Data[0] = uNextTex0Data[0];
|
|
|
|
uCurTex0Data[1] = uNextTex0Data[1];
|
|
|
|
|
|
|
|
FlushTexSetNewVars(psm);
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
if (PSMT_ISCLUT(psm)) ZeroGS::CluttingForFlushedTex(&tex0, uNextTex0Data[1], ictx) ;
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|