2008-12-08 05:25:12 +00:00
|
|
|
// Copyright (C) 2003-2008 Dolphin Project.
|
|
|
|
|
|
|
|
// 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, version 2.0.
|
|
|
|
|
|
|
|
// 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 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official SVN repository and contact information can be found at
|
|
|
|
// http://code.google.com/p/dolphin-emu/
|
|
|
|
|
|
|
|
#include "D3DBase.h"
|
|
|
|
|
|
|
|
#include "Config.h"
|
|
|
|
#include "Common.h"
|
|
|
|
#include "Profiler.h"
|
|
|
|
#include "BPStructs.h"
|
|
|
|
#include "OpcodeDecoding.h"
|
|
|
|
#include "TextureCache.h"
|
|
|
|
#include "TextureDecoder.h"
|
|
|
|
#include "VertexManager.h"
|
2009-02-28 22:10:38 +00:00
|
|
|
#include "PixelShaderGen.h"
|
|
|
|
#include "PixelShaderManager.h"
|
2009-03-07 23:01:58 +00:00
|
|
|
#include "VertexShaderManager.h"
|
2008-12-08 05:25:12 +00:00
|
|
|
#include "Utils.h"
|
|
|
|
|
|
|
|
#include "main.h" //for the plugin interface
|
|
|
|
|
|
|
|
bool textureChanged[8];
|
|
|
|
|
|
|
|
const bool renderFog = false;
|
|
|
|
|
2009-02-28 22:10:38 +00:00
|
|
|
using namespace D3D;
|
|
|
|
|
2008-12-08 05:25:12 +00:00
|
|
|
// State translation lookup tables
|
2009-02-28 22:10:38 +00:00
|
|
|
static const D3DBLEND d3dSrcFactors[8] =
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
|
|
|
D3DBLEND_ZERO,
|
|
|
|
D3DBLEND_ONE,
|
|
|
|
D3DBLEND_DESTCOLOR,
|
|
|
|
D3DBLEND_INVDESTCOLOR,
|
|
|
|
D3DBLEND_SRCALPHA,
|
|
|
|
D3DBLEND_INVSRCALPHA,
|
|
|
|
D3DBLEND_DESTALPHA,
|
|
|
|
D3DBLEND_INVDESTALPHA
|
|
|
|
};
|
|
|
|
|
2009-02-28 22:10:38 +00:00
|
|
|
static const D3DBLEND d3dDestFactors[8] =
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
|
|
|
D3DBLEND_ZERO,
|
|
|
|
D3DBLEND_ONE,
|
|
|
|
D3DBLEND_SRCCOLOR,
|
|
|
|
D3DBLEND_INVSRCCOLOR,
|
|
|
|
D3DBLEND_SRCALPHA,
|
|
|
|
D3DBLEND_INVSRCALPHA,
|
|
|
|
D3DBLEND_DESTALPHA,
|
|
|
|
D3DBLEND_INVDESTALPHA
|
|
|
|
};
|
|
|
|
|
2009-02-28 22:10:38 +00:00
|
|
|
static const D3DCULL d3dCullModes[4] =
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
|
|
|
D3DCULL_NONE,
|
|
|
|
D3DCULL_CCW,
|
|
|
|
D3DCULL_CW,
|
|
|
|
D3DCULL_CCW
|
|
|
|
};
|
|
|
|
|
2009-02-28 22:10:38 +00:00
|
|
|
static const D3DCMPFUNC d3dCmpFuncs[8] =
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
|
|
|
D3DCMP_NEVER,
|
|
|
|
D3DCMP_LESS,
|
|
|
|
D3DCMP_EQUAL,
|
|
|
|
D3DCMP_LESSEQUAL,
|
|
|
|
D3DCMP_GREATER,
|
|
|
|
D3DCMP_NOTEQUAL,
|
|
|
|
D3DCMP_GREATEREQUAL,
|
|
|
|
D3DCMP_ALWAYS
|
|
|
|
};
|
|
|
|
|
2009-02-28 22:10:38 +00:00
|
|
|
static const D3DTEXTUREFILTERTYPE d3dMipFilters[4] =
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
|
|
|
D3DTEXF_NONE,
|
|
|
|
D3DTEXF_POINT,
|
|
|
|
D3DTEXF_ANISOTROPIC,
|
|
|
|
D3DTEXF_LINEAR, //reserved
|
|
|
|
};
|
|
|
|
|
2009-02-28 22:10:38 +00:00
|
|
|
static const D3DTEXTUREADDRESS d3dClamps[4] =
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
|
|
|
D3DTADDRESS_CLAMP,
|
|
|
|
D3DTADDRESS_WRAP,
|
|
|
|
D3DTADDRESS_MIRROR,
|
|
|
|
D3DTADDRESS_WRAP //reserved
|
|
|
|
};
|
|
|
|
|
|
|
|
void BPInit()
|
|
|
|
{
|
|
|
|
memset(&bpmem, 0, sizeof(bpmem));
|
|
|
|
bpmem.bpMask = 0xFFFFFF;
|
|
|
|
}
|
|
|
|
|
|
|
|
// __________________________________________________________________________________________________
|
|
|
|
// BPWritten
|
|
|
|
//
|
|
|
|
void BPWritten(int addr, int changes, int newval)
|
|
|
|
{
|
|
|
|
switch(addr)
|
|
|
|
{
|
|
|
|
case BPMEM_GENMODE:
|
|
|
|
if (changes)
|
|
|
|
{
|
|
|
|
VertexManager::Flush();
|
|
|
|
((u32*)&bpmem)[addr] = newval;
|
|
|
|
|
|
|
|
// dev->SetRenderState(D3DRS_CULLMODE, d3dCullModes[bpmem.genMode.cullmode]);
|
2009-02-28 22:10:38 +00:00
|
|
|
Renderer::SetRenderState(D3DRS_CULLMODE, d3dCullModes[bpmem.genMode.cullmode]);
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
|
|
if (bpmem.genMode.cullmode == 3)
|
|
|
|
{
|
|
|
|
// dev->SetRenderState(D3DRS_COLORWRITEENABLE, 0);
|
2009-02-28 22:10:38 +00:00
|
|
|
Renderer::SetRenderState(D3DRS_COLORWRITEENABLE, 0);
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DWORD write = 0;
|
|
|
|
if (bpmem.blendmode.alphaupdate)
|
|
|
|
write = D3DCOLORWRITEENABLE_ALPHA;
|
|
|
|
if (bpmem.blendmode.colorupdate)
|
|
|
|
write |= D3DCOLORWRITEENABLE_RED | D3DCOLORWRITEENABLE_GREEN | D3DCOLORWRITEENABLE_BLUE;
|
|
|
|
|
|
|
|
// dev->SetRenderState(D3DRS_COLORWRITEENABLE, write);
|
2009-02-28 22:10:38 +00:00
|
|
|
Renderer::SetRenderState(D3DRS_COLORWRITEENABLE, write);
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
2009-03-07 23:01:58 +00:00
|
|
|
PixelShaderManager::SetGenModeChanged();
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case BPMEM_IND_MTX+0:
|
|
|
|
case BPMEM_IND_MTX+1:
|
|
|
|
case BPMEM_IND_MTX+2:
|
|
|
|
case BPMEM_IND_MTX+3:
|
|
|
|
case BPMEM_IND_MTX+4:
|
|
|
|
case BPMEM_IND_MTX+5:
|
|
|
|
case BPMEM_IND_MTX+6:
|
|
|
|
case BPMEM_IND_MTX+7:
|
|
|
|
case BPMEM_IND_MTX+8:
|
|
|
|
if (changes) {
|
|
|
|
VertexManager::Flush();
|
|
|
|
((u32*)&bpmem)[addr] = newval;
|
2009-02-28 22:10:38 +00:00
|
|
|
PixelShaderManager::SetIndMatrixChanged((addr-BPMEM_IND_MTX)/3);
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case BPMEM_RAS1_SS0:
|
|
|
|
case BPMEM_RAS1_SS1:
|
|
|
|
if (changes) {
|
|
|
|
VertexManager::Flush();
|
|
|
|
((u32*)&bpmem)[addr] = newval;
|
2009-02-28 22:10:38 +00:00
|
|
|
PixelShaderManager::SetIndTexScaleChanged();
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BPMEM_ZMODE:
|
|
|
|
if (changes)
|
|
|
|
{
|
|
|
|
VertexManager::Flush();
|
|
|
|
((u32*)&bpmem)[addr] = newval;
|
|
|
|
if (bpmem.zmode.testenable)
|
|
|
|
{
|
|
|
|
// dev->SetRenderState(D3DRS_ZENABLE, TRUE);
|
|
|
|
// dev->SetRenderState(D3DRS_ZWRITEENABLE, bpmem.zmode.updateenable);
|
|
|
|
// dev->SetRenderState(D3DRS_ZFUNC,d3dCmpFuncs[bpmem.zmode.func]);
|
|
|
|
|
2009-02-28 22:10:38 +00:00
|
|
|
Renderer::SetRenderState(D3DRS_ZENABLE, TRUE);
|
|
|
|
Renderer::SetRenderState(D3DRS_ZWRITEENABLE, bpmem.zmode.updateenable);
|
|
|
|
Renderer::SetRenderState(D3DRS_ZFUNC, d3dCmpFuncs[bpmem.zmode.func]);
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// if the test is disabled write is disabled too
|
|
|
|
// dev->SetRenderState(D3DRS_ZENABLE, FALSE);
|
|
|
|
// dev->SetRenderState(D3DRS_ZWRITEENABLE, FALSE);
|
|
|
|
|
2009-02-28 22:10:38 +00:00
|
|
|
Renderer::SetRenderState(D3DRS_ZENABLE, FALSE);
|
|
|
|
Renderer::SetRenderState(D3DRS_ZWRITEENABLE, FALSE);
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
|
|
|
|
2009-02-28 22:10:38 +00:00
|
|
|
//if (!bpmem.zmode.updateenable)
|
|
|
|
// Renderer::SetRenderMode(Renderer::RM_Normal);
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2009-02-28 22:10:38 +00:00
|
|
|
case BPMEM_ALPHACOMPARE:
|
|
|
|
if (changes) {
|
|
|
|
VertexManager::Flush();
|
|
|
|
((u32*)&bpmem)[addr] = newval;
|
|
|
|
PRIM_LOG("alphacmp: ref0=%d, ref1=%d, comp0=%d, comp1=%d, logic=%d\n", bpmem.alphaFunc.ref0,
|
|
|
|
bpmem.alphaFunc.ref1, bpmem.alphaFunc.comp0, bpmem.alphaFunc.comp1, bpmem.alphaFunc.logic);
|
|
|
|
PixelShaderManager::SetAlpha(bpmem.alphaFunc);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BPMEM_CONSTANTALPHA:
|
|
|
|
if (changes) {
|
|
|
|
VertexManager::Flush();
|
|
|
|
((u32*)&bpmem)[addr] = newval;
|
|
|
|
PRIM_LOG("constalpha: alp=%d, en=%d\n", bpmem.dstalpha.alpha, bpmem.dstalpha.enable);
|
2009-03-07 23:01:58 +00:00
|
|
|
//PixelShaderManager::SetDestAlpha(bpmem.dstalpha);
|
2009-02-28 22:10:38 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2008-12-08 05:25:12 +00:00
|
|
|
case BPMEM_LINEPTWIDTH:
|
|
|
|
{
|
|
|
|
// We can't change line width in D3D unless we use ID3DXLine
|
|
|
|
//bpmem.lineptwidth.linesize);
|
|
|
|
float psize = float(bpmem.lineptwidth.pointsize) * 6.0f;
|
|
|
|
|
|
|
|
Renderer::SetRenderState(D3DRS_POINTSIZE, *((DWORD*)&psize));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2009-03-07 23:01:58 +00:00
|
|
|
case BPMEM_PE_CONTROL: // GXSetZCompLoc, GXPixModeSync
|
2008-12-08 05:25:12 +00:00
|
|
|
if (changes) {
|
|
|
|
VertexManager::Flush();
|
|
|
|
((u32*)&bpmem)[addr] = newval;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BPMEM_BLENDMODE:
|
|
|
|
if (changes & 0xFFFF)
|
|
|
|
{
|
|
|
|
VertexManager::Flush();
|
|
|
|
((u32*)&bpmem)[addr] = newval;
|
|
|
|
if (changes & 1)
|
|
|
|
{
|
2009-02-28 22:10:38 +00:00
|
|
|
Renderer::SetRenderState(D3DRS_ALPHABLENDENABLE, bpmem.blendmode.blendenable);
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
|
|
|
if (changes & 2) {} // Logic op blending. D3D can't do this but can fake some modes.
|
|
|
|
if (changes & 4) {
|
|
|
|
// Dithering is pointless. Will make things uglier and will be different from GC.
|
|
|
|
// dev->SetRenderState(D3DRS_DITHERENABLE,bpmem.blendmode.dither);
|
|
|
|
}
|
|
|
|
D3DBLEND src = d3dSrcFactors[bpmem.blendmode.srcfactor];
|
|
|
|
D3DBLEND dst = d3dDestFactors[bpmem.blendmode.dstfactor];
|
|
|
|
|
|
|
|
if (changes & 0x700)
|
|
|
|
{
|
2009-02-28 22:10:38 +00:00
|
|
|
Renderer::SetRenderState(D3DRS_SRCBLEND, src);
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
|
|
|
if (changes & 0xE0) {
|
|
|
|
if (!bpmem.blendmode.subtract)
|
|
|
|
{
|
2009-02-28 22:10:38 +00:00
|
|
|
Renderer::SetRenderState(D3DRS_DESTBLEND, dst);
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-02-28 22:10:38 +00:00
|
|
|
Renderer::SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (changes & 0x800) {
|
|
|
|
if (bpmem.blendmode.subtract)
|
|
|
|
{
|
2009-02-28 22:10:38 +00:00
|
|
|
Renderer::SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE);
|
|
|
|
Renderer::SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-02-28 22:10:38 +00:00
|
|
|
Renderer::SetRenderState(D3DRS_SRCBLEND, src);
|
|
|
|
Renderer::SetRenderState(D3DRS_DESTBLEND, dst);
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
|
|
|
|
2009-02-28 22:10:38 +00:00
|
|
|
Renderer::SetRenderState(D3DRS_BLENDOP, bpmem.blendmode.subtract ? D3DBLENDOP_SUBTRACT : D3DBLENDOP_ADD);
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
|
|
|
//if (bpmem.blendmode.logicopenable) // && bpmem.blendmode.logicmode == 4)
|
|
|
|
// MessageBox(0,"LOGIC",0,0);
|
|
|
|
|
|
|
|
if (changes & 0x18)
|
|
|
|
{
|
|
|
|
// Color Mask
|
|
|
|
DWORD write = 0;
|
|
|
|
if (bpmem.blendmode.alphaupdate)
|
|
|
|
write = D3DCOLORWRITEENABLE_ALPHA;
|
|
|
|
if (bpmem.blendmode.colorupdate)
|
|
|
|
write |= D3DCOLORWRITEENABLE_RED | D3DCOLORWRITEENABLE_GREEN | D3DCOLORWRITEENABLE_BLUE;
|
|
|
|
|
2009-02-28 22:10:38 +00:00
|
|
|
Renderer::SetRenderState(D3DRS_COLORWRITEENABLE, write);
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BPMEM_FOGRANGE:
|
|
|
|
case BPMEM_FOGPARAM0:
|
|
|
|
case BPMEM_FOGBEXPONENT:
|
|
|
|
case BPMEM_FOGBMAGNITUDE:
|
|
|
|
case BPMEM_FOGPARAM3:
|
2009-02-28 22:10:38 +00:00
|
|
|
if (changes) {
|
2008-12-08 05:25:12 +00:00
|
|
|
VertexManager::Flush();
|
|
|
|
((u32*)&bpmem)[addr] = newval;
|
2009-03-07 23:01:58 +00:00
|
|
|
PixelShaderManager::SetFogParamChanged();
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BPMEM_FOGCOLOR:
|
2009-03-07 23:01:58 +00:00
|
|
|
if (changes)
|
|
|
|
{
|
2008-12-08 05:25:12 +00:00
|
|
|
VertexManager::Flush();
|
|
|
|
((u32*)&bpmem)[addr] = newval;
|
2009-03-07 23:01:58 +00:00
|
|
|
PixelShaderManager::SetFogColorChanged();
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BPMEM_TEXINVALIDATE:
|
|
|
|
//TexCache_Invalidate();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BPMEM_SCISSOROFFSET: //TODO: investigate
|
|
|
|
{
|
|
|
|
VertexManager::Flush();
|
|
|
|
((u32*)&bpmem)[addr] = newval;
|
2009-02-28 22:10:38 +00:00
|
|
|
Renderer::SetScissorRect();
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2009-03-07 23:01:58 +00:00
|
|
|
case BPMEM_SCISSORTL:
|
|
|
|
case BPMEM_SCISSORBR:
|
|
|
|
|
|
|
|
if (changes)
|
|
|
|
{
|
|
|
|
VertexManager::Flush();
|
|
|
|
((u32*)&bpmem)[addr] = newval;
|
|
|
|
/*if (!Renderer::SetScissorRect())
|
|
|
|
{
|
|
|
|
if (addr == BPMEM_SCISSORBR) {
|
|
|
|
ERROR_LOG(VIDEO, "bad scissor!\n");
|
|
|
|
}
|
|
|
|
}*/
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2008-12-08 05:25:12 +00:00
|
|
|
case BPMEM_ZTEX1:
|
|
|
|
if (changes) {
|
|
|
|
VertexManager::Flush();
|
|
|
|
((u32*)&bpmem)[addr] = newval;
|
|
|
|
//PRIM_LOG("ztex bias=0x%x\n", bpmem.ztex1.bias);
|
2009-03-07 23:01:58 +00:00
|
|
|
PixelShaderManager::SetZTextureBias(bpmem.ztex1.bias);
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case BPMEM_ZTEX2:
|
|
|
|
if (changes) {
|
|
|
|
VertexManager::Flush();
|
|
|
|
((u32*)&bpmem)[addr] = newval;
|
2009-03-07 23:01:58 +00:00
|
|
|
if (changes & 3) {
|
|
|
|
PixelShaderManager::SetZTextureTypeChanged();
|
|
|
|
}
|
2008-12-08 05:25:12 +00:00
|
|
|
#ifdef _DEBUG
|
|
|
|
const char* pzop[] = {"DISABLE", "ADD", "REPLACE", "?"};
|
|
|
|
const char* pztype[] = {"Z8", "Z16", "Z24", "?"};
|
2009-02-28 23:02:46 +00:00
|
|
|
DEBUG_LOG(VIDEO, "ztex op=%s, type=%s\n", pzop[bpmem.ztex2.op], pztype[bpmem.ztex2.type]);
|
2008-12-08 05:25:12 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2009-03-07 23:01:58 +00:00
|
|
|
case BPMEM_SETDRAWDONE: //GXSetDrawDone
|
2008-12-08 05:25:12 +00:00
|
|
|
VertexManager::Flush();
|
2009-02-28 22:10:38 +00:00
|
|
|
switch (newval & 0xFF)
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
|
|
|
case 0x02:
|
|
|
|
g_VideoInitialize.pSetPEFinish(); // may generate interrupt
|
2009-02-28 22:45:19 +00:00
|
|
|
DEBUG_LOG(VIDEO, "GXSetDrawDone SetPEFinish (value: 0x%02X)", (newval & 0xFFFF));
|
2008-12-08 05:25:12 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2009-02-28 22:45:19 +00:00
|
|
|
DEBUG_LOG(VIDEO, "GXSetDrawDone ??? (value 0x%02X)", (newval & 0xFFFF));
|
2008-12-08 05:25:12 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BPMEM_PE_TOKEN_ID:
|
2009-02-28 22:10:38 +00:00
|
|
|
g_VideoInitialize.pSetPEToken(static_cast<u16>(newval & 0xFFFF), FALSE);
|
2009-02-28 22:45:19 +00:00
|
|
|
DEBUG_LOG(VIDEO, "SetPEToken 0x%04x", (newval & 0xFFFF));
|
2008-12-08 05:25:12 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BPMEM_PE_TOKEN_INT_ID:
|
2009-02-28 22:10:38 +00:00
|
|
|
g_VideoInitialize.pSetPEToken(static_cast<u16>(newval & 0xFFFF), TRUE);
|
2009-02-28 22:45:19 +00:00
|
|
|
DEBUG_LOG(VIDEO, "SetPEToken + INT 0x%04x", (newval & 0xFFFF));
|
2008-12-08 05:25:12 +00:00
|
|
|
break;
|
|
|
|
|
2009-03-07 23:01:58 +00:00
|
|
|
case BPMEM_SETGPMETRIC: // set gp metric?
|
2008-12-08 05:25:12 +00:00
|
|
|
break;
|
|
|
|
|
2009-02-28 22:10:38 +00:00
|
|
|
case BPMEM_TRIGGER_EFB_COPY:
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
|
|
|
VertexManager::Flush();
|
|
|
|
|
2009-02-28 22:10:38 +00:00
|
|
|
((u32*)&bpmem)[addr] = newval;
|
2008-12-08 05:25:12 +00:00
|
|
|
RECT rc = {
|
|
|
|
(LONG)(bpmem.copyTexSrcXY.x*Renderer::GetXScale()),
|
|
|
|
(LONG)(bpmem.copyTexSrcXY.y*Renderer::GetYScale()),
|
|
|
|
(LONG)((bpmem.copyTexSrcXY.x+bpmem.copyTexSrcWH.x)*Renderer::GetXScale()),
|
|
|
|
(LONG)((bpmem.copyTexSrcXY.y+bpmem.copyTexSrcWH.y)*Renderer::GetYScale())
|
|
|
|
};
|
|
|
|
|
|
|
|
UPE_Copy PE_copy;
|
|
|
|
PE_copy.Hex = bpmem.triggerEFBCopy;
|
|
|
|
|
|
|
|
// clamp0
|
|
|
|
// clamp1
|
|
|
|
// target_pixel_format
|
|
|
|
// gamma
|
|
|
|
// scale_something
|
|
|
|
// clear
|
|
|
|
// frame_to_field
|
|
|
|
// copy_to_xfb
|
|
|
|
|
|
|
|
// ???: start Mem to/from EFB transfer
|
|
|
|
/* bool bMip = false; // ignored
|
|
|
|
if (bpmem.triggerEFBCopy & EFBCOPY_GENERATEMIPS)
|
|
|
|
bMip = true;*/
|
|
|
|
|
|
|
|
if (PE_copy.copy_to_xfb == 0) // bpmem.triggerEFBCopy & EFBCOPY_EFBTOTEXTURE)
|
|
|
|
{
|
|
|
|
// EFB to texture
|
|
|
|
// for some reason it sets bpmem.zcontrol.pixel_format to PIXELFMT_Z24 every time a zbuffer format is given as a dest to GXSetTexCopyDst
|
|
|
|
TextureCache::CopyEFBToRenderTarget(bpmem.copyTexDest<<5, &rc);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// EFB to XFB
|
|
|
|
// MessageBox(0, "WASDF", 0, 0);
|
|
|
|
Renderer::SwapBuffers();
|
2009-02-28 22:10:38 +00:00
|
|
|
PRIM_LOG("Renderer::SwapBuffers()");
|
2008-12-08 05:25:12 +00:00
|
|
|
g_VideoInitialize.pCopiedToXFB();
|
|
|
|
}
|
|
|
|
|
|
|
|
// clearing
|
|
|
|
if (PE_copy.clear) // bpmem.triggerEFBCopy & EFBCOPY_CLEAR)
|
|
|
|
{
|
|
|
|
// it seems that the GC is able to alpha blend on color-fill
|
|
|
|
// we cant do that so if alpha is != 255 we skip it
|
|
|
|
|
2009-03-07 23:01:58 +00:00
|
|
|
VertexShaderManager::SetViewportChanged();
|
|
|
|
|
2009-03-09 23:24:53 +00:00
|
|
|
// Since clear operations use the source rectangle, we have to do
|
|
|
|
// regular renders
|
2009-03-10 23:22:56 +00:00
|
|
|
DWORD clearflags = 0;
|
|
|
|
D3DCOLOR col = 0;
|
|
|
|
float clearZ = 0;
|
2009-03-09 23:24:53 +00:00
|
|
|
if (bpmem.blendmode.colorupdate || bpmem.blendmode.alphaupdate)
|
|
|
|
{
|
|
|
|
if (bpmem.blendmode.colorupdate || bpmem.blendmode.alphaupdate)
|
|
|
|
col = (bpmem.clearcolorAR << 16) | bpmem.clearcolorGB;
|
2009-03-10 23:22:56 +00:00
|
|
|
// clearflags |= D3DCLEAR_TARGET; set to break animal crossing :p
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// clear z-buffer
|
|
|
|
if (bpmem.zmode.updateenable)
|
|
|
|
{
|
2009-03-10 23:22:56 +00:00
|
|
|
clearZ = (float)(bpmem.clearZValue & 0xFFFFFF) / float(0xFFFFFF);
|
2008-12-08 05:25:12 +00:00
|
|
|
if (clearZ > 1.0f) clearZ = 1.0f;
|
|
|
|
if (clearZ < 0.0f) clearZ = 0.0f;
|
2009-03-10 23:22:56 +00:00
|
|
|
clearflags |= D3DCLEAR_ZBUFFER | D3DCLEAR_STENCIL;
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
2009-03-10 23:22:56 +00:00
|
|
|
D3D::dev->Clear(0, NULL, clearflags, col, clearZ, 0);
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2009-02-28 22:10:38 +00:00
|
|
|
case BPMEM_LOADTLUT: //GXLoadTlut
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
|
|
|
VertexManager::Flush();
|
2009-02-28 22:10:38 +00:00
|
|
|
((u32*)&bpmem)[addr] = newval;
|
|
|
|
|
|
|
|
u32 tlutTMemAddr = (newval & 0x3FF) << 9;
|
|
|
|
u32 tlutXferCount = (newval & 0x1FFC00) >> 5;
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2009-02-28 22:10:38 +00:00
|
|
|
u8 *ptr = 0;
|
|
|
|
// TODO - figure out a cleaner way.
|
|
|
|
if (g_VideoInitialize.bWii)
|
|
|
|
ptr = g_VideoInitialize.pGetMemoryPointer(bpmem.tlutXferSrc << 5);
|
|
|
|
else
|
|
|
|
ptr = g_VideoInitialize.pGetMemoryPointer((bpmem.tlutXferSrc & 0xFFFFF) << 5);
|
|
|
|
if (ptr)
|
|
|
|
memcpy_gc(texMem + tlutTMemAddr, ptr, tlutXferCount);
|
|
|
|
else
|
|
|
|
PanicAlert("Invalid palette pointer %08x %08x %08x", bpmem.tlutXferSrc, bpmem.tlutXferSrc << 5, (bpmem.tlutXferSrc & 0xFFFFF)<< 5);
|
2008-12-08 05:25:12 +00:00
|
|
|
// TODO(ector) : kill all textures that use this palette
|
|
|
|
// Not sure if it's a good idea, though. For now, we hash texture palettes
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2009-02-28 22:10:38 +00:00
|
|
|
case 0xf6: // ksel0
|
|
|
|
case 0xf7: // ksel1
|
|
|
|
case 0xf8: // ksel2
|
|
|
|
case 0xf9: // ksel3
|
|
|
|
case 0xfa: // ksel4
|
|
|
|
case 0xfb: // ksel5
|
|
|
|
case 0xfc: // ksel6
|
|
|
|
case 0xfd: // ksel7
|
|
|
|
if (changes)
|
|
|
|
{
|
|
|
|
VertexManager::Flush();
|
|
|
|
((u32*)&bpmem)[addr] = newval;
|
|
|
|
PixelShaderManager::SetTevKSelChanged(addr-0xf6);
|
|
|
|
}
|
|
|
|
break;
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2009-02-28 22:10:38 +00:00
|
|
|
default:
|
2009-03-07 23:01:58 +00:00
|
|
|
switch (addr & 0xFC) //texture sampler filter
|
2009-02-28 22:10:38 +00:00
|
|
|
{
|
2009-03-07 23:01:58 +00:00
|
|
|
case 0x28: // tevorder 0-3
|
|
|
|
case 0x2C: // tevorder 4-7
|
|
|
|
if (changes)
|
|
|
|
{
|
|
|
|
VertexManager::Flush();
|
|
|
|
((u32*)&bpmem)[addr] = newval;
|
|
|
|
PixelShaderManager::SetTevOrderChanged(addr - 0x28);
|
|
|
|
}
|
|
|
|
break;
|
2009-02-28 22:10:38 +00:00
|
|
|
case 0x80: // TEX MODE 0
|
|
|
|
case 0xA0:
|
|
|
|
if (changes)
|
|
|
|
{
|
|
|
|
VertexManager::Flush();
|
|
|
|
((u32*)&bpmem)[addr] = newval;
|
|
|
|
FourTexUnits &tex = bpmem.tex[(addr&0xE0)==0xA0];
|
|
|
|
int stage = (addr&3);//(addr>>4)&2;
|
|
|
|
TexMode0 &tm0 = tex.texMode0[stage];
|
|
|
|
|
|
|
|
D3DTEXTUREFILTERTYPE min, mag, mip;
|
|
|
|
if (g_Config.bForceFiltering)
|
|
|
|
{
|
|
|
|
min = mag = mip = D3DTEXF_LINEAR;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
min = (tm0.min_filter&4) ? D3DTEXF_LINEAR : D3DTEXF_POINT;
|
|
|
|
mag = tm0.mag_filter ? D3DTEXF_LINEAR : D3DTEXF_POINT;
|
|
|
|
mip = d3dMipFilters[tm0.min_filter&3];
|
|
|
|
}
|
|
|
|
if ((addr & 0xE0) == 0xA0)
|
|
|
|
stage += 4;
|
|
|
|
|
|
|
|
if (g_Config.bForceMaxAniso)
|
|
|
|
{
|
|
|
|
mag = D3DTEXF_ANISOTROPIC;
|
|
|
|
mip = D3DTEXF_ANISOTROPIC;
|
|
|
|
min = D3DTEXF_ANISOTROPIC;
|
|
|
|
}
|
|
|
|
dev->SetSamplerState(stage, D3DSAMP_MINFILTER, min);
|
|
|
|
dev->SetSamplerState(stage, D3DSAMP_MAGFILTER, mag);
|
|
|
|
dev->SetSamplerState(stage, D3DSAMP_MIPFILTER, mip);
|
|
|
|
|
|
|
|
dev->SetSamplerState(stage, D3DSAMP_MAXANISOTROPY,16);
|
|
|
|
dev->SetSamplerState(stage, D3DSAMP_ADDRESSU,d3dClamps[tm0.wrap_s]);
|
|
|
|
dev->SetSamplerState(stage, D3DSAMP_ADDRESSV,d3dClamps[tm0.wrap_t]);
|
|
|
|
//wip
|
|
|
|
//dev->SetSamplerState(stage,D3DSAMP_MIPMAPLODBIAS,tm0.lod_bias/4.0f);
|
|
|
|
//char temp[256];
|
|
|
|
//sprintf(temp,"lod %f",tm0.lod_bias/4.0f);
|
|
|
|
//g_VideoInitialize.pLog(temp);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x84://TEX MODE 1
|
|
|
|
case 0xA4:
|
|
|
|
break;
|
|
|
|
case 0x88://TEX IMAGE 0
|
|
|
|
case 0xA8:
|
|
|
|
if (changes)
|
|
|
|
{
|
|
|
|
//textureChanged[((addr&0xE0)==0xA0)*4+(addr&3)] = true;
|
|
|
|
VertexManager::Flush();
|
|
|
|
((u32*)&bpmem)[addr] = newval;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x8C://TEX IMAGE 1
|
|
|
|
case 0xAC:
|
|
|
|
if (changes)
|
|
|
|
{
|
|
|
|
//textureChanged[((addr&0xE0)==0xA0)*4+(addr&3)] = true;
|
|
|
|
VertexManager::Flush();
|
|
|
|
((u32*)&bpmem)[addr] = newval;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x90://TEX IMAGE 2
|
|
|
|
case 0xB0:
|
|
|
|
if (changes)
|
|
|
|
{
|
|
|
|
//textureChanged[((addr&0xE0)==0xA0)*4+(addr&3)] = true;
|
|
|
|
VertexManager::Flush();
|
|
|
|
((u32*)&bpmem)[addr] = newval;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x94://TEX IMAGE 3
|
|
|
|
case 0xB4:
|
|
|
|
if (changes)
|
|
|
|
{
|
|
|
|
//textureChanged[((addr&0xE0)==0xA0)*4+(addr&3)] = true;
|
|
|
|
VertexManager::Flush();
|
|
|
|
((u32*)&bpmem)[addr] = newval;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x98://TEX TLUT
|
|
|
|
case 0xB8:
|
|
|
|
if (changes)
|
|
|
|
{
|
|
|
|
//textureChanged[((addr&0xE0)==0xA0)*4+(addr&3)] = true;
|
|
|
|
VertexManager::Flush();
|
|
|
|
((u32*)&bpmem)[addr] = newval;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x9C://TEX UNKNOWN
|
|
|
|
case 0xBC:
|
|
|
|
//ERROR_LOG("texunknown%x = %x\n", addr, newval);
|
|
|
|
((u32*)&bpmem)[addr] = newval;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0xE0:
|
|
|
|
case 0xE4:
|
|
|
|
if (addr&1) { // don't compare with changes!
|
|
|
|
VertexManager::Flush();
|
2009-03-07 23:01:58 +00:00
|
|
|
((u32*)&bpmem)[addr] = newval;
|
2009-02-28 22:10:38 +00:00
|
|
|
int num = (addr >> 1) & 0x3;
|
|
|
|
PixelShaderManager::SetColorChanged(bpmem.tevregs[num].high.type, num);
|
2009-03-07 23:01:58 +00:00
|
|
|
} else
|
|
|
|
((u32*)&bpmem)[addr] = newval;
|
2009-02-28 22:10:38 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
switch (addr&0xF0)
|
|
|
|
{
|
|
|
|
case 0x10: // tevindirect 0-15
|
|
|
|
if (changes) {
|
|
|
|
VertexManager::Flush();
|
|
|
|
((u32*)&bpmem)[addr] = newval;
|
|
|
|
PixelShaderManager::SetTevIndirectChanged(addr - 0x10);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x30:
|
|
|
|
if (changes) {
|
|
|
|
VertexManager::Flush();
|
|
|
|
((u32*)&bpmem)[addr] = newval;
|
|
|
|
PixelShaderManager::SetTexDimsChanged((addr >> 1) & 0x7);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0xC0:
|
|
|
|
case 0xD0:
|
|
|
|
if (changes)
|
|
|
|
{
|
|
|
|
VertexManager::Flush();
|
|
|
|
((u32*)&bpmem)[addr] = newval;
|
|
|
|
PixelShaderManager::SetTevCombinerChanged((addr & 0x1f)/2);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x20:
|
|
|
|
case 0x80:
|
|
|
|
case 0x90:
|
|
|
|
case 0xA0:
|
|
|
|
case 0xB0:
|
|
|
|
default:
|
2009-03-07 23:01:58 +00:00
|
|
|
if (changes)
|
|
|
|
{
|
|
|
|
VertexManager::Flush();
|
|
|
|
((u32*)&bpmem)[addr] = newval;
|
|
|
|
}
|
2009-02-28 22:10:38 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|