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
|
|
|
*/
|
|
|
|
|
|
|
|
//-------------------------- Includes
|
2010-11-07 05:51:54 +00:00
|
|
|
#include "Util.h"
|
2010-03-19 00:31:15 +00:00
|
|
|
#include "zerogs.h"
|
2010-10-23 08:15:39 +00:00
|
|
|
#include "ZZoglVB.h"
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
/////////////////////
|
|
|
|
// graphics resources
|
|
|
|
|
2010-05-01 23:34:44 +00:00
|
|
|
bool s_bTexFlush = false;
|
2010-03-19 00:31:15 +00:00
|
|
|
int s_nLastResolveReset = 0;
|
|
|
|
int s_nResolveCounts[30] = {0}; // resolve counts for last 30 frames
|
2010-10-23 04:14:19 +00:00
|
|
|
int s_nNewWidth = -1, s_nNewHeight = -1;
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-10-23 04:14:19 +00:00
|
|
|
primInfo *prim;
|
2010-03-19 00:31:15 +00:00
|
|
|
////////////////////
|
|
|
|
// State parameters
|
2010-10-23 04:14:19 +00:00
|
|
|
int g_nDepthUpdateCount = 0;
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
static ZeroGSInit s_ZeroGSInit;
|
|
|
|
|
2010-10-23 04:14:19 +00:00
|
|
|
// does one time only initializing/destruction
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-10-16 11:54:46 +00:00
|
|
|
void HandleGLError()
|
2010-03-19 00:31:15 +00:00
|
|
|
{
|
|
|
|
FUNCLOG
|
|
|
|
// check the error status of this framebuffer */
|
|
|
|
GLenum error = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
|
|
|
|
|
2010-04-25 00:31:27 +00:00
|
|
|
// if error != GL_FRAMEBUFFER_COMPLETE_EXT, there's an error of some sort
|
2010-05-01 20:33:53 +00:00
|
|
|
|
|
|
|
if (error != 0)
|
|
|
|
{
|
2010-06-15 11:20:52 +00:00
|
|
|
int w = 0;
|
|
|
|
int h = 0;
|
2010-03-19 00:31:15 +00:00
|
|
|
GLint fmt;
|
|
|
|
glGetRenderbufferParameterivEXT(GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_INTERNAL_FORMAT_EXT, &fmt);
|
|
|
|
glGetRenderbufferParameterivEXT(GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_WIDTH_EXT, &w);
|
|
|
|
glGetRenderbufferParameterivEXT(GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_HEIGHT_EXT, &h);
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
switch (error)
|
2010-03-19 00:31:15 +00:00
|
|
|
{
|
|
|
|
case GL_FRAMEBUFFER_COMPLETE_EXT:
|
|
|
|
break;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT:
|
2010-04-25 08:33:05 +00:00
|
|
|
ZZLog::Error_Log("Error! missing a required image/buffer attachment!");
|
2010-03-19 00:31:15 +00:00
|
|
|
break;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT:
|
2010-04-25 08:33:05 +00:00
|
|
|
ZZLog::Error_Log("Error! has no images/buffers attached!");
|
2010-03-19 00:31:15 +00:00
|
|
|
break;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
// case GL_FRAMEBUFFER_INCOMPLETE_DUPLICATE_ATTACHMENT_EXT:
|
2010-04-25 08:33:05 +00:00
|
|
|
// ZZLog::Error_Log("Error! has an image/buffer attached in multiple locations!");
|
2010-03-19 00:31:15 +00:00
|
|
|
// break;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT:
|
2010-04-25 08:33:05 +00:00
|
|
|
ZZLog::Error_Log("Error! has mismatched image/buffer dimensions!");
|
2010-03-19 00:31:15 +00:00
|
|
|
break;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
case GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT:
|
2010-04-25 08:33:05 +00:00
|
|
|
ZZLog::Error_Log("Error! colorbuffer attachments have different types!");
|
2010-03-19 00:31:15 +00:00
|
|
|
break;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT:
|
2010-04-25 08:33:05 +00:00
|
|
|
ZZLog::Error_Log("Error! trying to draw to non-attached color buffer!");
|
2010-03-19 00:31:15 +00:00
|
|
|
break;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT:
|
2010-04-25 08:33:05 +00:00
|
|
|
ZZLog::Error_Log("Error! trying to read from a non-attached color buffer!");
|
2010-03-19 00:31:15 +00:00
|
|
|
break;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
case GL_FRAMEBUFFER_UNSUPPORTED_EXT:
|
2010-04-25 08:33:05 +00:00
|
|
|
ZZLog::Error_Log("Error! format is not supported by current graphics card/driver!");
|
2010-03-19 00:31:15 +00:00
|
|
|
break;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
default:
|
2010-06-15 11:20:52 +00:00
|
|
|
ZZLog::Error_Log("*UNKNOWN ERROR* reported from glCheckFramebufferStatusEXT(0x%x)!", error);
|
2010-03-19 00:31:15 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-16 11:54:46 +00:00
|
|
|
void ZZGSStateReset()
|
2010-03-19 00:31:15 +00:00
|
|
|
{
|
|
|
|
FUNCLOG
|
|
|
|
icurctx = -1;
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
for (int i = 0; i < 2; ++i)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
vb[i].Destroy();
|
2010-10-16 11:54:46 +00:00
|
|
|
memset(&vb[i], 0, sizeof(VB));
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
vb[i].tex0.tw = 1;
|
|
|
|
vb[i].tex0.th = 1;
|
|
|
|
vb[i].scissor.x1 = 639;
|
|
|
|
vb[i].scissor.y1 = 479;
|
|
|
|
vb[i].tex0.tbw = 64;
|
|
|
|
vb[i].Init(VB_BUFFERSIZE);
|
|
|
|
}
|
|
|
|
|
|
|
|
s_RangeMngr.Clear();
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
g_MemTargs.Destroy();
|
|
|
|
s_RTs.Destroy();
|
|
|
|
s_DepthRTs.Destroy();
|
|
|
|
s_BitwiseTextures.Destroy();
|
|
|
|
|
|
|
|
vb[0].ictx = 0;
|
|
|
|
vb[1].ictx = 1;
|
2010-07-02 12:10:40 +00:00
|
|
|
}
|
|
|
|
|
2010-11-14 01:38:10 +00:00
|
|
|
void SetDeviceSize(int nNewWidth, int nNewHeight)
|
2010-03-19 00:31:15 +00:00
|
|
|
{
|
|
|
|
FUNCLOG
|
|
|
|
s_nNewWidth = nNewWidth;
|
|
|
|
s_nNewHeight = nNewHeight;
|
|
|
|
|
2010-06-19 06:23:40 +00:00
|
|
|
if (!(conf.fullscreen()))
|
2010-05-01 20:33:53 +00:00
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
conf.width = nNewWidth;
|
|
|
|
conf.height = nNewHeight;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-16 11:54:46 +00:00
|
|
|
void ChangeDeviceSize(int nNewWidth, int nNewHeight)
|
2010-03-19 00:31:15 +00:00
|
|
|
{
|
|
|
|
FUNCLOG
|
|
|
|
|
2010-11-14 01:38:10 +00:00
|
|
|
Size oldSize = GLWin.backbuffer;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-10-16 11:54:46 +00:00
|
|
|
if (!ZZCreate(nNewWidth&~7, nNewHeight&~7))
|
2010-04-25 08:33:05 +00:00
|
|
|
{
|
|
|
|
ZZLog::Error_Log("Failed to recreate, changing to old device.");
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-11-14 01:38:10 +00:00
|
|
|
if (!ZZCreate(oldSize.w, oldSize.h))
|
2010-04-25 08:33:05 +00:00
|
|
|
{
|
|
|
|
SysMessage("Failed to create device, exiting...");
|
2010-03-19 00:31:15 +00:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
for (int i = 0; i < 2; ++i)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
vb[i].bNeedFrameCheck = vb[i].bNeedZCheck = 1;
|
|
|
|
vb[i].CheckFrame(0);
|
|
|
|
}
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
assert(vb[0].pBufferData != NULL && vb[1].pBufferData != NULL);
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
|
|
|
|
2010-10-16 11:54:46 +00:00
|
|
|
void SetAA(int mode)
|
2010-03-19 00:31:15 +00:00
|
|
|
{
|
|
|
|
FUNCLOG
|
2010-09-15 16:54:19 +00:00
|
|
|
float f = 1.0f;
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
// need to flush all targets
|
|
|
|
s_RTs.ResolveAll();
|
|
|
|
s_RTs.Destroy();
|
|
|
|
s_DepthRTs.ResolveAll();
|
|
|
|
s_DepthRTs.Destroy();
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-09-15 16:54:19 +00:00
|
|
|
AA.x = AA.y = 0; // This is code for x0, x2, x4, x8 and x16 anti-aliasing.
|
|
|
|
|
2010-04-25 00:31:27 +00:00
|
|
|
if (mode > 0)
|
2010-03-19 00:31:15 +00:00
|
|
|
{
|
2010-09-15 16:54:19 +00:00
|
|
|
// ( 1, 0 ) ; ( 1, 1 ) ; ( 2, 1 ) ; ( 2, 2 )
|
|
|
|
// it's used as a binary shift, so x >> AA.x, y >> AA.y
|
|
|
|
AA.x = (mode + 1) / 2;
|
|
|
|
AA.y = mode / 2;
|
|
|
|
f = 2.0f;
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
memset(s_nResolveCounts, 0, sizeof(s_nResolveCounts));
|
|
|
|
s_nLastResolveReset = 0;
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
vb[0].prndr = NULL;
|
|
|
|
vb[0].pdepth = NULL;
|
|
|
|
vb[1].prndr = NULL;
|
|
|
|
vb[1].pdepth = NULL;
|
2010-09-15 16:54:19 +00:00
|
|
|
|
|
|
|
vb[0].bNeedFrameCheck = vb[0].bNeedZCheck = 1;
|
|
|
|
vb[1].bNeedFrameCheck = vb[1].bNeedZCheck = 1;
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
glPointSize(f);
|
|
|
|
}
|
|
|
|
|
2010-10-23 04:14:19 +00:00
|
|
|
//void RenderCustom(float fAlpha)
|
|
|
|
//{
|
|
|
|
// FUNCLOG
|
|
|
|
// GL_REPORT_ERROR();
|
|
|
|
//
|
|
|
|
// fAlpha = 1;
|
|
|
|
// glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); // switch to the backbuffer
|
|
|
|
//
|
|
|
|
// DisableAllgl() ;
|
|
|
|
// SetShaderCaller("RenderCustom");
|
|
|
|
//
|
2010-11-14 01:38:10 +00:00
|
|
|
// glViewport(0, 0, GLWin.backbuffer.w, GLWin.backbuffer.h);
|
2010-10-23 04:14:19 +00:00
|
|
|
//
|
|
|
|
// // play custom animation
|
|
|
|
// glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
|
|
|
//
|
|
|
|
// // tex coords
|
|
|
|
// float4 v = float4(1 / 32767.0f, 1 / 32767.0f, 0, 0);
|
|
|
|
// ZZshSetParameter4fv(pvsBitBlt.prog, pvsBitBlt.sBitBltPos, v, "g_fBitBltPos");
|
|
|
|
// v.x = (float)nLogoWidth;
|
|
|
|
// v.y = (float)nLogoHeight;
|
|
|
|
// ZZshSetParameter4fv(pvsBitBlt.prog, pvsBitBlt.sBitBltTex, v, "g_fBitBltTex");
|
|
|
|
//
|
|
|
|
// v.x = v.y = v.z = v.w = fAlpha;
|
|
|
|
// ZZshSetParameter4fv(ppsBaseTexture.prog, ppsBaseTexture.sOneColor, v, "g_fOneColor");
|
|
|
|
//
|
|
|
|
// if (conf.wireframe()) glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
|
|
|
//
|
|
|
|
// // inside vhDCb[0]'s target area, so render that region only
|
|
|
|
// ZZshGLSetTextureParameter(ppsBaseTexture.prog, ppsBaseTexture.sFinal, ptexLogo, "Logo");
|
|
|
|
// glBindBuffer(GL_ARRAY_BUFFER, vboRect);
|
|
|
|
//
|
|
|
|
// SET_STREAM();
|
|
|
|
//
|
|
|
|
// ZZshSetVertexShader(pvsBitBlt.prog);
|
|
|
|
// ZZshSetPixelShader(ppsBaseTexture.prog);
|
|
|
|
// DrawTriangleArray();
|
|
|
|
//
|
|
|
|
// // restore
|
|
|
|
// if (conf.wireframe()) glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
|
|
|
//
|
|
|
|
// ProcessMessages();
|
|
|
|
//
|
|
|
|
// GLWin.SwapGLBuffers();
|
|
|
|
//
|
|
|
|
// glEnable(GL_SCISSOR_TEST);
|
|
|
|
// glEnable(GL_STENCIL_TEST);
|
|
|
|
//
|
|
|
|
// vb[0].bSyncVars = 0;
|
|
|
|
// vb[1].bSyncVars = 0;
|
|
|
|
//
|
|
|
|
// GL_REPORT_ERROR();
|
|
|
|
//}
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-10-23 04:14:19 +00:00
|
|
|
//////////////////////////
|
|
|
|
// Internal Definitions //
|
|
|
|
//////////////////////////
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-10-23 04:14:19 +00:00
|
|
|
__forceinline void SetFogColor(float4 v)
|
2010-03-19 00:31:15 +00:00
|
|
|
{
|
|
|
|
FUNCLOG
|
2010-06-19 05:41:06 +00:00
|
|
|
|
2010-10-23 04:14:19 +00:00
|
|
|
SetShaderCaller("SetFogColor");
|
|
|
|
ZZshSetParameter4fv(g_fparamFogColor, v, "g_fParamFogColor");
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
|
|
|
|
2010-10-23 04:14:19 +00:00
|
|
|
__forceinline void SetFogColor(u32 fog)
|
2010-03-19 00:31:15 +00:00
|
|
|
{
|
|
|
|
FUNCLOG
|
2010-05-01 20:33:53 +00:00
|
|
|
|
|
|
|
gs.fogcol = fog;
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-10-16 11:54:46 +00:00
|
|
|
FlushBoth();
|
2010-10-23 04:14:19 +00:00
|
|
|
|
2010-09-19 08:01:48 +00:00
|
|
|
float4 v;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-08-22 09:42:28 +00:00
|
|
|
// set it immediately
|
|
|
|
v.SetColor(gs.fogcol);
|
2010-10-23 04:14:19 +00:00
|
|
|
SetFogColor(v);
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
|
|
|
|
2010-10-23 04:14:19 +00:00
|
|
|
__forceinline void SetFogColor(GIFRegFOGCOL* fog)
|
2010-07-09 09:26:35 +00:00
|
|
|
{
|
|
|
|
FUNCLOG
|
|
|
|
|
2010-09-19 08:01:48 +00:00
|
|
|
float4 v;
|
2010-07-09 09:26:35 +00:00
|
|
|
|
|
|
|
v.x = fog->FCR / 255.0f;
|
|
|
|
v.y = fog->FCG / 255.0f;
|
|
|
|
v.z = fog->FCB / 255.0f;
|
2010-10-23 04:14:19 +00:00
|
|
|
SetFogColor(v);
|
2010-07-09 09:26:35 +00:00
|
|
|
}
|
|
|
|
|
2010-10-16 11:54:46 +00:00
|
|
|
void ExtWrite()
|
2010-03-19 00:31:15 +00:00
|
|
|
{
|
|
|
|
FUNCLOG
|
2010-04-25 08:33:05 +00:00
|
|
|
ZZLog::Warn_Log("A hollow voice says 'EXTWRITE'! Nothing happens.");
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
// use local DISPFB, EXTDATA, EXTBUF, and PMODE
|
|
|
|
// int bpp, start, end;
|
|
|
|
// tex0Info texframe;
|
|
|
|
|
|
|
|
// bpp = 4;
|
|
|
|
// if( texframe.psm == PSMT16S ) bpp = 3;
|
|
|
|
// else if (PSMT_ISHALF(texframe.psm)) bpp = 2;
|
|
|
|
//
|
|
|
|
// // get the start and end addresses of the buffer
|
|
|
|
// GetRectMemAddress(start, end, texframe.psm, 0, 0, texframe.tw, texframe.th, texframe.tbp0, texframe.tbw);
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////
|
|
|
|
// Caches //
|
|
|
|
////////////
|
|
|
|
|
|
|
|
|
2010-04-15 22:03:23 +00:00
|
|
|
// case 0: return false;
|
|
|
|
// case 1: break;
|
|
|
|
// case 2: m_CBP[0] = TEX0.CBP; break;
|
|
|
|
// case 3: m_CBP[1] = TEX0.CBP; break;
|
|
|
|
// case 4: if(m_CBP[0] == TEX0.CBP) return false; m_CBP[0] = TEX0.CBP; break;
|
|
|
|
// case 5: if(m_CBP[1] == TEX0.CBP) return false; m_CBP[1] = TEX0.CBP; break;
|
|
|
|
// case 6: ASSERT(0); return false; // ffx2 menu
|
|
|
|
// case 7: ASSERT(0); return false;
|
|
|
|
// default: __assume(0);
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-04-15 22:03:23 +00:00
|
|
|
// cld state:
|
|
|
|
// 000 - clut data is not loaded; data in the temp buffer is stored
|
|
|
|
// 001 - clut data is always loaded.
|
|
|
|
// 010 - clut data is always loaded; cbp0 = cbp.
|
|
|
|
// 011 - clut data is always loadedl cbp1 = cbp.
|
|
|
|
// 100 - cbp0 is compared with cbp. if different, clut data is loaded.
|
|
|
|
// 101 - cbp1 is compared with cbp. if different, clut data is loaded.
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-04-15 22:03:23 +00:00
|
|
|
// GSdx sets cbp0 & cbp1 when checking for clut changes. ZeroGS sets them in texClutWrite.
|
2010-10-16 11:54:46 +00:00
|
|
|
bool CheckChangeInClut(u32 highdword, u32 psm)
|
2010-04-15 22:03:23 +00:00
|
|
|
{
|
|
|
|
FUNCLOG
|
|
|
|
int cld = ZZOglGet_cld_TexBits(highdword);
|
|
|
|
int cbp = ZZOglGet_cbp_TexBits(highdword);
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-04-15 22:03:23 +00:00
|
|
|
// processing the CLUT after tex0/2 are written
|
2010-04-25 08:33:05 +00:00
|
|
|
//ZZLog::Error_Log("high == 0x%x; cld == %d", highdword, cld);
|
2010-05-01 20:33:53 +00:00
|
|
|
|
|
|
|
switch (cld)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
return false;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 4:
|
|
|
|
if (gs.cbp[0] == cbp) return false;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 5:
|
|
|
|
if (gs.cbp[1] == cbp) return false;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2010-04-15 22:03:23 +00:00
|
|
|
}
|
|
|
|
|
2010-10-17 15:49:34 +00:00
|
|
|
// Compare the cache with current memory
|
|
|
|
|
|
|
|
// CSM2 is not supported
|
|
|
|
if (ZZOglGet_csm_TexBits(highdword))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
int cpsm = ZZOglGet_cpsm_TexBits(highdword);
|
|
|
|
int csa = ZZOglGet_csa_TexBits(highdword);
|
|
|
|
int entries = PSMT_IS8CLUT(psm) ? 256 : 16;
|
|
|
|
|
|
|
|
u8* GSMem = g_pbyGSMemory + cbp * 256;
|
|
|
|
|
|
|
|
if (PSMT_IS32BIT(cpsm))
|
2010-10-18 17:39:12 +00:00
|
|
|
return Cmp_ClutBuffer_GSMem<u32>((u32*)GSMem, csa, entries*4);
|
2010-10-17 15:49:34 +00:00
|
|
|
else {
|
|
|
|
// Mana Khemia triggers this.
|
|
|
|
//ZZLog::Error_Log("16 bit clut not supported.");
|
2010-10-18 17:39:12 +00:00
|
|
|
return Cmp_ClutBuffer_GSMem<u16>((u16*)GSMem, csa, entries*2);
|
2010-10-17 15:49:34 +00:00
|
|
|
}
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
|
|
|
|
2010-10-16 11:54:46 +00:00
|
|
|
void texClutWrite(int ctx)
|
2010-03-19 00:31:15 +00:00
|
|
|
{
|
|
|
|
FUNCLOG
|
2010-07-03 07:57:56 +00:00
|
|
|
s_bTexFlush = false;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
tex0Info& tex0 = vb[ctx].tex0;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
|
|
|
assert(PSMT_ISCLUT(tex0.psm));
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
// processing the CLUT after tex0/2 are written
|
2010-05-01 20:33:53 +00:00
|
|
|
switch (tex0.cld)
|
2010-04-15 22:03:23 +00:00
|
|
|
{
|
2010-05-01 20:33:53 +00:00
|
|
|
case 0:
|
|
|
|
return;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
break; // tex0.cld is usually 1.
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
gs.cbp[0] = tex0.cbp;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
gs.cbp[1] = tex0.cbp;
|
|
|
|
break;
|
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
case 4:
|
2010-04-15 22:03:23 +00:00
|
|
|
if (gs.cbp[0] == tex0.cbp) return;
|
2010-03-19 00:31:15 +00:00
|
|
|
gs.cbp[0] = tex0.cbp;
|
|
|
|
break;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
case 5:
|
2010-04-15 22:03:23 +00:00
|
|
|
if (gs.cbp[1] == tex0.cbp) return;
|
2010-03-19 00:31:15 +00:00
|
|
|
gs.cbp[1] = tex0.cbp;
|
|
|
|
break;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-04-25 08:33:05 +00:00
|
|
|
default: //ZZLog::Debug_Log("cld isn't 0-5!");
|
2010-03-19 00:31:15 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
Flush(!ctx);
|
|
|
|
|
2010-10-17 15:49:34 +00:00
|
|
|
// Write the memory to clut buffer
|
|
|
|
GSMem_to_ClutBuffer(tex0);
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
|
|
|
|