From 3d69003c5f50edf61ac4990d6f9d234a76d6a84f Mon Sep 17 00:00:00 2001 From: Luke Benstead Date: Mon, 13 Jun 2022 20:16:37 +0100 Subject: [PATCH] Allow disabling near-z --- GL/platforms/sh4.c | 16 ++++++++++++++++ GL/platforms/software.c | 13 +++++++++++++ GL/private.h | 5 ++--- GL/state.c | 6 ++++-- 4 files changed, 35 insertions(+), 5 deletions(-) diff --git a/GL/platforms/sh4.c b/GL/platforms/sh4.c index 9c63a0d..f18bdc2 100644 --- a/GL/platforms/sh4.c +++ b/GL/platforms/sh4.c @@ -188,6 +188,22 @@ void SceneListSubmit(void* src, int n) { const float h = GetVideoMode()->height; + if(!ZNEAR_CLIPPING_ENABLED) { + for(int i = 0; i < n; ++i, ++vertex) { + PREFETCH(vertex + 1); + if(glIsVertex(vertex->flags)) { + _glPerspectiveDivideVertex(vertex, h); + } + _glSubmitHeaderOrVertex(vertex); + } + + /* Wait for both store queues to complete */ + d = (uint32_t *)0xe0000000; + d[0] = d[8] = 0; + + return; + } + tri_count = 0; strip_count = 0; diff --git a/GL/platforms/software.c b/GL/platforms/software.c index a6f1974..94916a7 100644 --- a/GL/platforms/software.c +++ b/GL/platforms/software.c @@ -260,6 +260,19 @@ void SceneListSubmit(void* src, int n) { const float h = GetVideoMode()->height; + /* If Z-clipping is disabled, just fire everything over to the buffer */ + if(!ZNEAR_CLIPPING_ENABLED) { + for(int i = 0; i < n; ++i, ++vertex) { + PREFETCH(vertex + 1); + if(glIsVertex(vertex->flags)) { + _glPerspectiveDivideVertex(vertex, h); + } + _glSubmitHeaderOrVertex(vertex); + } + + return; + } + tri_count = 0; strip_count = 0; diff --git a/GL/private.h b/GL/private.h index 46287dd..ba286d1 100644 --- a/GL/private.h +++ b/GL/private.h @@ -279,9 +279,6 @@ typedef enum { struct SubmissionTarget; -float _glClipLineToNearZ(const Vertex* v1, const Vertex* v2, Vertex* vout); -void _glClipTriangleStrip(SubmissionTarget* target, uint8_t fladeShade); - PolyList* _glOpaquePolyList(); PolyList* _glPunchThruPolyList(); PolyList *_glTransparentPolyList(); @@ -385,6 +382,8 @@ GLboolean _glIsMipmapComplete(const TextureObject* obj); GLubyte* _glGetMipmapLocation(const TextureObject* obj, GLuint level); GLuint _glGetMipmapLevelCount(const TextureObject* obj); +extern GLboolean ZNEAR_CLIPPING_ENABLED; + extern GLboolean LIGHTING_ENABLED; GLboolean _glIsLightingEnabled(); diff --git a/GL/state.c b/GL/state.c index 5cf1fae..20f28c5 100644 --- a/GL/state.c +++ b/GL/state.c @@ -18,6 +18,8 @@ static GLenum FRONT_FACE = GL_CCW; static GLboolean CULLING_ENABLED = GL_FALSE; static GLboolean COLOR_MATERIAL_ENABLED = GL_FALSE; +GLboolean ZNEAR_CLIPPING_ENABLED = GL_TRUE; + GLboolean LIGHTING_ENABLED = GL_FALSE; /* Is the shared texture palette enabled? */ @@ -356,7 +358,7 @@ GLAPI void APIENTRY glEnable(GLenum cap) { _glEnableLight(cap & 0xF, GL_TRUE); break; case GL_NEARZ_CLIPPING_KOS: - _glEnableClipping(GL_TRUE); + ZNEAR_CLIPPING_ENABLED = GL_TRUE; break; case GL_POLYGON_OFFSET_POINT: case GL_POLYGON_OFFSET_LINE: @@ -418,7 +420,7 @@ GLAPI void APIENTRY glDisable(GLenum cap) { _glEnableLight(cap & 0xF, GL_FALSE); break; case GL_NEARZ_CLIPPING_KOS: - _glEnableClipping(GL_FALSE); + ZNEAR_CLIPPING_ENABLED = GL_FALSE; break; case GL_POLYGON_OFFSET_POINT: case GL_POLYGON_OFFSET_LINE: