From 4292304df18baf31a7d3c78a1f1306979783c8ce Mon Sep 17 00:00:00 2001 From: Luke Benstead Date: Tue, 24 Mar 2020 13:58:44 +0000 Subject: [PATCH] Implement glClearDepth --- GL/draw.c | 11 ++++++++--- GL/state.c | 8 ++++---- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/GL/draw.c b/GL/draw.c index d8217c8..79a00ff 100644 --- a/GL/draw.c +++ b/GL/draw.c @@ -1171,10 +1171,15 @@ GL_FORCE_INLINE void divide(SubmissionTarget* target) { float f = MATH_fsrra(vertex->w * vertex->w); vertex->xyz[0] *= f; vertex->xyz[1] *= f; + vertex->xyz[2] = f; - /* Scale depending on glDepthRange */ - vertex->xyz[2] = 1.0f - ((DEPTH_RANGE_MULTIPLIER_L * vertex->xyz[2] * f) + DEPTH_RANGE_MULTIPLIER_H); - + /* FIXME: Consider taking glDepthRange into account. PVR is designed to use invW rather + * than Z which is unlike most GPUs - this apparently provides advantages. + * + * This can be done (if Z is between -1 and 1) with: + * + * //((DEPTH_RANGE_MULTIPLIER_L * vertex->xyz[2] * f) + DEPTH_RANGE_MULTIPLIER_H); + */ ++vertex; } } diff --git a/GL/state.c b/GL/state.c index 72a54e2..a705526 100644 --- a/GL/state.c +++ b/GL/state.c @@ -274,6 +274,7 @@ void _glInitContext() { GL_CONTEXT.fmt.uv = PVR_UVFMT_32BIT; GL_CONTEXT.gen.color_clamp = PVR_CLRCLAMP_DISABLE; + glClearDepth(1.0f); glDepthFunc(GL_LESS); glDepthMask(GL_TRUE); glFrontFace(GL_CCW); @@ -439,13 +440,12 @@ GLAPI void APIENTRY glClearColor(GLfloat r, GLfloat g, GLfloat b, GLfloat a) { /* Depth Testing */ GLAPI void APIENTRY glClearDepthf(GLfloat depth) { - _GL_UNUSED(depth); - + glClearDepth(depth); } GLAPI void APIENTRY glClearDepth(GLfloat depth) { - _GL_UNUSED(depth); - + /* We reverse because using invW means that farther Z == lower number */ + pvr_set_zclip(1.0f - depth); } GLAPI void APIENTRY glDrawBuffer(GLenum mode) {