From 1578e3e195bef30dc0bbf02aed39827ecd0d0e9c Mon Sep 17 00:00:00 2001 From: omegadox Date: Sun, 5 Apr 2009 10:49:19 +0000 Subject: [PATCH] Recoded and moved BPStucts to VideoCommon. Some cleanup in PixelShaderManager. TODO: Have DX use BPFunctions. Note: Compiling DX plugin will not work atm. git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@2870 8ced0084-cf51-0410-be5f-012b33b47a6e --- Source/Core/VideoCommon/Src/BPFunctions.h | 60 + Source/Core/VideoCommon/Src/BPMemory.cpp | 11 +- Source/Core/VideoCommon/Src/BPMemory.h | 85 +- Source/Core/VideoCommon/Src/BPStructs.cpp | 486 ++++++ .../VideoCommon}/Src/BPStructs.h | 54 +- .../VideoCommon/Src/PixelShaderManager.cpp | 25 - .../Core/VideoCommon/Src/PixelShaderManager.h | 10 +- Source/Core/VideoCommon/Src/SConscript | 1 + Source/Core/VideoCommon/VideoCommon.vcproj | 14 +- .../Plugin_VideoDX9/Plugin_VideoDX9.vcproj | 4 + .../Plugin_VideoDX9/Src/BPFunctions.cpp | 99 ++ .../Plugins/Plugin_VideoDX9/Src/BPStructs.cpp | 1 - .../Plugin_VideoOGL/Plugin_VideoOGL.vcproj | 6 +- .../Plugin_VideoOGL/Src/BPFunctions.cpp | 255 ++++ ...BPStructs.cpp => BPStructs.cpp.backup.txt} | 1328 ++++++++--------- Source/Plugins/Plugin_VideoOGL/Src/SConscript | 1 + 16 files changed, 1652 insertions(+), 788 deletions(-) create mode 100644 Source/Core/VideoCommon/Src/BPFunctions.h create mode 100644 Source/Core/VideoCommon/Src/BPStructs.cpp rename Source/{Plugins/Plugin_VideoOGL => Core/VideoCommon}/Src/BPStructs.h (96%) create mode 100644 Source/Plugins/Plugin_VideoDX9/Src/BPFunctions.cpp create mode 100644 Source/Plugins/Plugin_VideoOGL/Src/BPFunctions.cpp rename Source/Plugins/Plugin_VideoOGL/Src/{BPStructs.cpp => BPStructs.cpp.backup.txt} (90%) diff --git a/Source/Core/VideoCommon/Src/BPFunctions.h b/Source/Core/VideoCommon/Src/BPFunctions.h new file mode 100644 index 0000000000..e7442f5c7f --- /dev/null +++ b/Source/Core/VideoCommon/Src/BPFunctions.h @@ -0,0 +1,60 @@ +// Copyright (C) 2003-2009 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/ + + +// ------------------------------------------ +// The plugins has to define these functions +// ------------------------------------------ + +#ifndef _BPFUNCTIONS_H_ +#define _BPFUNCTIONS_H_ + +#include "BPMemory.h" +#include "VideoCommon.h" + +namespace BPFunctions +{ + +enum +{ + CONFIG_ISWII = 0, + CONFIG_DISABLEFOG, + CONFIG_SHOWEFBREGIONS +}; + +void FlushPipeline(); +void SetGenerationMode(); +void SetScissor(const BreakPoint &bp); +void SetLineWidth(); +void SetDepthMode(); +void SetBlendMode(); +void SetDitherMode(); +void SetLogicOpMode(); +void SetColorMask(); +float GetRendererTargetScaleX(); +float GetRendererTargetScaleY(); +void CopyEFB(const TRectangle &rc, const u32 &address, const bool &fromZBuffer, const bool &isIntensityFmt, const u32 ©fmt, const bool &scaleByHalf); +void RenderToXFB(const TRectangle &multirc, const float &yScale, const float &xfbLines, u8* pXFB, const u32 &dstWidth, const u32 &dstHeight); +void ClearScreen(const TRectangle &multirc); +void RestoreRenderState(); +void SetScissorRectangle(); +u8 *GetPointer(const u32 &address); +bool GetConfig(const int &type); + +}; + +#endif // _BPFUNCTIONS_H_ \ No newline at end of file diff --git a/Source/Core/VideoCommon/Src/BPMemory.cpp b/Source/Core/VideoCommon/Src/BPMemory.cpp index 3444f2fa74..a055fbcaeb 100644 --- a/Source/Core/VideoCommon/Src/BPMemory.cpp +++ b/Source/Core/VideoCommon/Src/BPMemory.cpp @@ -24,7 +24,7 @@ BPMemory bpmem; // The plugin must implement this. -void BPWritten(int addr, int changes, int newval); +void BPWritten(const BreakPoint& bp); // Call browser: OpcodeDecoding.cpp ExecuteDisplayList > Decode() > LoadBPReg() void LoadBPReg(u32 value0) @@ -34,10 +34,14 @@ void LoadBPReg(u32 value0) int oldval = ((u32*)&bpmem)[opcode]; int newval = (oldval & ~bpmem.bpMask) | (value0 & bpmem.bpMask); int changes = (oldval ^ newval) & 0xFFFFFF; + + BreakPoint bp = {opcode, changes, newval}; + //reset the mask register if (opcode != 0xFE) bpmem.bpMask = 0xFFFFFF; - BPWritten(opcode, changes, newval); + + BPWritten(bp); } // Called when loading a saved state. @@ -57,7 +61,8 @@ void BPReload() // Cases in which we DON'T want to reload the BP continue; default: - BPWritten(i, 0xFFFFFF, ((u32*)&bpmem)[i]); + BreakPoint bp = {i, 0xFFFFFF, ((u32*)&bpmem)[i]}; + BPWritten(bp); } } } diff --git a/Source/Core/VideoCommon/Src/BPMemory.h b/Source/Core/VideoCommon/Src/BPMemory.h index 441a427590..43e7ce114c 100644 --- a/Source/Core/VideoCommon/Src/BPMemory.h +++ b/Source/Core/VideoCommon/Src/BPMemory.h @@ -23,39 +23,81 @@ #pragma pack(4) #define BPMEM_GENMODE 0x00 -#define BPMEM_IND_MTX 0x06 -#define BPMEM_RAS1_SS0 0x25 // ind tex coord scale 0 -#define BPMEM_RAS1_SS1 0x26 // ind tex coord scale 1 +#define BPMEM_DISPLAYCOPYFILER 0x01 // 0x01 + 4 +#define BPMEM_IND_MTXA 0x06 // 0x06 + (3 * 3) +#define BPMEM_IND_MTXB 0x07 // 0x07 + (3 * 3) +#define BPMEM_IND_MTXC 0x08 // 0x08 + (3 * 3) +#define BPMEM_IND_IMASK 0x0F +#define BPMEM_IND_CMD 0x10 // 0x10 + 16 +#define BPMEM_SCISSORTL 0x20 +#define BPMEM_SCISSORBR 0x21 +#define BPMEM_LINEPTWIDTH 0x22 +#define BPMEM_SU_COUNTER 0x23 +#define BPMEM_RAS_COUNTER 0x24 +#define BPMEM_RAS1_SS0 0x25 +#define BPMEM_RAS1_SS1 0x26 +#define BPMEM_IREF 0x27 +#define BPMEM_TREF 0x28 // 0x28 + 8 +#define BPMEM_SU_SSIZE 0x30 // 0x30 + (2 * 8) +#define BPMEM_SU_TSIZE 0x31 // 0x31 + (2 * 8) #define BPMEM_ZMODE 0x40 #define BPMEM_BLENDMODE 0x41 #define BPMEM_CONSTANTALPHA 0x42 #define BPMEM_PE_CONTROL 0x43 +#define BPMEM_FIELDMASK 0x44 #define BPMEM_SETDRAWDONE 0x45 +#define BPMEM_CLOCK0 0x46 +#define BPMEM_PE_TOKEN_ID 0x47 +#define BPMEM_PE_TOKEN_INT_ID 0x48 +#define BPMEM_EFB_TL 0x49 +#define BPMEM_EFB_BR 0x4A +#define BPMEM_EFB_ADDR 0x4B +#define BPMEM_MIPMAP_STRIDE 0x4D +#define BPMEM_COPYYSCALE 0x4E +#define BPMEM_CLEAR_AR 0x4F +#define BPMEM_CLEAR_GB 0x50 +#define BPMEM_CLEAR_Z 0x51 #define BPMEM_TRIGGER_EFB_COPY 0x52 -#define BPMEM_ALPHACOMPARE 0xF3 -#define BPMEM_LINEPTWIDTH 0x22 -#define BPMEM_LOADTLUT 0x65 -#define BPMEM_SETGPMETRIC 0x67 -#define BPMEM_TEXINVALIDATE 0x66 -#define BPMEM_SCISSORTL 0x20 -#define BPMEM_SCISSORBR 0x21 +#define BPMEM_COPYFILTER0 0x53 +#define BPMEM_COPYFILTER1 0x54 +#define BPMEM_CLEARBBOX1 0x55 +#define BPMEM_CLEARBBOX2 0x56 #define BPMEM_SCISSOROFFSET 0x59 -#define BPMEM_CLEARBBOX1 0x55 // let's hope not many games use bboxes.. -#define BPMEM_CLEARBBOX2 0x56 // TODO(ector): add something that watches bboxes -#define BPMEM_TEXMODE0_1 0x80 -#define BPMEM_TEXMODE0_2 0xA0 +#define BPMEM_LOADTLUT0 0x64 +#define BPMEM_LOADTLUT1 0x65 +#define BPMEM_TEXINVALIDATE 0x66 +#define BPMEM_SETGPMETRIC 0x67 +#define BPMEM_FIELDMODE 0x68 +#define BPMEM_CLOCK1 0x69 +#define BPMEM_TX_SETMODE0 0x80 // 0x80 + 4 +#define BPMEM_TX_SETMODE1 0x84 // 0x84 + 4 +#define BPMEM_TX_SETIMAGE0 0x88 // 0x88 + 4 +#define BPMEM_TX_SETIMAGE1 0x8C // 0x8C + 4 +#define BPMEM_TX_SETIMAGE2 0x90 // 0x90 + 4 +#define BPMEM_TX_SETIMAGE3 0x94 // 0x94 + 4 +#define BPMEM_TX_LOADTLUT_0 0x98 // 0x98 + 4, This smells wrong, I think it should be SET +#define BPMEM_TX_SETMODE0_4 0xA0 // 0xA0 + 4 +#define BPMEM_TX_SETMODE1_4 0xA4 // 0xA4 + 4 +#define BPMEM_TX_SETIMAGE0_4 0xA8 // 0xA8 + 4 +#define BPMEM_TX_SETIMAGE1_4 0xAC // 0xA4 + 4 +#define BPMEM_TX_SETIMAGE2_4 0xB0 // 0xB0 + 4 +#define BPMEM_TX_SETIMAGE3_4 0xB4 // 0xB4 + 4 +#define BPMEM_TX_SETLUT_4 0xB8 // 0xB8 + 4 +#define BPMEM_TEV_COLOR_ENV 0xC0 // 0xC0 + (2 * 16) +#define BPMEM_TEV_ALPHA_ENV 0xC1 // 0xC1 + (2 * 16) +#define BPMEM_TEV_REGISTER_L 0xE0 // 0xE0 + (2 * 4) +#define BPMEM_TEV_REGISTER_H 0xE1 // 0xE1 + (2 * 4) #define BPMEM_FOGRANGE 0xE8 #define BPMEM_FOGPARAM0 0xEE #define BPMEM_FOGBMAGNITUDE 0xEF #define BPMEM_FOGBEXPONENT 0xF0 #define BPMEM_FOGPARAM3 0xF1 #define BPMEM_FOGCOLOR 0xF2 +#define BPMEM_ALPHACOMPARE 0xF3 #define BPMEM_ZTEX1 0xF4 #define BPMEM_ZTEX2 0xF5 -#define BPMEM_DRAWDONE 0x45 - -#define BPMEM_PE_TOKEN_ID 0x47 -#define BPMEM_PE_TOKEN_INT_ID 0x48 +#define BPMEM_TEV_KSEL 0xF6 // 0xF6 + 8 +#define BPMEM_BP_MASK 0xFE ////////////////////////////////////////////////////////////////////////// // Tev/combiner things @@ -779,6 +821,13 @@ union UPE_Copy // All of BP memory ////////////////////////////////////////////////////////////////////////// +struct BreakPoint +{ + int address; + int changes; + int newvalue; +}; + struct BPMemory { GenMode genMode; diff --git a/Source/Core/VideoCommon/Src/BPStructs.cpp b/Source/Core/VideoCommon/Src/BPStructs.cpp new file mode 100644 index 0000000000..d33519104a --- /dev/null +++ b/Source/Core/VideoCommon/Src/BPStructs.cpp @@ -0,0 +1,486 @@ +// Copyright (C) 2003-2009 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 "Profiler.h" +#include "Statistics.h" +#include "VideoCommon.h" +#include "PixelShaderManager.h" +#include "BPFunctions.h" +#include "BPStructs.h" +#include "TextureDecoder.h" +#include "OpcodeDecoding.h" +#include "VertexLoader.h" +#include "VertexShaderManager.h" + +using namespace BPFunctions; + +void BPInit() +{ + memset(&bpmem, 0, sizeof(bpmem)); + bpmem.bpMask = 0xFFFFFF; +} + +// ---------------------------------------------------------------------------------------------------------- +// Write to the BreakPoint Memory +/* ------------------ + Called: + At the end of every: OpcodeDecoding.cpp ExecuteDisplayList > Decode() > LoadBPReg + TODO: + Turn into function table. The (future) DisplayList (DL) jit can then call the functions directly, + getting rid of dynamic dispatch. Unfortunately, few games use DLs properly - most\ + just stuff geometry in them and don't put state changes there. */ +// ---------------------------------------------------------------------------------------------------------- +void BPWritten(const BreakPoint& bp) +{ + // If nothing changed, return + //if ((bp.changes == 0 ? false : true)) + // return; + + // Flush the pipeline then update the BreakPoint Memory + FlushPipeline(); + ((u32*)&bpmem)[bp.address] = bp.newvalue; + + switch (bp.address) + { + // ----------------------------------------------------- + // BPs that calls other code besides updating the memory + // ----------------------------------------------------- + case BPMEM_GENMODE: + PRIM_LOG("genmode: texgen=%d, col=%d, ms_en=%d, tev=%d, culmode=%d, ind=%d, zfeeze=%d", + bpmem.genMode.numtexgens, bpmem.genMode.numcolchans, + bpmem.genMode.ms_en, bpmem.genMode.numtevstages+1, bpmem.genMode.cullmode, + bpmem.genMode.numindstages, bpmem.genMode.zfreeze); + SetGenerationMode(); + break; + case BPMEM_IND_MTXA: + case BPMEM_IND_MTXB: + case BPMEM_IND_MTXC: + case BPMEM_IND_MTXA+3: + case BPMEM_IND_MTXB+3: + case BPMEM_IND_MTXC+3: + case BPMEM_IND_MTXA+6: + case BPMEM_IND_MTXB+6: + case BPMEM_IND_MTXC+6: + PixelShaderManager::SetIndMatrixChanged((bp.address - BPMEM_IND_MTXA) / 3); + break; + case BPMEM_RAS1_SS0: // Index Texture Coordinate Scale 0 + case BPMEM_RAS1_SS1: // Index Texture Coordinate Scale 1 + PixelShaderManager::SetIndTexScaleChanged(); + break; + case BPMEM_SCISSORTL: // Scissor Rectable Top, Left + case BPMEM_SCISSORBR: // Scissor Rectable Bottom, Right + SetScissor(bp); + break; + case BPMEM_LINEPTWIDTH: + SetLineWidth(); + break; + case BPMEM_ZMODE: + PRIM_LOG("zmode: test=%d, func=%d, upd=%d", bpmem.zmode.testenable, bpmem.zmode.func, + bpmem.zmode.updateenable); + SetDepthMode(); + break; + case BPMEM_BLENDMODE: + if (bp.changes & 0xFFFF) + { + PRIM_LOG("blendmode: en=%d, open=%d, colupd=%d, alphaupd=%d, dst=%d, src=%d, sub=%d, mode=%d", + bpmem.blendmode.blendenable, bpmem.blendmode.logicopenable, bpmem.blendmode.colorupdate, bpmem.blendmode.alphaupdate, + bpmem.blendmode.dstfactor, bpmem.blendmode.srcfactor, bpmem.blendmode.subtract, bpmem.blendmode.logicmode); + // Set LogicOp Blending Mode + if (bp.changes & 2) + { + SETSTAT(stats.logicOpMode, bpmem.blendmode.logicopenable != 0 ? bpmem.blendmode.logicmode : stats.logicOpMode); + SetLogicOpMode(); + } + // Set Dithering Mode + if (bp.changes & 4) + { + SETSTAT(stats.dither, bpmem.blendmode.dither); + SetDitherMode(); + } + // Set Blending Mode + if (bp.changes & 0xFE1) + { + SETSTAT(stats.srcFactor, bpmem.blendmode.srcfactor); + SETSTAT(stats.dstFactor, bpmem.blendmode.dstfactor); + SetBlendMode(); + } + // Set Color Mask + if (bp.changes & 0x18) + { + SETSTAT(stats.alphaUpdate, bpmem.blendmode.alphaupdate); + SETSTAT(stats.colorUpdate, bpmem.blendmode.colorupdate); + SetColorMask(); + } + } + break; + case BPMEM_CONSTANTALPHA: + PRIM_LOG("constalpha: alp=%d, en=%d", bpmem.dstalpha.alpha, bpmem.dstalpha.enable); + SETSTAT(stats.dstAlphaEnable, bpmem.dstalpha.enable); + SETSTAT_UINT(stats.dstAlpha, bpmem.dstalpha.alpha); + PixelShaderManager::SetDestAlpha(bpmem.dstalpha); + break; + case BPMEM_SETDRAWDONE: + switch (bp.newvalue & 0xFF) + { + case 0x02: + g_VideoInitialize.pSetPEFinish(); // may generate interrupt + DEBUG_LOG(VIDEO, "GXSetDrawDone SetPEFinish (value: 0x%02X)", (bp.newvalue & 0xFFFF)); + break; + + default: + DEBUG_LOG(VIDEO, "GXSetDrawDone ??? (value 0x%02X)", (bp.newvalue & 0xFFFF)); + break; + } + break; + case BPMEM_PE_TOKEN_ID: + g_VideoInitialize.pSetPEToken(static_cast(bp.newvalue & 0xFFFF), FALSE); + DEBUG_LOG(VIDEO, "SetPEToken 0x%04x", (bp.newvalue & 0xFFFF)); + break; + case BPMEM_PE_TOKEN_INT_ID: + g_VideoInitialize.pSetPEToken(static_cast(bp.newvalue & 0xFFFF), TRUE); + DEBUG_LOG(VIDEO, "SetPEToken + INT 0x%04x", (bp.newvalue & 0xFFFF)); + break; + // ------------------------ + // EFB copy command. This copies a rectangle from the EFB to either RAM in a texture format or to XFB as YUYV. + // It can also optionally clear the EFB while copying from it. To emulate this, we of course copy first and clear afterwards. + case BPMEM_TRIGGER_EFB_COPY: + { + DVSTARTSUBPROFILE("LoadBPReg:swap"); + // The bottom right is within the rectangle + // The values in bpmem.copyTexSrcXY and bpmem.copyTexSrcWH are updated in case 0x49 and 0x4a in this function + TRectangle rc = { + (int)(bpmem.copyTexSrcXY.x), + (int)(bpmem.copyTexSrcXY.y), + (int)((bpmem.copyTexSrcXY.x + bpmem.copyTexSrcWH.x + 1)), + (int)((bpmem.copyTexSrcXY.y + bpmem.copyTexSrcWH.y + 1)) + }; + + float MValueX = GetRendererTargetScaleX(); + float MValueY = GetRendererTargetScaleY(); + // Need another rc here to get it to scale. + // Here the bottom right is the out of the rectangle. + TRectangle multirc = { + (int)(bpmem.copyTexSrcXY.x * MValueX), + (int)(bpmem.copyTexSrcXY.y * MValueY), + (int)((bpmem.copyTexSrcXY.x * MValueX + (bpmem.copyTexSrcWH.x + 1) * MValueX)), + (int)((bpmem.copyTexSrcXY.y * MValueY + (bpmem.copyTexSrcWH.y + 1) * MValueY)) + }; + UPE_Copy PE_copy; + PE_copy.Hex = bpmem.triggerEFBCopy; + // ---------------------------------------------------------- + // Check to where we should copy the image data from the EFB. + // ---------------------------------------------------------- + if (PE_copy.copy_to_xfb == 0) + { + if (GetConfig(CONFIG_SHOWEFBREGIONS)) + stats.efb_regions.push_back(rc); + u32 address = bpmem.copyTexDest << 5; + bool fromZBuffer = (bpmem.zcontrol.pixel_format == PIXELFMT_Z24); + bool isIntensity = (PE_copy.intensity_fmt > 0); + u32 copyFormat = ((PE_copy.target_pixel_format / 2) + ((PE_copy.target_pixel_format & 1) * 8)); + bool scaleByHalf = (PE_copy.half_scale > 0); + CopyEFB(rc, address, fromZBuffer, isIntensity, copyFormat, scaleByHalf); + } + else + { + // the number of lines copied is determined by the y scale * source efb height + float yScale = bpmem.dispcopyyscale / 256.0f; + float xfbLines = bpmem.copyTexSrcWH.y + 1.0f * yScale; + u8* pXFB = Memory_GetPtr(bpmem.copyTexDest << 5); + u32 dstWidth = (bpmem.copyMipMapStrideChannels << 4); + u32 dstHeight = (u32)xfbLines; + RenderToXFB(multirc, yScale, xfbLines, pXFB, dstWidth, dstHeight); + } + + // ---------------------------------------------------------------------------------- + // Clear the picture after it's done and submitted, to prepare for the next picture + // ---------------------------------------------------------------------------------- + if (PE_copy.clear) + ClearScreen(multirc); + + RestoreRenderState(); + + break; + } + case BPMEM_SCISSOROFFSET: + SetScissorRectangle(); + break; + case BPMEM_LOADTLUT0: + case BPMEM_LOADTLUT1: + { + DVSTARTSUBPROFILE("LoadBPReg:GXLoadTlut"); + + u32 tlutTMemAddr = (bp.newvalue & 0x3FF) << 9; + u32 tlutXferCount = (bp.newvalue & 0x1FFC00) >> 5; + + u8 *ptr = 0; + + // TODO - figure out a cleaner way. + if (GetConfig(CONFIG_ISWII)) + ptr = GetPointer(bpmem.tlutXferSrc << 5); + else + ptr = GetPointer((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); + + // 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; + case BPMEM_FOGRANGE: + case BPMEM_FOGPARAM0: + case BPMEM_FOGBMAGNITUDE: + case BPMEM_FOGBEXPONENT: + case BPMEM_FOGPARAM3: + if(!GetConfig(CONFIG_DISABLEFOG)) + PixelShaderManager::SetFogParamChanged(); + break; + case BPMEM_FOGCOLOR: + PixelShaderManager::SetFogColorChanged(); + break; + case BPMEM_ALPHACOMPARE: + PRIM_LOG("alphacmp: ref0=%d, ref1=%d, comp0=%d, comp1=%d, logic=%d", bpmem.alphaFunc.ref0, + bpmem.alphaFunc.ref1, bpmem.alphaFunc.comp0, bpmem.alphaFunc.comp1, bpmem.alphaFunc.logic); + PixelShaderManager::SetAlpha(bpmem.alphaFunc); + break; + case BPMEM_ZTEX1: // BIAS + PRIM_LOG("ztex bias=0x%x", bpmem.ztex1.bias); + PixelShaderManager::SetZTextureBias(bpmem.ztex1.bias); + break; + case BPMEM_ZTEX2: + if (bp.changes & 3) + PixelShaderManager::SetZTextureTypeChanged(); + #if defined(_DEBUG) || defined(DEBUGFAST) + const char* pzop[] = {"DISABLE", "ADD", "REPLACE", "?"}; + const char* pztype[] = {"Z8", "Z16", "Z24", "?"}; + PRIM_LOG("ztex op=%s, type=%s", pzop[bpmem.ztex2.op], pztype[bpmem.ztex2.type]); + #endif + break; + + // -------------------------------------- + // BPs that only flush and update memory + // -------------------------------------- + case BPMEM_DISPLAYCOPYFILER: + case BPMEM_DISPLAYCOPYFILER+1: + case BPMEM_DISPLAYCOPYFILER+2: + case BPMEM_DISPLAYCOPYFILER+3: + case BPMEM_IND_IMASK: + case BPMEM_SU_COUNTER: + case BPMEM_RAS_COUNTER: + case BPMEM_IREF: + case BPMEM_PE_CONTROL: + case BPMEM_FIELDMASK: + case BPMEM_CLOCK0: + case BPMEM_EFB_TL: // EFB Source Rect. Top, Left + case BPMEM_EFB_BR: // EFB Source Rect. Bottom, Right (w, h - 1) + case BPMEM_EFB_ADDR: // EFB Target Address + case BPMEM_MIPMAP_STRIDE: // MipMap Stride Channel + case BPMEM_COPYYSCALE: // Display Copy Y Scale + case BPMEM_CLEAR_AR: // Set Clear Alpha and Red Components + case BPMEM_CLEAR_GB: // Green and Blue + case BPMEM_CLEAR_Z: // Clear Z, 24-bit Z Value + case BPMEM_COPYFILTER0: + case BPMEM_COPYFILTER1: + case BPMEM_CLEARBBOX1: // let's hope not many games use bboxes.. + case BPMEM_CLEARBBOX2: // TODO(ector): add something that watches bboxes + case BPMEM_TEXINVALIDATE: + case BPMEM_SETGPMETRIC: // Debugging info + case BPMEM_FIELDMODE: + case BPMEM_CLOCK1: + case BPMEM_TEV_KSEL: // Texture Environment Swap Mode Table 0 + case BPMEM_TEV_KSEL+1:// Texture Environment Swap Mode Table 1 + case BPMEM_TEV_KSEL+2:// Texture Environment Swap Mode Table 2 + case BPMEM_TEV_KSEL+3:// Texture Environment Swap Mode Table 3 + case BPMEM_TEV_KSEL+4:// Texture Environment Swap Mode Table 4 + case BPMEM_TEV_KSEL+5:// Texture Environment Swap Mode Table 5 + case BPMEM_TEV_KSEL+6:// Texture Environment Swap Mode Table 6 + case BPMEM_TEV_KSEL+7:// Texture Environment Swap Mode Table 7 + case BPMEM_BP_MASK: + break; + + // ------------------------------------------------ + // On Default, we try to look for other things + // before we give up and say its an unknown opcode + // ------------------------------------------------ + default: + switch (bp.address & 0xFC) // Texture sampler filter + { + case BPMEM_TREF: // Texture Environment Order + case BPMEM_TREF+1: + case BPMEM_TREF+2: + case BPMEM_TREF+3: + case BPMEM_TREF+4: + case BPMEM_TREF+5: + case BPMEM_TREF+6: + case BPMEM_TREF+7: + case BPMEM_SU_SSIZE: // Texture Wrap Size U? + case BPMEM_SU_TSIZE: // Texture Wrap Size V? + case BPMEM_SU_SSIZE+2: + case BPMEM_SU_TSIZE+2: + case BPMEM_SU_SSIZE+4: + case BPMEM_SU_TSIZE+4: + case BPMEM_SU_SSIZE+6: + case BPMEM_SU_TSIZE+6: + case BPMEM_SU_SSIZE+8: + case BPMEM_SU_TSIZE+8: + case BPMEM_SU_SSIZE+10: + case BPMEM_SU_TSIZE+10: + case BPMEM_SU_SSIZE+12: + case BPMEM_SU_TSIZE+12: + case BPMEM_SU_SSIZE+14: + case BPMEM_SU_TSIZE+14: + case BPMEM_TX_SETMODE0: // 0x90 for Linear, Index 0 + case BPMEM_TX_SETMODE0+1: + case BPMEM_TX_SETMODE0+2: + case BPMEM_TX_SETMODE0+3: // Index 4 + case BPMEM_TX_SETMODE1: + case BPMEM_TX_SETMODE1+1: + case BPMEM_TX_SETMODE1+2: + case BPMEM_TX_SETMODE1+3: + case BPMEM_TX_SETIMAGE0: // Texture Size ? + case BPMEM_TX_SETIMAGE0+1: + case BPMEM_TX_SETIMAGE0+2: + case BPMEM_TX_SETIMAGE0+3: + case BPMEM_TX_SETIMAGE1: + case BPMEM_TX_SETIMAGE1+1: + case BPMEM_TX_SETIMAGE1+2: + case BPMEM_TX_SETIMAGE1+3: + case BPMEM_TX_SETIMAGE2: + case BPMEM_TX_SETIMAGE2+1: + case BPMEM_TX_SETIMAGE2+2: + case BPMEM_TX_SETIMAGE2+3: + case BPMEM_TX_SETIMAGE3: // Texture Pointer + case BPMEM_TX_SETIMAGE3+1: + case BPMEM_TX_SETIMAGE3+2: + case BPMEM_TX_SETIMAGE3+3: + case BPMEM_TX_LOADTLUT_0: // wtf? Load TLUT 0 here ?? (THIS HAS TO BE SET TLUT NOT LOAD TLUT !! :P, mistake found in YAGD!) + case BPMEM_TX_LOADTLUT_0+1: + case BPMEM_TX_LOADTLUT_0+2: + case BPMEM_TX_LOADTLUT_0+3: + case BPMEM_TX_SETMODE0_4: // This is Mode 0 for Index 5 to 8 + case BPMEM_TX_SETMODE0_4+1: + case BPMEM_TX_SETMODE0_4+2: + case BPMEM_TX_SETMODE0_4+3: + case BPMEM_TX_SETMODE1_4: // This is Mode 1 for Index 5 to 8 + case BPMEM_TX_SETMODE1_4+1: + case BPMEM_TX_SETMODE1_4+2: + case BPMEM_TX_SETMODE1_4+3: + case BPMEM_TX_SETIMAGE0_4: // This is Image 0 for Index 5 to 8 + case BPMEM_TX_SETIMAGE0_4+1: + case BPMEM_TX_SETIMAGE0_4+2: + case BPMEM_TX_SETIMAGE0_4+3: + case BPMEM_TX_SETIMAGE1_4: // This is Image 1 for Index 5 to 8 + case BPMEM_TX_SETIMAGE1_4+1: + case BPMEM_TX_SETIMAGE1_4+2: + case BPMEM_TX_SETIMAGE1_4+3: + case BPMEM_TX_SETIMAGE2_4: // This is Image 2 for Index 5 to 8 + case BPMEM_TX_SETIMAGE2_4+1: + case BPMEM_TX_SETIMAGE2_4+2: + case BPMEM_TX_SETIMAGE2_4+3: + case BPMEM_TX_SETIMAGE3_4: // This is Image 3 for Index 5 to 8 + case BPMEM_TX_SETIMAGE3_4+1: + case BPMEM_TX_SETIMAGE3_4+2: + case BPMEM_TX_SETIMAGE3_4+3: + case BPMEM_TX_SETLUT_4: // This is Setting TLUT for Index 5 to 8 + case BPMEM_TX_SETLUT_4+1: + case BPMEM_TX_SETLUT_4+2: + case BPMEM_TX_SETLUT_4+3: + break; + case BPMEM_TEV_REGISTER_L: // Reg 1 + case BPMEM_TEV_REGISTER_H: + case BPMEM_TEV_REGISTER_L+2: // Reg 2 + case BPMEM_TEV_REGISTER_H+2: + case BPMEM_TEV_REGISTER_L+4: // Reg 3 + case BPMEM_TEV_REGISTER_H+4: + case BPMEM_TEV_REGISTER_L+6: // Reg 4 + case BPMEM_TEV_REGISTER_H+6: + if (bp.address & 1) + { + // don't compare with changes! + int num = (bp.address >> 1 ) & 0x3; + PixelShaderManager::SetColorChanged(bpmem.tevregs[num].high.type, num); + } + break; + // ------------------------------------------------ + // On Default, we try to look for other things + // before we give up and say its an unknown opcode + // again ... + // ------------------------------------------------ + default: + switch (bp.address & 0xF0) + { + case BPMEM_IND_CMD: + case BPMEM_IND_CMD+1: + case BPMEM_IND_CMD+2: + case BPMEM_IND_CMD+3: + case BPMEM_IND_CMD+4: + case BPMEM_IND_CMD+5: + case BPMEM_IND_CMD+6: + case BPMEM_IND_CMD+7: + case BPMEM_IND_CMD+8: + case BPMEM_IND_CMD+9: + case BPMEM_IND_CMD+10: + case BPMEM_IND_CMD+11: + case BPMEM_IND_CMD+12: + case BPMEM_IND_CMD+13: + case BPMEM_IND_CMD+14: + case BPMEM_IND_CMD+15: + case BPMEM_TEV_COLOR_ENV: // Texture Environment 1 + case BPMEM_TEV_ALPHA_ENV: + case BPMEM_TEV_COLOR_ENV+2: // Texture Environment 2 + case BPMEM_TEV_ALPHA_ENV+2: + case BPMEM_TEV_COLOR_ENV+4: // Texture Environment 3 + case BPMEM_TEV_ALPHA_ENV+4: + case BPMEM_TEV_COLOR_ENV+8: // Texture Environment 4 + case BPMEM_TEV_ALPHA_ENV+8: + case BPMEM_TEV_COLOR_ENV+10: // Texture Environment 5 + case BPMEM_TEV_ALPHA_ENV+10: + case BPMEM_TEV_COLOR_ENV+12: // Texture Environment 6 + case BPMEM_TEV_ALPHA_ENV+12: + case BPMEM_TEV_COLOR_ENV+14: // Texture Environment 7 + case BPMEM_TEV_ALPHA_ENV+14: + case BPMEM_TEV_COLOR_ENV+16: // Texture Environment 8 + case BPMEM_TEV_ALPHA_ENV+16: + case BPMEM_TEV_COLOR_ENV+18: // Texture Environment 9 + case BPMEM_TEV_ALPHA_ENV+18: + case BPMEM_TEV_COLOR_ENV+20: // Texture Environment 10 + case BPMEM_TEV_ALPHA_ENV+20: + case BPMEM_TEV_COLOR_ENV+22: // Texture Environment 11 + case BPMEM_TEV_ALPHA_ENV+22: + case BPMEM_TEV_COLOR_ENV+24: // Texture Environment 12 + case BPMEM_TEV_ALPHA_ENV+24: + case BPMEM_TEV_COLOR_ENV+26: // Texture Environment 13 + case BPMEM_TEV_ALPHA_ENV+26: + case BPMEM_TEV_COLOR_ENV+28: // Texture Environment 14 + case BPMEM_TEV_ALPHA_ENV+28: + case BPMEM_TEV_COLOR_ENV+30: // Texture Environment 15 + case BPMEM_TEV_ALPHA_ENV+30: + case BPMEM_TEV_COLOR_ENV+32: // Texture Environment 16 + case BPMEM_TEV_ALPHA_ENV+32: + break; + default: + WARN_LOG(VIDEO, "Unknown BreakPoint opcode: address = %08x value = %08x", bp.address, bp.newvalue); + } + + } + + } +} + diff --git a/Source/Plugins/Plugin_VideoOGL/Src/BPStructs.h b/Source/Core/VideoCommon/Src/BPStructs.h similarity index 96% rename from Source/Plugins/Plugin_VideoOGL/Src/BPStructs.h rename to Source/Core/VideoCommon/Src/BPStructs.h index 815b337ad5..fa1100db29 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/BPStructs.h +++ b/Source/Core/VideoCommon/Src/BPStructs.h @@ -1,27 +1,27 @@ -// Copyright (C) 2003-2009 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/ - -#ifndef _BPSTRUCTS_H_ -#define _BPSTRUCTS_H_ - -#include "BPMemory.h" - -void BPInit(); -void LoadBPReg(u32 value0); -void BPReload(); - -#endif // _BPSTRUCTS_H_ +// Copyright (C) 2003-2009 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/ + +#ifndef _BPSTRUCTS_H_ +#define _BPSTRUCTS_H_ + +#include "BPMemory.h" + +void BPInit(); +void LoadBPReg(u32 value0); +void BPReload(); + +#endif // _BPSTRUCTS_H_ diff --git a/Source/Core/VideoCommon/Src/PixelShaderManager.cpp b/Source/Core/VideoCommon/Src/PixelShaderManager.cpp index 4774a02b2b..9c1d82c6c0 100644 --- a/Source/Core/VideoCommon/Src/PixelShaderManager.cpp +++ b/Source/Core/VideoCommon/Src/PixelShaderManager.cpp @@ -328,31 +328,6 @@ void PixelShaderManager::SetIndMatrixChanged(int matrixidx) { s_nIndTexMtxChanged |= 1 << matrixidx; } - -void PixelShaderManager::SetGenModeChanged() -{ -} - -void PixelShaderManager::SetTevCombinerChanged(int id) -{ -} - -void PixelShaderManager::SetTevKSelChanged(int id) -{ -} - -void PixelShaderManager::SetTevOrderChanged(int id) -{ -} - -void PixelShaderManager::SetTevIndirectChanged(int id) -{ -} - -void PixelShaderManager::SetZTextureOpChanged() -{ -} - void PixelShaderManager::SetZTextureTypeChanged() { s_bZTextureTypeChanged = true; diff --git a/Source/Core/VideoCommon/Src/PixelShaderManager.h b/Source/Core/VideoCommon/Src/PixelShaderManager.h index 2229f30082..94100a78bd 100644 --- a/Source/Core/VideoCommon/Src/PixelShaderManager.h +++ b/Source/Core/VideoCommon/Src/PixelShaderManager.h @@ -41,23 +41,15 @@ public: static void SetTexDims(int texmapid, u32 width, u32 height, u32 wraps, u32 wrapt); static void SetZTextureBias(u32 bias); static void SetViewport(float* viewport); - static void SetIndTexScaleChanged(); static void SetIndMatrixChanged(int matrixidx); - - static void SetGenModeChanged(); - static void SetTevCombinerChanged(int id); static void SetTevKSelChanged(int id); - static void SetTevOrderChanged(int id); - static void SetTevIndirectChanged(int id); - static void SetZTextureOpChanged(); static void SetZTextureTypeChanged(); + static void SetIndTexScaleChanged(); static void SetTexturesUsed(u32 nonpow2tex); static void SetTexDimsChanged(int texmapid); static void SetFogColorChanged(); static void SetFogParamChanged(); - static void SetColorMatrix(const float* pmatrix, const float* pfConstAdd); - static u32 GetTextureMask(); }; diff --git a/Source/Core/VideoCommon/Src/SConscript b/Source/Core/VideoCommon/Src/SConscript index 30e12b170d..1d00101deb 100644 --- a/Source/Core/VideoCommon/Src/SConscript +++ b/Source/Core/VideoCommon/Src/SConscript @@ -7,6 +7,7 @@ files = [ 'CPMemory.cpp', 'XFMemory.cpp', 'XFStructs.cpp', + 'BPStructs.cpp', 'memcpy_amd.cpp', 'LookUpTables.cpp', 'OpcodeDecoding.cpp', diff --git a/Source/Core/VideoCommon/VideoCommon.vcproj b/Source/Core/VideoCommon/VideoCommon.vcproj index ce86407495..a297dae3fc 100644 --- a/Source/Core/VideoCommon/VideoCommon.vcproj +++ b/Source/Core/VideoCommon/VideoCommon.vcproj @@ -1,7 +1,7 @@ + + + + + + diff --git a/Source/Plugins/Plugin_VideoDX9/Plugin_VideoDX9.vcproj b/Source/Plugins/Plugin_VideoDX9/Plugin_VideoDX9.vcproj index 00cc478d59..645568f690 100644 --- a/Source/Plugins/Plugin_VideoDX9/Plugin_VideoDX9.vcproj +++ b/Source/Plugins/Plugin_VideoDX9/Plugin_VideoDX9.vcproj @@ -1179,6 +1179,10 @@ + + diff --git a/Source/Plugins/Plugin_VideoDX9/Src/BPFunctions.cpp b/Source/Plugins/Plugin_VideoDX9/Src/BPFunctions.cpp new file mode 100644 index 0000000000..57242359c0 --- /dev/null +++ b/Source/Plugins/Plugin_VideoDX9/Src/BPFunctions.cpp @@ -0,0 +1,99 @@ +// Copyright (C) 2003-2009 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 "BPFunctions.h" + +namespace BPFunctions +{ + +void FlushPipeline() +{ + +} + +void SetGenerationMode() +{ + +} + +void SetScissor(const BreakPoint &bp) +{ + +} +void SetLineWidth() +{ + +} +void SetDepthMode() +{ + +} +void SetBlendMode() +{ + Renderer::SetBlendMode(false); +} +void SetDitherMode() +{ + +} +void SetLogicOpMode() +{ + +} +void SetColorMask() +{ + +} +float GetRendererTargetScaleX() +{ + return 0.0f; +} +float GetRendererTargetScaleY() +{ + return 0.0f; +} +void CopyEFB(const TRectangle &rc, const u32 &address, const bool &fromZBuffer, const bool &isIntensityFmt, const u32 ©fmt, const bool &scaleByHalf) +{ + +} + +void RenderToXFB(const TRectangle &multirc, const float &yScale, const float &xfbLines, u8* pXFB, const u32 &dstWidth, const u32 &dstHeight) +{ + +} +void ClearScreen(const TRectangle &multirc) +{ + +} + +void RestoreRenderState() +{ + +} + +void SetScissorRectangle() +{ +} +bool GetConfig(const int &type) +{ + return false; +} +u8 *GetPointer(const u32 &address) +{ + return NULL; +} +}; \ No newline at end of file diff --git a/Source/Plugins/Plugin_VideoDX9/Src/BPStructs.cpp b/Source/Plugins/Plugin_VideoDX9/Src/BPStructs.cpp index 452e61c7b3..7be5ed8a8a 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/BPStructs.cpp +++ b/Source/Plugins/Plugin_VideoDX9/Src/BPStructs.cpp @@ -137,7 +137,6 @@ void BPWritten(int addr, int changes, int newval) // dev->SetRenderState(D3DRS_COLORWRITEENABLE, write); Renderer::SetRenderState(D3DRS_COLORWRITEENABLE, write); } - PixelShaderManager::SetGenModeChanged(); } break; case BPMEM_IND_MTX+0: diff --git a/Source/Plugins/Plugin_VideoOGL/Plugin_VideoOGL.vcproj b/Source/Plugins/Plugin_VideoOGL/Plugin_VideoOGL.vcproj index abc7618137..2f6ad843d2 100644 --- a/Source/Plugins/Plugin_VideoOGL/Plugin_VideoOGL.vcproj +++ b/Source/Plugins/Plugin_VideoOGL/Plugin_VideoOGL.vcproj @@ -717,11 +717,7 @@ Name="Decoder" > - - 0) + { + glEnable(GL_CULL_FACE); + glFrontFace(bpmem.genMode.cullmode == 2 ? GL_CCW : GL_CW); + } + else + glDisable(GL_CULL_FACE); +} + + +void SetScissor(const BreakPoint &bp) +{ + if (!Renderer::SetScissorRect()) + if (bp.address == BPMEM_SCISSORBR) + ERROR_LOG(VIDEO, "bad scissor!"); +} +void SetLineWidth() +{ + float fratio = xfregs.rawViewport[0] != 0 ? ((float)Renderer::GetTargetWidth() / EFB_WIDTH) : 1.0f; + if (bpmem.lineptwidth.linesize > 0) + glLineWidth((float)bpmem.lineptwidth.linesize * fratio / 6.0f); // scale by ratio of widths + if (bpmem.lineptwidth.pointsize > 0) + glPointSize((float)bpmem.lineptwidth.pointsize * fratio / 6.0f); +} +void SetDepthMode() +{ + if (bpmem.zmode.testenable) + { + glEnable(GL_DEPTH_TEST); + glDepthMask(bpmem.zmode.updateenable ? GL_TRUE : GL_FALSE); + glDepthFunc(glCmpFuncs[bpmem.zmode.func]); + } + else + { + // if the test is disabled write is disabled too + glDisable(GL_DEPTH_TEST); + glDepthMask(GL_FALSE); + } + + if (!bpmem.zmode.updateenable) + Renderer::SetRenderMode(Renderer::RM_Normal); +} +void SetBlendMode() +{ + Renderer::SetBlendMode(false); +} +void SetDitherMode() +{ + if (bpmem.blendmode.dither) + glEnable(GL_DITHER); + else + glDisable(GL_DITHER); +} +void SetLogicOpMode() +{ + if (bpmem.blendmode.logicopenable) + { + glEnable(GL_COLOR_LOGIC_OP); + glLogicOp(glLogicOpCodes[bpmem.blendmode.logicmode]); + } + else + glDisable(GL_COLOR_LOGIC_OP); +} +void SetColorMask() +{ + Renderer::SetColorMask(); +} +float GetRendererTargetScaleX() +{ + return Renderer::GetTargetScaleX(); +} +float GetRendererTargetScaleY() +{ + return Renderer::GetTargetScaleY(); +} +void CopyEFB(const TRectangle &rc, const u32 &address, const bool &fromZBuffer, const bool &isIntensityFmt, const u32 ©fmt, const bool &scaleByHalf) +{ + // bpmem.zcontrol.pixel_format to PIXELFMT_Z24 is when the game wants to copy from ZBuffer (Zbuffer uses 24-bit Format) + if (!g_Config.bEFBCopyDisable) + if (g_Config.bCopyEFBToRAM) // To RAM + TextureConverter::EncodeToRam(address, fromZBuffer, isIntensityFmt, copyfmt, scaleByHalf, rc); + else // To OGL Texture + TextureMngr::CopyRenderTargetToTexture(address, fromZBuffer, isIntensityFmt, copyfmt, scaleByHalf, rc); +} + +void RenderToXFB(const TRectangle &multirc, const float &yScale, const float &xfbLines, u8* pXFB, const u32 &dstWidth, const u32 &dstHeight) +{ + // EFB to XFB + if (g_Config.bUseXFB) + { + + XFB_Write(pXFB, multirc, dstWidth, dstHeight); + // FIXME: we draw XFB from here in DC mode. + // Bad hack since we can have multiple EFB to XFB copy before a draw. + // Plus we should use width and height from VI regs (see VI->Update()). + // Dixit donkopunchstania for the info. + //DebugLog("(EFB to XFB->XFB_Draw): ptr: %08x | %ix%i", (u32)pXFB, dstWidth, dstHeight); + if (g_VideoInitialize.bUseDualCore) + XFB_Draw(pXFB, dstWidth, dstHeight, 0); + } + else + { + // Hm, we need to compensate for the fact that the copy may be bigger than what is displayed. + // Seen in Spartan Warrior. Not sure how to deal with it yet. + Renderer::Swap(multirc); + } + g_VideoInitialize.pCopiedToXFB(); +} +void ClearScreen(const TRectangle &multirc) +{ + + // Clear color + Renderer::SetRenderMode(Renderer::RM_Normal); + // Clear Z-Buffer target + bool bRestoreZBufferTarget = Renderer::UseFakeZTarget(); + + // Update the view port for clearing the picture + glViewport(0, 0, Renderer::GetTargetWidth(), Renderer::GetTargetHeight()); + + // Always set the scissor in case it was set by the game and has not been reset + glScissor(multirc.left, (Renderer::GetTargetHeight() - multirc.bottom), + (multirc.right - multirc.left), (multirc.bottom - multirc.top)); + // --------------------------- + + VertexShaderManager::SetViewportChanged(); + + // Since clear operations use the source rectangle, we have to do + // regular renders (glClear clears the entire buffer) + if (bpmem.blendmode.colorupdate || bpmem.blendmode.alphaupdate || bpmem.zmode.updateenable) + { + GLbitfield bits = 0; + if (bpmem.blendmode.colorupdate || bpmem.blendmode.alphaupdate) + { + u32 clearColor = (bpmem.clearcolorAR << 16) | bpmem.clearcolorGB; + glClearColor(((clearColor>>16) & 0xff)*(1/255.0f), + ((clearColor>>8 ) & 0xff)*(1/255.0f), + ((clearColor>>0 ) & 0xff)*(1/255.0f), + ((clearColor>>24) & 0xff)*(1/255.0f)); + bits |= GL_COLOR_BUFFER_BIT; + } + if (bpmem.zmode.updateenable) + { + glClearDepth((float)(bpmem.clearZValue & 0xFFFFFF) / float(0xFFFFFF)); + bits |= GL_DEPTH_BUFFER_BIT; + } + if (bRestoreZBufferTarget) + glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT); // don't clear ztarget here + glClear(bits); + } + + // Have to clear the target zbuffer + if (bpmem.zmode.updateenable && bRestoreZBufferTarget) + { + glDrawBuffer(GL_COLOR_ATTACHMENT1_EXT); + GL_REPORT_ERRORD(); + glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); + + // red should probably be the LSB + glClearColor(((bpmem.clearZValue>>0)&0xff)*(1/255.0f), + ((bpmem.clearZValue>>8)&0xff)*(1/255.0f), + ((bpmem.clearZValue>>16)&0xff)*(1/255.0f), 0); + glClear(GL_COLOR_BUFFER_BIT); + Renderer::SetColorMask(); + GL_REPORT_ERRORD(); + } + + if (bRestoreZBufferTarget) + { + // restore target + GLenum s_drawbuffers[2] = {GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT1_EXT}; + glDrawBuffers(2, s_drawbuffers); + } +} + +void RestoreRenderState() +{ + Renderer::RestoreGLState(); +} + +void SetScissorRectangle() +{ + Renderer::SetScissorRect(); +} +bool GetConfig(const int &type) +{ + switch (type) + { + case CONFIG_ISWII: + return g_VideoInitialize.bWii; + case CONFIG_DISABLEFOG: + return g_Config.bDisableFog; + case CONFIG_SHOWEFBREGIONS: + return g_Config.bShowEFBCopyRegions; + default: + PanicAlert("GetConfig Error: Unknown Config Type!"); + return false; + } +} +u8 *GetPointer(const u32 &address) +{ + return g_VideoInitialize.pGetMemoryPointer(address); +} +}; \ No newline at end of file diff --git a/Source/Plugins/Plugin_VideoOGL/Src/BPStructs.cpp b/Source/Plugins/Plugin_VideoOGL/Src/BPStructs.cpp.backup.txt similarity index 90% rename from Source/Plugins/Plugin_VideoOGL/Src/BPStructs.cpp rename to Source/Plugins/Plugin_VideoOGL/Src/BPStructs.cpp.backup.txt index 52ce9dc39d..621efd84d2 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/BPStructs.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/BPStructs.cpp.backup.txt @@ -1,699 +1,629 @@ -// Copyright (C) 2003-2009 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 "Globals.h" -#include "Profiler.h" -#include "Config.h" -#include "Statistics.h" - -#include "VertexLoader.h" -#include "VertexManager.h" - -#include "BPStructs.h" -#include "Render.h" -#include "OpcodeDecoding.h" -#include "TextureMngr.h" -#include "TextureDecoder.h" -#include "TextureConverter.h" -#include "VertexShaderManager.h" -#include "PixelShaderManager.h" -#include "XFB.h" -#include "main.h" - -// ---------------------------------------------- -// State translation lookup tables -// Reference: Yet Another Gamecube Documentation -// ---------------------------------------------- - -static const GLenum glCmpFuncs[8] = { - GL_NEVER, GL_LESS, GL_EQUAL, GL_LEQUAL, GL_GREATER, GL_NOTEQUAL, GL_GEQUAL, GL_ALWAYS -}; - -static const GLenum glLogicOpCodes[16] = { - GL_CLEAR, GL_AND, GL_AND_REVERSE, GL_COPY, GL_AND_INVERTED, GL_NOOP, GL_XOR, - GL_OR, GL_NOR, GL_EQUIV, GL_INVERT, GL_OR_REVERSE, GL_COPY_INVERTED, GL_OR_INVERTED, GL_NAND, GL_SET -}; - -void BPInit() -{ - memset(&bpmem, 0, sizeof(bpmem)); - bpmem.bpMask = 0xFFFFFF; -} - -// ---------------------------------------------------------------------------------------------------------- -// Write to the BreakPoint Memory -/* ------------------ - Called: - At the end of every: OpcodeDecoding.cpp ExecuteDisplayList > Decode() > LoadBPReg - TODO: - Turn into function table. The (future) DisplayList (DL) jit can then call the functions directly, - getting rid of dynamic dispatch. Unfortunately, few games use DLs properly - most\ - just stuff geometry in them and don't put state changes there. */ -// ---------------------------------------------------------------------------------------------------------- -void BPWritten(int addr, int changes, int newval) -{ - switch (addr) - { - case BPMEM_GENMODE: - if (changes) { - VertexManager::Flush(); - ((u32*)&bpmem)[addr] = newval; - PRIM_LOG("genmode: texgen=%d, col=%d, ms_en=%d, tev=%d, culmode=%d, ind=%d, zfeeze=%d", - bpmem.genMode.numtexgens, bpmem.genMode.numcolchans, - bpmem.genMode.ms_en, bpmem.genMode.numtevstages+1, bpmem.genMode.cullmode, - bpmem.genMode.numindstages, bpmem.genMode.zfreeze); - - // none, ccw, cw, ccw - if (bpmem.genMode.cullmode > 0) { - glEnable(GL_CULL_FACE); - glFrontFace(bpmem.genMode.cullmode == 2 ? GL_CCW : GL_CW); - } - else - glDisable(GL_CULL_FACE); - PixelShaderManager::SetGenModeChanged(); - } - 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; - PixelShaderManager::SetIndMatrixChanged((addr-BPMEM_IND_MTX)/3); - } - break; - case BPMEM_RAS1_SS0: - case BPMEM_RAS1_SS1: - if (changes) { - VertexManager::Flush(); - ((u32*)&bpmem)[addr] = newval; - PixelShaderManager::SetIndTexScaleChanged(); - } - break; - case BPMEM_ZMODE: - if (changes) { - VertexManager::Flush(); - ((u32*)&bpmem)[addr] = newval; - PRIM_LOG("zmode: test=%d, func=%d, upd=%d", bpmem.zmode.testenable, bpmem.zmode.func, - bpmem.zmode.updateenable); - - if (bpmem.zmode.testenable) { - glEnable(GL_DEPTH_TEST); - glDepthMask(bpmem.zmode.updateenable?GL_TRUE:GL_FALSE); - glDepthFunc(glCmpFuncs[bpmem.zmode.func]); - } - else { - // if the test is disabled write is disabled too - glDisable(GL_DEPTH_TEST); - glDepthMask(GL_FALSE); - } - - if (!bpmem.zmode.updateenable) - Renderer::SetRenderMode(Renderer::RM_Normal); - } - break; - - case BPMEM_ALPHACOMPARE: - if (changes) { - VertexManager::Flush(); - ((u32*)&bpmem)[addr] = newval; - PRIM_LOG("alphacmp: ref0=%d, ref1=%d, comp0=%d, comp1=%d, logic=%d", 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", bpmem.dstalpha.alpha, bpmem.dstalpha.enable); - SETSTAT(stats.dstAlphaEnable, bpmem.dstalpha.enable); - SETSTAT_UINT(stats.dstAlpha, bpmem.dstalpha.alpha); - PixelShaderManager::SetDestAlpha(bpmem.dstalpha); - } - break; - - case BPMEM_LINEPTWIDTH: - { - float fratio = xfregs.rawViewport[0] != 0 ? ((float)Renderer::GetTargetWidth() / EFB_WIDTH) : 1.0f; - if (bpmem.lineptwidth.linesize > 0) - glLineWidth((float)bpmem.lineptwidth.linesize * fratio / 6.0f); // scale by ratio of widths - if (bpmem.lineptwidth.pointsize > 0) - glPointSize((float)bpmem.lineptwidth.pointsize * fratio / 6.0f); - break; - } - - case BPMEM_PE_CONTROL: // GXSetZCompLoc, GXPixModeSync - if (changes) { - VertexManager::Flush(); - ((u32*)&bpmem)[addr] = newval; - } - break; - - case BPMEM_BLENDMODE: - if (changes & 0xFFFF) { - VertexManager::Flush(); - ((u32*)&bpmem)[addr] = newval; - - PRIM_LOG("blendmode: en=%d, open=%d, colupd=%d, alphaupd=%d, dst=%d, src=%d, sub=%d, mode=%d", - bpmem.blendmode.blendenable, bpmem.blendmode.logicopenable, bpmem.blendmode.colorupdate, bpmem.blendmode.alphaupdate, - bpmem.blendmode.dstfactor, bpmem.blendmode.srcfactor, bpmem.blendmode.subtract, bpmem.blendmode.logicmode); - - // Set LogicOp Blending Mode - if (changes & 2) - { - SETSTAT(stats.logicOpMode, bpmem.blendmode.logicopenable != 0 ? bpmem.blendmode.logicmode : stats.logicOpMode); - if (bpmem.blendmode.logicopenable) - { - glEnable(GL_COLOR_LOGIC_OP); - glLogicOp(glLogicOpCodes[bpmem.blendmode.logicmode]); - } - else - glDisable(GL_COLOR_LOGIC_OP); - } - - // Set Dithering Mode - if (changes & 4) - { - SETSTAT(stats.dither, bpmem.blendmode.dither); - if (bpmem.blendmode.dither) glEnable(GL_DITHER); - else glDisable(GL_DITHER); - } - - // Set Blending Mode - if (changes & 0xFE1) - { - SETSTAT(stats.srcFactor, bpmem.blendmode.srcfactor); - SETSTAT(stats.dstFactor, bpmem.blendmode.dstfactor); - Renderer::SetBlendMode(false); - } - - // Set Color Mask - if (changes & 0x18) - { - SETSTAT(stats.alphaUpdate, bpmem.blendmode.alphaupdate); - SETSTAT(stats.colorUpdate, bpmem.blendmode.colorupdate); - Renderer::SetColorMask(); - } - } - break; - - case BPMEM_FOGRANGE: - case BPMEM_FOGPARAM0: - case BPMEM_FOGBEXPONENT: - case BPMEM_FOGBMAGNITUDE: - case BPMEM_FOGPARAM3: - if (!g_Config.bDisableFog) - if (changes) { - VertexManager::Flush(); - ((u32*)&bpmem)[addr] = newval; - PixelShaderManager::SetFogParamChanged(); - } - break; - - case BPMEM_FOGCOLOR: - if (changes) - { - VertexManager::Flush(); - ((u32*)&bpmem)[addr] = newval; - PixelShaderManager::SetFogColorChanged(); - } - break; - - case BPMEM_TEXINVALIDATE: - break; - - case BPMEM_SCISSOROFFSET: - if (changes) { - VertexManager::Flush(); - ((u32*)&bpmem)[addr] = newval; - Renderer::SetScissorRect(); - } - break; - - 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!"); - } - } - } - break; - case BPMEM_ZTEX1: - if (changes) { - VertexManager::Flush(); - ((u32*)&bpmem)[addr] = newval; - PRIM_LOG("ztex bias=0x%x", bpmem.ztex1.bias); - PixelShaderManager::SetZTextureBias(bpmem.ztex1.bias); - } - break; - case BPMEM_ZTEX2: - if (changes) { - VertexManager::Flush(); - ((u32*)&bpmem)[addr] = newval; - if (changes & 3) { - PixelShaderManager::SetZTextureTypeChanged(); - } -#if defined(_DEBUG) || defined(DEBUGFAST) - const char* pzop[] = {"DISABLE", "ADD", "REPLACE", "?"}; - const char* pztype[] = {"Z8", "Z16", "Z24", "?"}; - PRIM_LOG("ztex op=%s, type=%s", pzop[bpmem.ztex2.op], pztype[bpmem.ztex2.type]); -#endif - } - break; - - 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; - - case BPMEM_SETDRAWDONE: - VertexManager::Flush(); - switch (newval & 0xFF) - { - case 0x02: - g_VideoInitialize.pSetPEFinish(); // may generate interrupt - DEBUG_LOG(VIDEO, "GXSetDrawDone SetPEFinish (value: 0x%02X)", (newval & 0xFFFF)); - break; - - default: - DEBUG_LOG(VIDEO, "GXSetDrawDone ??? (value 0x%02X)", (newval & 0xFFFF)); - break; - } - break; - - case BPMEM_PE_TOKEN_ID: - g_VideoInitialize.pSetPEToken(static_cast(newval & 0xFFFF), FALSE); - DEBUG_LOG(VIDEO, "SetPEToken 0x%04x", (newval & 0xFFFF)); - break; - - case BPMEM_PE_TOKEN_INT_ID: - g_VideoInitialize.pSetPEToken(static_cast(newval & 0xFFFF), TRUE); - DEBUG_LOG(VIDEO, "SetPEToken + INT 0x%04x", (newval & 0xFFFF)); - break; - - case BPMEM_SETGPMETRIC: // Set gp metric? - break; - - // ------------------------ - // EFB copy command. This copies a rectangle from the EFB to either RAM in a texture format or to XFB as YUYV. - // It can also optionally clear the EFB while copying from it. To emulate this, we of course copy first and clear afterwards. - case BPMEM_TRIGGER_EFB_COPY: - { - DVSTARTSUBPROFILE("LoadBPReg:swap"); - VertexManager::Flush(); - - ((u32*)&bpmem)[addr] = newval; - // The bottom right is within the rectangle - // The values in bpmem.copyTexSrcXY and bpmem.copyTexSrcWH are updated in case 0x49 and 0x4a in this function - TRectangle rc = { - (int)(bpmem.copyTexSrcXY.x), - (int)(bpmem.copyTexSrcXY.y), - (int)((bpmem.copyTexSrcXY.x + bpmem.copyTexSrcWH.x + 1)), - (int)((bpmem.copyTexSrcXY.y + bpmem.copyTexSrcWH.y + 1)) - }; - float MValueX = Renderer::GetTargetScaleX(); - float MValueY = Renderer::GetTargetScaleY(); - // Need another rc here to get it to scale. - // Here the bottom right is the out of the rectangle. - TRectangle multirc = { - (int)(bpmem.copyTexSrcXY.x * MValueX), - (int)(bpmem.copyTexSrcXY.y * MValueY), - (int)((bpmem.copyTexSrcXY.x * MValueX + (bpmem.copyTexSrcWH.x + 1) * MValueX)), - (int)((bpmem.copyTexSrcXY.y * MValueY + (bpmem.copyTexSrcWH.y + 1) * MValueY)) - }; - - UPE_Copy PE_copy; - PE_copy.Hex = bpmem.triggerEFBCopy; - - // -------------------------------------------------------- - // Check to where we should copy the image data from the EFB. - // -------------------------- - if (PE_copy.copy_to_xfb == 0) - { - if (g_Config.bShowEFBCopyRegions) - stats.efb_regions.push_back(rc); - - // 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 - if (!g_Config.bEFBCopyDisable) - { - if (g_Config.bCopyEFBToRAM) - { - TextureConverter::EncodeToRam(bpmem.copyTexDest << 5, - bpmem.zcontrol.pixel_format == PIXELFMT_Z24, - PE_copy.intensity_fmt > 0, - (PE_copy.target_pixel_format / 2) + ((PE_copy.target_pixel_format & 1) * 8), // ?? - PE_copy.half_scale > 0, rc); - } - else - { - TextureMngr::CopyRenderTargetToTexture(bpmem.copyTexDest << 5, - bpmem.zcontrol.pixel_format == PIXELFMT_Z24, - PE_copy.intensity_fmt > 0, - (PE_copy.target_pixel_format / 2) + ((PE_copy.target_pixel_format & 1) * 8), // ?? - PE_copy.half_scale > 0, rc); - } - } - } - else - { - // EFB to XFB - if (g_Config.bUseXFB) - { - // the number of lines copied is determined by the y scale * source efb height - float yScale = bpmem.dispcopyyscale / 256.0f; - float xfbLines = bpmem.copyTexSrcWH.y + 1.0f * yScale; - u8* pXFB = Memory_GetPtr(bpmem.copyTexDest << 5); - u32 dstWidth = (bpmem.copyMipMapStrideChannels << 4); - u32 dstHeight = (u32)xfbLines; - XFB_Write(pXFB, multirc, dstWidth, dstHeight); - // FIXME: we draw XFB from here in DC mode. - // Bad hack since we can have multiple EFB to XFB copy before a draw. - // Plus we should use width and height from VI regs (see VI->Update()). - // Dixit donkopunchstania for the info. - //DebugLog("(EFB to XFB->XFB_Draw): ptr: %08x | %ix%i", (u32)pXFB, dstWidth, dstHeight); - if (g_VideoInitialize.bUseDualCore) - XFB_Draw(pXFB, dstWidth, dstHeight, 0); - } - else - { - // Hm, we need to compensate for the fact that the copy may be bigger than what is displayed. - // Seen in Spartan Warrior. Not sure how to deal with it yet. - Renderer::Swap(multirc); - } - g_VideoInitialize.pCopiedToXFB(); - } - - // -------------------------------------------------------- - // Clear the picture after it's done and submitted, to prepare for the next picture - // -------------------------- - if (PE_copy.clear) - { - // Clear color - Renderer::SetRenderMode(Renderer::RM_Normal); - // Clear Z-Buffer target - bool bRestoreZBufferTarget = Renderer::UseFakeZTarget(); - - // Update the view port for clearing the picture - glViewport(0, 0, Renderer::GetTargetWidth(), Renderer::GetTargetHeight()); - - // Always set the scissor in case it was set by the game and has not been reset - glScissor(multirc.left, (Renderer::GetTargetHeight() - multirc.bottom), - (multirc.right - multirc.left), (multirc.bottom - multirc.top)); - // --------------------------- - - VertexShaderManager::SetViewportChanged(); - - // Since clear operations use the source rectangle, we have to do - // regular renders (glClear clears the entire buffer) - if (bpmem.blendmode.colorupdate || bpmem.blendmode.alphaupdate || bpmem.zmode.updateenable) - { - GLbitfield bits = 0; - if (bpmem.blendmode.colorupdate || bpmem.blendmode.alphaupdate) - { - u32 clearColor = (bpmem.clearcolorAR << 16) | bpmem.clearcolorGB; - glClearColor(((clearColor>>16) & 0xff)*(1/255.0f), - ((clearColor>>8 ) & 0xff)*(1/255.0f), - ((clearColor>>0 ) & 0xff)*(1/255.0f), - ((clearColor>>24) & 0xff)*(1/255.0f)); - bits |= GL_COLOR_BUFFER_BIT; - } - if (bpmem.zmode.updateenable) - { - glClearDepth((float)(bpmem.clearZValue & 0xFFFFFF) / float(0xFFFFFF)); - bits |= GL_DEPTH_BUFFER_BIT; - } - if (bRestoreZBufferTarget) - glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT); // don't clear ztarget here - glClear(bits); - } - - // Have to clear the target zbuffer - if (bpmem.zmode.updateenable && bRestoreZBufferTarget) - { - glDrawBuffer(GL_COLOR_ATTACHMENT1_EXT); - GL_REPORT_ERRORD(); - glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); - - // red should probably be the LSB - glClearColor(((bpmem.clearZValue>>0)&0xff)*(1/255.0f), - ((bpmem.clearZValue>>8)&0xff)*(1/255.0f), - ((bpmem.clearZValue>>16)&0xff)*(1/255.0f), 0); - glClear(GL_COLOR_BUFFER_BIT); - Renderer::SetColorMask(); - GL_REPORT_ERRORD(); - } - - if (bRestoreZBufferTarget) - { - // restore target - GLenum s_drawbuffers[2] = {GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT1_EXT}; - glDrawBuffers(2, s_drawbuffers); - } - } - Renderer::RestoreGLState(); - } - break; - // ================================== - - case BPMEM_LOADTLUT: - { - DVSTARTSUBPROFILE("LoadBPReg:GXLoadTlut"); - VertexManager::Flush(); - ((u32*)&bpmem)[addr] = newval; - - u32 tlutTMemAddr = (newval & 0x3FF) << 9; - u32 tlutXferCount = (newval & 0x1FFC00) >> 5; - - 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); - - // 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; - - - default: - switch (addr & 0xFC) //texture sampler filter - { - case 0x28: // tevorder 0-3 - case 0x2C: // tevorder 4-7 - if (changes) - { - VertexManager::Flush(); - ((u32*)&bpmem)[addr] = newval; - PixelShaderManager::SetTevOrderChanged(addr - 0x28); - } - break; - case 0x80: // TEX MODE 0 - case 0xA0: - if (changes) - { - VertexManager::Flush(); - ((u32*)&bpmem)[addr] = newval; - } - 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", addr, newval); - ((u32*)&bpmem)[addr] = newval; - break; - case 0xE0: - case 0xE4: - if (addr&1) { // don't compare with changes! - VertexManager::Flush(); - ((u32*)&bpmem)[addr] = newval; - int num = (addr>>1)&0x3; - PixelShaderManager::SetColorChanged(bpmem.tevregs[num].high.type, num); - } - else - ((u32*)&bpmem)[addr] = newval; - 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: - - // Just update the bpmem struct, don't do anything else - default: - if (changes) - { - VertexManager::Flush(); - ((u32*)&bpmem)[addr] = newval; - /*switch(addr) { - case 0x01: - case 0x02: - case 0x03: - case 0x04: break; // copy filter values - case 0x0f: break; // mask - case 0x27: break; // tev ind order - case 0x44: break; // field mask - case 0x45: break; // draw done - case 0x46: break; // clock - case 0x49: - case 0x4a: break; // copy tex src - case 0x4b: break; // copy tex dest - case 0x4d: break; // copyMipMapStrideChannels - case 0x4e: break; // disp copy scale - case 0x4f: break; // clear color - case 0x50: break; // clear color - case 0x51: break; // casez - case 0x52: break; // trigger efb copy - case 0x53: - case 0x54: break; // more copy filters - case 0x55: - case 0x56: break; // bounding box - case 0x64: - case 0x65: break; // tlut src dest - case 0xe8: break; // fog range - case 0xe9: - case 0xea: - case 0xeb: - case 0xec: - case 0xed: break; // fog - case 0xfe: break; // mask - default: - // 0x58 = 0xf - // 0x69 = 0x49e - ERROR_LOG("bp%.2x = %x", addr, newval); - }*/ - } - break; - } - break; - - } - break; - } -} - + switch (addr) + { + case BPMEM_GENMODE: + if (changes) { + VertexManager::Flush(); + ((u32*)&bpmem)[addr] = newval; + PRIM_LOG("genmode: texgen=%d, col=%d, ms_en=%d, tev=%d, culmode=%d, ind=%d, zfeeze=%d", + bpmem.genMode.numtexgens, bpmem.genMode.numcolchans, + bpmem.genMode.ms_en, bpmem.genMode.numtevstages+1, bpmem.genMode.cullmode, + bpmem.genMode.numindstages, bpmem.genMode.zfreeze); + + // none, ccw, cw, ccw + if (bpmem.genMode.cullmode > 0) { + glEnable(GL_CULL_FACE); + glFrontFace(bpmem.genMode.cullmode == 2 ? GL_CCW : GL_CW); + } + else + glDisable(GL_CULL_FACE); + PixelShaderManager::SetGenModeChanged(); + } + 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; + PixelShaderManager::SetIndMatrixChanged((addr-BPMEM_IND_MTX)/3); + } + break; + case BPMEM_RAS1_SS0: + case BPMEM_RAS1_SS1: + if (changes) { + VertexManager::Flush(); + ((u32*)&bpmem)[addr] = newval; + PixelShaderManager::SetIndTexScaleChanged(); + } + break; + case BPMEM_ZMODE: + if (changes) { + VertexManager::Flush(); + ((u32*)&bpmem)[addr] = newval; + PRIM_LOG("zmode: test=%d, func=%d, upd=%d", bpmem.zmode.testenable, bpmem.zmode.func, + bpmem.zmode.updateenable); + + if (bpmem.zmode.testenable) { + glEnable(GL_DEPTH_TEST); + glDepthMask(bpmem.zmode.updateenable?GL_TRUE:GL_FALSE); + glDepthFunc(glCmpFuncs[bpmem.zmode.func]); + } + else { + // if the test is disabled write is disabled too + glDisable(GL_DEPTH_TEST); + glDepthMask(GL_FALSE); + } + + if (!bpmem.zmode.updateenable) + Renderer::SetRenderMode(Renderer::RM_Normal); + } + break; + + case BPMEM_ALPHACOMPARE: + if (changes) { + VertexManager::Flush(); + ((u32*)&bpmem)[addr] = newval; + PRIM_LOG("alphacmp: ref0=%d, ref1=%d, comp0=%d, comp1=%d, logic=%d", 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", bpmem.dstalpha.alpha, bpmem.dstalpha.enable); + SETSTAT(stats.dstAlphaEnable, bpmem.dstalpha.enable); + SETSTAT_UINT(stats.dstAlpha, bpmem.dstalpha.alpha); + PixelShaderManager::SetDestAlpha(bpmem.dstalpha); + } + break; + + case BPMEM_LINEPTWIDTH: + { + float fratio = xfregs.rawViewport[0] != 0 ? ((float)Renderer::GetTargetWidth() / EFB_WIDTH) : 1.0f; + if (bpmem.lineptwidth.linesize > 0) + glLineWidth((float)bpmem.lineptwidth.linesize * fratio / 6.0f); // scale by ratio of widths + if (bpmem.lineptwidth.pointsize > 0) + glPointSize((float)bpmem.lineptwidth.pointsize * fratio / 6.0f); + break; + } + + case BPMEM_PE_CONTROL: // GXSetZCompLoc, GXPixModeSync + if (changes) { + VertexManager::Flush(); + ((u32*)&bpmem)[addr] = newval; + } + break; + + case BPMEM_BLENDMODE: + if (changes & 0xFFFF) { + VertexManager::Flush(); + ((u32*)&bpmem)[addr] = newval; + + PRIM_LOG("blendmode: en=%d, open=%d, colupd=%d, alphaupd=%d, dst=%d, src=%d, sub=%d, mode=%d", + bpmem.blendmode.blendenable, bpmem.blendmode.logicopenable, bpmem.blendmode.colorupdate, bpmem.blendmode.alphaupdate, + bpmem.blendmode.dstfactor, bpmem.blendmode.srcfactor, bpmem.blendmode.subtract, bpmem.blendmode.logicmode); + + // Set LogicOp Blending Mode + if (changes & 2) + { + SETSTAT(stats.logicOpMode, bpmem.blendmode.logicopenable != 0 ? bpmem.blendmode.logicmode : stats.logicOpMode); + if (bpmem.blendmode.logicopenable) + { + glEnable(GL_COLOR_LOGIC_OP); + glLogicOp(glLogicOpCodes[bpmem.blendmode.logicmode]); + } + else + glDisable(GL_COLOR_LOGIC_OP); + } + + // Set Dithering Mode + if (changes & 4) + { + SETSTAT(stats.dither, bpmem.blendmode.dither); + if (bpmem.blendmode.dither) glEnable(GL_DITHER); + else glDisable(GL_DITHER); + } + + // Set Blending Mode + if (changes & 0xFE1) + { + SETSTAT(stats.srcFactor, bpmem.blendmode.srcfactor); + SETSTAT(stats.dstFactor, bpmem.blendmode.dstfactor); + Renderer::SetBlendMode(false); + } + + // Set Color Mask + if (changes & 0x18) + { + SETSTAT(stats.alphaUpdate, bpmem.blendmode.alphaupdate); + SETSTAT(stats.colorUpdate, bpmem.blendmode.colorupdate); + Renderer::SetColorMask(); + } + } + break; + + case BPMEM_FOGRANGE: + case BPMEM_FOGPARAM0: + case BPMEM_FOGBEXPONENT: + case BPMEM_FOGBMAGNITUDE: + case BPMEM_FOGPARAM3: + if (!g_Config.bDisableFog) + if (changes) { + VertexManager::Flush(); + ((u32*)&bpmem)[addr] = newval; + PixelShaderManager::SetFogParamChanged(); + } + break; + + case BPMEM_FOGCOLOR: + if (changes) + { + VertexManager::Flush(); + ((u32*)&bpmem)[addr] = newval; + PixelShaderManager::SetFogColorChanged(); + } + break; + + case BPMEM_TEXINVALIDATE: + break; + + case BPMEM_SCISSOROFFSET: + if (changes) { + VertexManager::Flush(); + ((u32*)&bpmem)[addr] = newval; + Renderer::SetScissorRect(); + } + break; + + 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!"); + } + } + } + break; + case BPMEM_ZTEX1: + if (changes) { + VertexManager::Flush(); + ((u32*)&bpmem)[addr] = newval; + PRIM_LOG("ztex bias=0x%x", bpmem.ztex1.bias); + PixelShaderManager::SetZTextureBias(bpmem.ztex1.bias); + } + break; + case BPMEM_ZTEX2: + if (changes) { + VertexManager::Flush(); + ((u32*)&bpmem)[addr] = newval; + if (changes & 3) { + PixelShaderManager::SetZTextureTypeChanged(); + } +#if defined(_DEBUG) || defined(DEBUGFAST) + const char* pzop[] = {"DISABLE", "ADD", "REPLACE", "?"}; + const char* pztype[] = {"Z8", "Z16", "Z24", "?"}; + PRIM_LOG("ztex op=%s, type=%s", pzop[bpmem.ztex2.op], pztype[bpmem.ztex2.type]); +#endif + } + break; + + 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; + + case BPMEM_SETDRAWDONE: + VertexManager::Flush(); + switch (newval & 0xFF) + { + case 0x02: + g_VideoInitialize.pSetPEFinish(); // may generate interrupt + DEBUG_LOG(VIDEO, "GXSetDrawDone SetPEFinish (value: 0x%02X)", (newval & 0xFFFF)); + break; + + default: + DEBUG_LOG(VIDEO, "GXSetDrawDone ??? (value 0x%02X)", (newval & 0xFFFF)); + break; + } + break; + + case BPMEM_PE_TOKEN_ID: + g_VideoInitialize.pSetPEToken(static_cast(newval & 0xFFFF), FALSE); + DEBUG_LOG(VIDEO, "SetPEToken 0x%04x", (newval & 0xFFFF)); + break; + + case BPMEM_PE_TOKEN_INT_ID: + g_VideoInitialize.pSetPEToken(static_cast(newval & 0xFFFF), TRUE); + DEBUG_LOG(VIDEO, "SetPEToken + INT 0x%04x", (newval & 0xFFFF)); + break; + + case BPMEM_SETGPMETRIC: // Set gp metric? + break; + + // ------------------------ + // EFB copy command. This copies a rectangle from the EFB to either RAM in a texture format or to XFB as YUYV. + // It can also optionally clear the EFB while copying from it. To emulate this, we of course copy first and clear afterwards. + case BPMEM_TRIGGER_EFB_COPY: + { + DVSTARTSUBPROFILE("LoadBPReg:swap"); + VertexManager::Flush(); + + ((u32*)&bpmem)[addr] = newval; + // The bottom right is within the rectangle + // The values in bpmem.copyTexSrcXY and bpmem.copyTexSrcWH are updated in case 0x49 and 0x4a in this function + TRectangle rc = { + (int)(bpmem.copyTexSrcXY.x), + (int)(bpmem.copyTexSrcXY.y), + (int)((bpmem.copyTexSrcXY.x + bpmem.copyTexSrcWH.x + 1)), + (int)((bpmem.copyTexSrcXY.y + bpmem.copyTexSrcWH.y + 1)) + }; + float MValueX = Renderer::GetTargetScaleX(); + float MValueY = Renderer::GetTargetScaleY(); + // Need another rc here to get it to scale. + // Here the bottom right is the out of the rectangle. + TRectangle multirc = { + (int)(bpmem.copyTexSrcXY.x * MValueX), + (int)(bpmem.copyTexSrcXY.y * MValueY), + (int)((bpmem.copyTexSrcXY.x * MValueX + (bpmem.copyTexSrcWH.x + 1) * MValueX)), + (int)((bpmem.copyTexSrcXY.y * MValueY + (bpmem.copyTexSrcWH.y + 1) * MValueY)) + }; + + UPE_Copy PE_copy; + PE_copy.Hex = bpmem.triggerEFBCopy; + + // -------------------------------------------------------- + // Check to where we should copy the image data from the EFB. + // -------------------------- + if (PE_copy.copy_to_xfb == 0) + { + if (g_Config.bShowEFBCopyRegions) + stats.efb_regions.push_back(rc); + + // 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 + if (!g_Config.bEFBCopyDisable) + { + if (g_Config.bCopyEFBToRAM) + { + TextureConverter::EncodeToRam(bpmem.copyTexDest << 5, + bpmem.zcontrol.pixel_format == PIXELFMT_Z24, + PE_copy.intensity_fmt > 0, + (PE_copy.target_pixel_format / 2) + ((PE_copy.target_pixel_format & 1) * 8), // ?? + PE_copy.half_scale > 0, rc); + } + else + { + TextureMngr::CopyRenderTargetToTexture(bpmem.copyTexDest << 5, + bpmem.zcontrol.pixel_format == PIXELFMT_Z24, + PE_copy.intensity_fmt > 0, + (PE_copy.target_pixel_format / 2) + ((PE_copy.target_pixel_format & 1) * 8), // ?? + PE_copy.half_scale > 0, rc); + } + } + } + else + { + // EFB to XFB + if (g_Config.bUseXFB) + { + // the number of lines copied is determined by the y scale * source efb height + float yScale = bpmem.dispcopyyscale / 256.0f; + float xfbLines = bpmem.copyTexSrcWH.y + 1.0f * yScale; + u8* pXFB = Memory_GetPtr(bpmem.copyTexDest << 5); + u32 dstWidth = (bpmem.copyMipMapStrideChannels << 4); + u32 dstHeight = (u32)xfbLines; + XFB_Write(pXFB, multirc, dstWidth, dstHeight); + // FIXME: we draw XFB from here in DC mode. + // Bad hack since we can have multiple EFB to XFB copy before a draw. + // Plus we should use width and height from VI regs (see VI->Update()). + // Dixit donkopunchstania for the info. + //DebugLog("(EFB to XFB->XFB_Draw): ptr: %08x | %ix%i", (u32)pXFB, dstWidth, dstHeight); + if (g_VideoInitialize.bUseDualCore) + XFB_Draw(pXFB, dstWidth, dstHeight, 0); + } + else + { + // Hm, we need to compensate for the fact that the copy may be bigger than what is displayed. + // Seen in Spartan Warrior. Not sure how to deal with it yet. + Renderer::Swap(multirc); + } + g_VideoInitialize.pCopiedToXFB(); + } + + // -------------------------------------------------------- + // Clear the picture after it's done and submitted, to prepare for the next picture + // -------------------------- + if (PE_copy.clear) + { + // Clear color + Renderer::SetRenderMode(Renderer::RM_Normal); + // Clear Z-Buffer target + bool bRestoreZBufferTarget = Renderer::UseFakeZTarget(); + + // Update the view port for clearing the picture + glViewport(0, 0, Renderer::GetTargetWidth(), Renderer::GetTargetHeight()); + + // Always set the scissor in case it was set by the game and has not been reset + glScissor(multirc.left, (Renderer::GetTargetHeight() - multirc.bottom), + (multirc.right - multirc.left), (multirc.bottom - multirc.top)); + // --------------------------- + + VertexShaderManager::SetViewportChanged(); + + // Since clear operations use the source rectangle, we have to do + // regular renders (glClear clears the entire buffer) + if (bpmem.blendmode.colorupdate || bpmem.blendmode.alphaupdate || bpmem.zmode.updateenable) + { + GLbitfield bits = 0; + if (bpmem.blendmode.colorupdate || bpmem.blendmode.alphaupdate) + { + u32 clearColor = (bpmem.clearcolorAR << 16) | bpmem.clearcolorGB; + glClearColor(((clearColor>>16) & 0xff)*(1/255.0f), + ((clearColor>>8 ) & 0xff)*(1/255.0f), + ((clearColor>>0 ) & 0xff)*(1/255.0f), + ((clearColor>>24) & 0xff)*(1/255.0f)); + bits |= GL_COLOR_BUFFER_BIT; + } + if (bpmem.zmode.updateenable) + { + glClearDepth((float)(bpmem.clearZValue & 0xFFFFFF) / float(0xFFFFFF)); + bits |= GL_DEPTH_BUFFER_BIT; + } + if (bRestoreZBufferTarget) + glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT); // don't clear ztarget here + glClear(bits); + } + + // Have to clear the target zbuffer + if (bpmem.zmode.updateenable && bRestoreZBufferTarget) + { + glDrawBuffer(GL_COLOR_ATTACHMENT1_EXT); + GL_REPORT_ERRORD(); + glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); + + // red should probably be the LSB + glClearColor(((bpmem.clearZValue>>0)&0xff)*(1/255.0f), + ((bpmem.clearZValue>>8)&0xff)*(1/255.0f), + ((bpmem.clearZValue>>16)&0xff)*(1/255.0f), 0); + glClear(GL_COLOR_BUFFER_BIT); + Renderer::SetColorMask(); + GL_REPORT_ERRORD(); + } + + if (bRestoreZBufferTarget) + { + // restore target + GLenum s_drawbuffers[2] = {GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT1_EXT}; + glDrawBuffers(2, s_drawbuffers); + } + } + Renderer::RestoreGLState(); + } + break; + // ================================== + + case BPMEM_LOADTLUT: + { + DVSTARTSUBPROFILE("LoadBPReg:GXLoadTlut"); + VertexManager::Flush(); + ((u32*)&bpmem)[addr] = newval; + + u32 tlutTMemAddr = (newval & 0x3FF) << 9; + u32 tlutXferCount = (newval & 0x1FFC00) >> 5; + + 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); + + // 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; + + + default: + switch (addr & 0xFC) //texture sampler filter + { + case 0x28: // tevorder 0-3 + case 0x2C: // tevorder 4-7 + if (changes) + { + VertexManager::Flush(); + ((u32*)&bpmem)[addr] = newval; + PixelShaderManager::SetTevOrderChanged(addr - 0x28); + } + break; + case 0x80: // TEX MODE 0 + case 0xA0: + if (changes) + { + VertexManager::Flush(); + ((u32*)&bpmem)[addr] = newval; + } + 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", addr, newval); + ((u32*)&bpmem)[addr] = newval; + break; + case 0xE0: + case 0xE4: + if (addr&1) { // don't compare with changes! + VertexManager::Flush(); + ((u32*)&bpmem)[addr] = newval; + int num = (addr>>1)&0x3; + PixelShaderManager::SetColorChanged(bpmem.tevregs[num].high.type, num); + } + else + ((u32*)&bpmem)[addr] = newval; + 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: + + // Just update the bpmem struct, don't do anything else + default: + if (changes) + { + VertexManager::Flush(); + ((u32*)&bpmem)[addr] = newval; + /*switch(addr) { + case 0x01: + case 0x02: + case 0x03: + case 0x04: break; // copy filter values + case 0x0f: break; // mask + case 0x27: break; // tev ind order + case 0x44: break; // field mask + case 0x45: break; // draw done + case 0x46: break; // clock + case 0x49: + case 0x4a: break; // copy tex src + case 0x4b: break; // copy tex dest + case 0x4d: break; // copyMipMapStrideChannels + case 0x4e: break; // disp copy scale + case 0x4f: break; // clear color + case 0x50: break; // clear color + case 0x51: break; // casez + case 0x52: break; // trigger efb copy + case 0x53: + case 0x54: break; // more copy filters + case 0x55: + case 0x56: break; // bounding box + case 0x64: + case 0x65: break; // tlut src dest + case 0xe8: break; // fog range + case 0xe9: + case 0xea: + case 0xeb: + case 0xec: + case 0xed: break; // fog + case 0xfe: break; // mask + default: + // 0x58 = 0xf + // 0x69 = 0x49e + ERROR_LOG("bp%.2x = %x", addr, newval); + }*/ + } + break; + } + break; + + } + break; + } \ No newline at end of file diff --git a/Source/Plugins/Plugin_VideoOGL/Src/SConscript b/Source/Plugins/Plugin_VideoOGL/Src/SConscript index 1af827703f..9dad14808d 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/SConscript +++ b/Source/Plugins/Plugin_VideoOGL/Src/SConscript @@ -11,6 +11,7 @@ name = "Plugin_VideoOGL" files = [ 'BPStructs.cpp', + 'BPFunctions.cpp', 'Config.cpp', 'rasterfont.cpp', 'Render.cpp',