diff --git a/Source/Core/VideoCommon/Src/PixelShaderManager.cpp b/Source/Core/VideoCommon/Src/PixelShaderManager.cpp index 9478eae6e5..f0a1a8ea08 100644 --- a/Source/Core/VideoCommon/Src/PixelShaderManager.cpp +++ b/Source/Core/VideoCommon/Src/PixelShaderManager.cpp @@ -306,7 +306,7 @@ void PixelShaderManager::SetZTextureBias(u32 bias) } } -void PixelShaderManager::SetViewport(float* viewport) +void PixelShaderManager::SetViewport(float* viewport,int VIndex) { // reversed gxsetviewport(xorig, yorig, width, height, nearz, farz) // [0] = width/2 @@ -316,30 +316,28 @@ void PixelShaderManager::SetViewport(float* viewport) // [4] = yorig + height/2 + 342 // [5] = 16777215 * farz - if (lastDepthRange[0] != viewport[5] || lastDepthRange[1] != viewport[2]) + if(VIndex <= 0) { - lastDepthRange[0] = viewport[5]; - lastDepthRange[1] = viewport[2]; + if (lastDepthRange[0] != viewport[5] || lastDepthRange[1] != viewport[2]) + { + lastDepthRange[0] = viewport[5]; + lastDepthRange[1] = viewport[2]; - s_bDepthRangeChanged = true; + s_bDepthRangeChanged = true; + } } -} - -void PixelShaderManager::SetZScale(float data) -{ - if (lastDepthRange[0] != data) + else { - lastDepthRange[0] = data; - s_bDepthRangeChanged = true; - } -} - -void PixelShaderManager::SetZOffset(float data) -{ - if (lastDepthRange[1] != data) - { - lastDepthRange[1] = data; - s_bDepthRangeChanged = true; + if (VIndex == 2 && lastDepthRange[1] != viewport[0]) + { + lastDepthRange[1] = viewport[0]; + s_bDepthRangeChanged = true; + } + else if(VIndex == 5 && lastDepthRange[0] != viewport[0]) + { + lastDepthRange[0] = viewport[0]; + s_bDepthRangeChanged = true; + } } } diff --git a/Source/Core/VideoCommon/Src/PixelShaderManager.h b/Source/Core/VideoCommon/Src/PixelShaderManager.h index 5625dbdb05..2f4e2dfdc3 100644 --- a/Source/Core/VideoCommon/Src/PixelShaderManager.h +++ b/Source/Core/VideoCommon/Src/PixelShaderManager.h @@ -43,7 +43,7 @@ public: static void SetTexDims(int texmapid, u32 width, u32 height, u32 wraps, u32 wrapt); static void SetCustomTexScale(int texmapid, float x, float y); static void SetZTextureBias(u32 bias); - static void SetViewport(float* viewport); + static void SetViewport(float* viewport,int VIndex = -1); static void SetIndMatrixChanged(int matrixidx); static void SetTevKSelChanged(int id); static void SetZTextureTypeChanged(); @@ -54,8 +54,6 @@ public: static void SetFogParamChanged(); static void SetColorMatrix(const float* pmatrix, const float* pfConstAdd); static u32 GetTextureMask(); - static void SetZScale(float data); - static void SetZOffset(float data); }; diff --git a/Source/Core/VideoCommon/Src/VertexShaderManager.cpp b/Source/Core/VideoCommon/Src/VertexShaderManager.cpp index 9331cac345..08ee1d45f2 100644 --- a/Source/Core/VideoCommon/Src/VertexShaderManager.cpp +++ b/Source/Core/VideoCommon/Src/VertexShaderManager.cpp @@ -438,27 +438,24 @@ void VertexShaderManager::SetTexMatrixChangedB(u32 Value) } } -void VertexShaderManager::SetViewport(float* _Viewport) +void VertexShaderManager::SetViewport(float* _Viewport, int constantIndex) { - // Workaround for paper mario, yep this is bizarre. + if(constantIndex <= 0) + { + memcpy(xfregs.rawViewport, _Viewport, sizeof(xfregs.rawViewport)); + } + else + { + xfregs.rawViewport[constantIndex] = _Viewport[0]; + } + /*//Tino: i think this is nod needed so let this commented til confirmed + // Workaround for paper mario, yep this is bizarre. for (size_t i = 0; i < ARRAYSIZE(xfregs.rawViewport); ++i) { if (*(u32*)(_Viewport + i) == 0x7f800000) // invalid fp number return; } - memcpy(xfregs.rawViewport, _Viewport, sizeof(xfregs.rawViewport)); - bViewportChanged = true; -} - -void VertexShaderManager::SetZScale(float data) -{ - xfregs.rawViewport[5] = data; - bViewportChanged = true; -} - -void VertexShaderManager::SetZOffset(float data) -{ - xfregs.rawViewport[2] = data; + memcpy(xfregs.rawViewport, _Viewport, sizeof(xfregs.rawViewport));*/ bViewportChanged = true; } @@ -469,7 +466,14 @@ void VertexShaderManager::SetViewportChanged() void VertexShaderManager::SetProjection(float* _pProjection, int constantIndex) { - memcpy(xfregs.rawProjection, _pProjection, sizeof(xfregs.rawProjection)); + if(constantIndex <= 0) + { + memcpy(xfregs.rawProjection, _pProjection, sizeof(xfregs.rawProjection)); + } + else + { + xfregs.rawProjection[constantIndex] = _pProjection[0]; + } bProjectionChanged = true; } diff --git a/Source/Core/VideoCommon/Src/VertexShaderManager.h b/Source/Core/VideoCommon/Src/VertexShaderManager.h index a7aa81ccfe..455ab6b8ad 100644 --- a/Source/Core/VideoCommon/Src/VertexShaderManager.h +++ b/Source/Core/VideoCommon/Src/VertexShaderManager.h @@ -31,15 +31,13 @@ public: // constant management static void SetConstants(); - static void SetViewport(float* _Viewport); + static void SetViewport(float* _Viewport, int constantIndex = -1); static void SetViewportChanged(); static void SetProjection(float* _pProjection, int constantIndex = -1); static void InvalidateXFRange(int start, int end); static void SetTexMatrixChangedA(u32 Value); static void SetTexMatrixChangedB(u32 Value); static void SetMaterialColor(int index, u32 data); - static void SetZScale(float data); - static void SetZOffset(float data); static void TranslateView(float x, float y); static void RotateView(float x, float y); diff --git a/Source/Core/VideoCommon/Src/XFMemory.h b/Source/Core/VideoCommon/Src/XFMemory.h index c2b3aa2e36..7b35ee153d 100644 --- a/Source/Core/VideoCommon/Src/XFMemory.h +++ b/Source/Core/VideoCommon/Src/XFMemory.h @@ -94,6 +94,13 @@ #define XFMEM_SETZSCALE 0x101c #define XFMEM_SETZOFFSET 0x101f #define XFMEM_SETPROJECTION 0x1020 +/*#define XFMEM_SETPROJECTIONB 0x1021 +#define XFMEM_SETPROJECTIONC 0x1022 +#define XFMEM_SETPROJECTIOND 0x1023 +#define XFMEM_SETPROJECTIONE 0x1024 +#define XFMEM_SETPROJECTIONF 0x1025 +#define XFMEM_SETPROJECTIONORTHO1 0x1026 +#define XFMEM_SETPROJECTIONORTHO2 0x1027*/ #define XFMEM_SETNUMTEXGENS 0x103f #define XFMEM_SETTEXMTXINFO 0x1040 #define XFMEM_SETPOSMTXINFO 0x1050 diff --git a/Source/Core/VideoCommon/Src/XFStructs.cpp b/Source/Core/VideoCommon/Src/XFStructs.cpp index 0ccc09c398..670e4bf188 100644 --- a/Source/Core/VideoCommon/Src/XFStructs.cpp +++ b/Source/Core/VideoCommon/Src/XFStructs.cpp @@ -49,6 +49,28 @@ void LoadXFReg(u32 transferSize, u32 baseAddress, u32 *pData) { xfregs.texcoords[address - XFMEM_SETPOSMTXINFO].postmtxinfo.hex = pData[i]; } + else if (address >= XFMEM_SETVIEWPORT && address <= XFMEM_SETVIEWPORT+5) + { + VertexManager::Flush(); + u32 Index = address - XFMEM_SETVIEWPORT; + VertexShaderManager::SetViewport((float*)&pData[i],Index); + PixelShaderManager::SetViewport((float*)&pData[i],Index); + if(Index == 0) + { + i += 5; + } + + } + else if (address >= XFMEM_SETPROJECTION && address <= XFMEM_SETPROJECTION+7) + { + VertexManager::Flush(); + u32 Index = address - XFMEM_SETPROJECTION; + VertexShaderManager::SetProjection((float*)&pData[i],Index); + if(Index == 0) + { + i += 7; + } + } else if (address < 0x2000) { u32 data = pData[i]; @@ -147,47 +169,13 @@ void LoadXFReg(u32 transferSize, u32 baseAddress, u32 *pData) //_assert_msg_(GX_XF, 0, "XF matrixindex1"); VertexShaderManager::SetTexMatrixChangedB(data); // ? break; - - case XFMEM_SETVIEWPORT: - VertexManager::Flush(); - VertexShaderManager::SetViewport((float*)&pData[i]); - PixelShaderManager::SetViewport((float*)&pData[i]); - i += 6; - break; - - case XFMEM_SETPROJECTION: - VertexManager::Flush(); - VertexShaderManager::SetProjection((float*)&pData[i]); - i += 7; - break; - case XFMEM_SETNUMTEXGENS: // GXSetNumTexGens if ((u32)xfregs.numTexGens != data) { VertexManager::Flush(); xfregs.numTexGens = data; } - break; - - // GXSetZScaleOffset ? - // Actually everything i tried didn't seem to change anything x) - // paper mario writes 16777216.0f, 1677721.75 - // Killer 7 writes 16777216.0f here - case XFMEM_SETZSCALE: - VertexManager::Flush(); - VertexShaderManager::SetZScale(*(float*)&data); - PixelShaderManager::SetZScale(*(float*)&data); - INFO_LOG(VIDEO, "Set ZScale : %x=%x\n", address, data); - break; - - // paper mario writes 16777216.0f, 5033165.0f - // Killer 7 alterns this between 16777216.0f and 16710107.0f - case XFMEM_SETZOFFSET: - VertexManager::Flush(); - VertexShaderManager::SetZOffset(*(float*)&data); - PixelShaderManager::SetZOffset(*(float*)&data); - INFO_LOG(VIDEO, "Set ZOffset : %x=%x\n", address, data); - break; + break; // -------------- // Unknown Regs