From b0f17ef9537bef1c7795fcd53291b6e3d885c57c Mon Sep 17 00:00:00 2001 From: Sergey Lipskiy Date: Sun, 15 Dec 2013 23:46:08 +0700 Subject: [PATCH] Add g_bN64DepthCompare parameter If it is true, N64 depth compare algorithm is used instead of OpenGL depth buffer. --- DepthBuffer.cpp | 4 +++- DepthBuffer.h | 2 ++ GLSLCombiner.cpp | 9 ++++++--- OpenGL.cpp | 20 +++++++++++--------- 4 files changed, 22 insertions(+), 13 deletions(-) diff --git a/DepthBuffer.cpp b/DepthBuffer.cpp index 7e2d50d7..1643a517 100644 --- a/DepthBuffer.cpp +++ b/DepthBuffer.cpp @@ -12,7 +12,9 @@ const GLuint ZlutImageUnit = 0; const GLuint TlutImageUnit = 1; const GLuint depthImageUnit = 2; -void DepthBuffer_Init() +bool g_bN64DepthCompare = true; + + void DepthBuffer_Init() { depthBuffer.current = NULL; depthBuffer.top = NULL; diff --git a/DepthBuffer.h b/DepthBuffer.h index 0626b5ab..de270f79 100644 --- a/DepthBuffer.h +++ b/DepthBuffer.h @@ -26,6 +26,8 @@ extern const GLuint ZlutImageUnit; extern const GLuint TlutImageUnit; extern const GLuint depthImageUnit; +extern bool g_bN64DepthCompare; + void DepthBuffer_Init(); void DepthBuffer_Destroy(); void DepthBuffer_SetBuffer( u32 address ); diff --git a/GLSLCombiner.cpp b/GLSLCombiner.cpp index 3226ff03..a5599f6d 100644 --- a/GLSLCombiner.cpp +++ b/GLSLCombiner.cpp @@ -401,9 +401,12 @@ GLSLCombiner::GLSLCombiner(Combiner *_color, Combiner *_alpha) { strcat(fragment_shader, " gl_FragColor = vec4(color2, alpha2); \n"); strcat(fragment_shader, " if (!alpha_test(gl_FragColor.a)) discard; \n"); - if (OGL.bImageTexture) -// strcat(fragment_shader, " bool bDC = depth_compare(); \n"); - strcat(fragment_shader, " if (!depth_compare()) discard; \n"); + if (OGL.bImageTexture) { + if (g_bN64DepthCompare) + strcat(fragment_shader, " if (!depth_compare()) discard; \n"); + else + strcat(fragment_shader, " depth_compare(); \n"); + } #ifdef USE_TOONIFY strcat(fragment_shader, " toonify(intensity); \n"); diff --git a/OpenGL.cpp b/OpenGL.cpp index f210e7a9..e61b0cbb 100644 --- a/OpenGL.cpp +++ b/OpenGL.cpp @@ -290,7 +290,13 @@ void OGL_InitStates() glEnableClientState( GL_FOG_COORDINATE_ARRAY_EXT ); } - glPolygonOffset( -3.0f, -3.0f ); + if (g_bN64DepthCompare) { + glDisable( GL_DEPTH_TEST ); + glDisable( GL_POLYGON_OFFSET_FILL ); + glDepthFunc( GL_ALWAYS ); + glDepthMask( FALSE ); + } else + glPolygonOffset( -3.0f, -3.0f ); glClearColor( 0.0f, 0.0f, 0.0f, 0.0f ); glClear( GL_COLOR_BUFFER_BIT ); @@ -559,8 +565,7 @@ void OGL_UpdateStates() else glDisable( GL_DEPTH_TEST ); - if (gDP.changed & CHANGED_RENDERMODE) - { + if (!g_bN64DepthCompare && (gDP.changed & CHANGED_RENDERMODE) > 0) { if (gDP.otherMode.depthCompare) glDepthFunc( GL_LEQUAL ); else @@ -568,13 +573,10 @@ void OGL_UpdateStates() OGL_UpdateDepthUpdate(); -// if (gDP.otherMode.depthMode == ZMODE_DEC) -// glEnable( GL_POLYGON_OFFSET_FILL ); -// else - { -// glPolygonOffset( -3.0f, -3.0f ); + if (gDP.otherMode.depthMode == ZMODE_DEC) + glEnable( GL_POLYGON_OFFSET_FILL ); + else glDisable( GL_POLYGON_OFFSET_FILL ); - } } if ((gDP.changed & CHANGED_ALPHACOMPARE) || (gDP.changed & CHANGED_RENDERMODE))