From 8a70d4411010c8bceff146a6811aeeab3f38fdee Mon Sep 17 00:00:00 2001 From: Sergey Lipskiy Date: Sat, 6 Dec 2014 00:17:03 +0600 Subject: [PATCH] Disable near plane clipping for NoN ucodes. --- GBI.cpp | 11 +++++++++++ GBI.h | 1 + OpenGL.cpp | 6 ++++-- Shaders.h | 3 ++- 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/GBI.cpp b/GBI.cpp index 6318e7d4..866c7669 100644 --- a/GBI.cpp +++ b/GBI.cpp @@ -24,6 +24,7 @@ #include "ZSort.h" #include "CRC.h" #include "Log.h" +#include "OpenGL.h" #include "Debug.h" u32 last_good_ucode = (u32) -1; @@ -170,6 +171,16 @@ void GBIInfo::_makeCurrent(MicrocodeInfo * _pCurrent) case ZSortp: ZSort_Init(); break; case F3DEX2CBFD:F3DEX2CBFD_Init(); break; } + + if (m_pCurrent->NoN) { + // Disable near and far plane clipping + glEnable(GL_DEPTH_CLAMP); + // Enable Far clipping plane in vertex shader + glEnable(GL_CLIP_DISTANCE0); + } else { + glDisable(GL_DEPTH_CLAMP); + glDisable(GL_CLIP_DISTANCE0); + } } } diff --git a/GBI.h b/GBI.h index 63e5ecce..2c90b1ed 100644 --- a/GBI.h +++ b/GBI.h @@ -691,6 +691,7 @@ struct GBIInfo void loadMicrocode(u32 uc_start, u32 uc_dstart, u16 uc_dsize); u32 getMicrocodeType() const {return m_pCurrent != NULL ? m_pCurrent->type : NONE;} bool isHWLSupported() const; + bool isNoN() const { return m_pCurrent != NULL ? m_pCurrent->NoN != 0 : false; } private: void _makeCurrent(MicrocodeInfo * _pCurrent); diff --git a/OpenGL.cpp b/OpenGL.cpp index 2656e971..761f3736 100644 --- a/OpenGL.cpp +++ b/OpenGL.cpp @@ -556,11 +556,13 @@ void OGLRender::_updateStates() const } else { if ((gSP.geometryMode & G_ZBUFFER) || gDP.otherMode.depthSource == G_ZS_PRIM) { glEnable(GL_DEPTH_TEST); - glDisable(GL_DEPTH_CLAMP); + if (!GBI.isNoN()) + glDisable(GL_DEPTH_CLAMP); } else { glDisable(GL_DEPTH_TEST); - glEnable(GL_DEPTH_CLAMP); + if (!GBI.isNoN()) + glEnable(GL_DEPTH_CLAMP); } if ((gDP.changed & CHANGED_RENDERMODE) > 0) { diff --git a/Shaders.h b/Shaders.h index ff8736bd..0213f6b9 100644 --- a/Shaders.h +++ b/Shaders.h @@ -120,8 +120,9 @@ static const char* vertex_shader = " break; \n" " } \n" " vFogFragCoord = clamp(vFogFragCoord, 0.0, 1.0); \n" -" if ((uFogUsage&255) == 1 && uFogMode == 0) \n" +" if ((uFogUsage&255) == 1 && uFogMode == 0) \n" " vShadeColor.a = vFogFragCoord; \n" +" gl_ClipDistance[0] = gl_Position.w - gl_Position.z; \n" "} \n" ;