GFX: Possible fix for depth range

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4044 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
omegadox 2009-08-24 06:48:00 +00:00
parent 689036c59c
commit 1427024a21
3 changed files with 18 additions and 16 deletions

View File

@ -91,8 +91,8 @@
#define XFMEM_SETMATRIXINDA 0x1018 #define XFMEM_SETMATRIXINDA 0x1018
#define XFMEM_SETMATRIXINDB 0x1019 #define XFMEM_SETMATRIXINDB 0x1019
#define XFMEM_SETVIEWPORT 0x101a #define XFMEM_SETVIEWPORT 0x101a
#define XFMEM_SETZSCALE 0x101c #define XFMEM_SETCONST_ZNEAR 0x101c
#define XFMEM_SETZOFFSET 0x101f #define XFMEM_SETCONST_ZFAR 0x101f
#define XFMEM_SETPROJECTION 0x1020 #define XFMEM_SETPROJECTION 0x1020
#define XFMEM_SETNUMTEXGENS 0x103f #define XFMEM_SETNUMTEXGENS 0x103f
#define XFMEM_SETTEXMTXINFO 0x1040 #define XFMEM_SETTEXMTXINFO 0x1040
@ -228,6 +228,7 @@ struct XFRegisters
bool bEnableDualTexTransform; bool bEnableDualTexTransform;
float rawViewport[6]; float rawViewport[6];
float rawProjection[7]; float rawProjection[7];
float depthRangeConst[2];
}; };

View File

@ -171,16 +171,18 @@ void LoadXFReg(u32 transferSize, u32 baseAddress, u32 *pData)
// GXSetZScaleOffset ? // GXSetZScaleOffset ?
// Actually everything i tried didn't seem to change anything x) // Actually everything i tried didn't seem to change anything x)
case XFMEM_SETZSCALE: // paper mario writes 16777216.0f, 1677721.75
// paper mario writes 16777216.0f, 1677721.75 // Killer 7 writes 16777216.0f here
// Killer 7 writes 16777216.0f here // WARN_LOG(VIDEO, "Set ZScale : %x=%x\n", address, data);
WARN_LOG(VIDEO, "Set ZScale : %x=%x\n", address, data); // paper mario writes 16777216.0f, 5033165.0f
break; // Killer 7 alterns this between 16777216.0f and 16710107.0f
// WARN_LOG(VIDEO, "Set ZOffset : %x=%x\n", address, data);
case XFMEM_SETZOFFSET: case XFMEM_SETCONST_ZNEAR:
// paper mario writes 16777216.0f, 5033165.0f xfregs.depthRangeConst[0] = *((float*)&data);
// Killer 7 alterns this between 16777216.0f and 16710107.0f break;
WARN_LOG(VIDEO, "Set ZOffset : %x=%x\n", address, data); case XFMEM_SETCONST_ZFAR:
xfregs.depthRangeConst[1] = *((float*)&data);
break; break;
// -------------- // --------------

View File

@ -181,6 +181,8 @@ void HandleCgError(CGcontext ctx, CGerror err, void* appdata)
// Init functions // Init functions
bool Renderer::Init() bool Renderer::Init()
{ {
xfregs.depthRangeConst[0] = 16777216.0f;
xfregs.depthRangeConst[1] = 16777216.0f;
bool bSuccess = true; bool bSuccess = true;
s_blendMode = 0; s_blendMode = 0;
s_MSAACoverageSamples = 0; s_MSAACoverageSamples = 0;
@ -1446,14 +1448,11 @@ void UpdateViewport()
int GLy = (int)ceil(Renderer::GetTargetHeight() - ((int)(xfregs.rawViewport[4] - xfregs.rawViewport[1] - 342 - scissorYOff)) * MValueY); int GLy = (int)ceil(Renderer::GetTargetHeight() - ((int)(xfregs.rawViewport[4] - xfregs.rawViewport[1] - 342 - scissorYOff)) * MValueY);
int GLWidth = (int)ceil(abs((int)(2 * xfregs.rawViewport[0])) * MValueX); int GLWidth = (int)ceil(abs((int)(2 * xfregs.rawViewport[0])) * MValueX);
int GLHeight = (int)ceil(abs((int)(2 * xfregs.rawViewport[1])) * MValueY); int GLHeight = (int)ceil(abs((int)(2 * xfregs.rawViewport[1])) * MValueY);
double GLNear = (xfregs.rawViewport[5] - xfregs.rawViewport[2]) / xfregs.depthRangeConst[0];
double GLFar = xfregs.rawViewport[5] / xfregs.depthRangeConst[1];
// Update the view port // Update the view port
glViewport(GLx, GLy, GLWidth, GLHeight); glViewport(GLx, GLy, GLWidth, GLHeight);
// GLDepthRange - this could be a source of trouble - see the viewport hacks.
// TODO : Should this use 16777216.0f or 16777215.0f ?
double GLNear = (xfregs.rawViewport[5] - xfregs.rawViewport[2]) / 16777215.0f;
double GLFar = xfregs.rawViewport[5] / 16777215.0f;
glDepthRange(GLNear, GLFar); glDepthRange(GLNear, GLFar);
// ------------------------------------- // -------------------------------------