Fix depth issues

This commit is contained in:
Luke Benstead 2020-04-06 20:50:26 +01:00
parent f3b1848879
commit 8add817086
4 changed files with 39 additions and 10 deletions

View File

@ -1172,10 +1172,14 @@ GL_FORCE_INLINE void divide(SubmissionTarget* target) {
float f = MATH_Fast_Invert(vertex->w); float f = MATH_Fast_Invert(vertex->w);
vertex->xyz[0] *= f; vertex->xyz[0] *= f;
vertex->xyz[1] *= f; vertex->xyz[1] *= f;
vertex->xyz[2] = vertex->w;
/* FIXME: Consider taking glDepthRange into account. PVR is designed to use invW rather /* We have to use 1/z instead of reusing 1/w from above because
* than Z which is unlike most GPUs - this apparently provides advantages. * orthographic projections always product a W == 1 and so would not
* correctly render ordered transparent surfaces */
vertex->xyz[2] = MATH_Fast_Invert(vertex->xyz[2]);
/* FIXME: Consider taking glDepthRange into account. PVR is designed to use 1/w
* which is unlike most GPUs - this apparently provides advantages.
* *
* This can be done (if Z is between -1 and 1) with: * This can be done (if Z is between -1 and 1) with:
* *

View File

@ -63,17 +63,17 @@ static int _calc_pvr_depth_test() {
case GL_NEVER: case GL_NEVER:
return PVR_DEPTHCMP_NEVER; return PVR_DEPTHCMP_NEVER;
case GL_LESS: case GL_LESS:
return PVR_DEPTHCMP_LESS; return PVR_DEPTHCMP_GREATER;
case GL_EQUAL: case GL_EQUAL:
return PVR_DEPTHCMP_EQUAL; return PVR_DEPTHCMP_EQUAL;
case GL_LEQUAL: case GL_LEQUAL:
return PVR_DEPTHCMP_LEQUAL; return PVR_DEPTHCMP_GEQUAL;
case GL_GREATER: case GL_GREATER:
return PVR_DEPTHCMP_GREATER; return PVR_DEPTHCMP_LESS;
case GL_NOTEQUAL: case GL_NOTEQUAL:
return PVR_DEPTHCMP_NOTEQUAL; return PVR_DEPTHCMP_NOTEQUAL;
case GL_GEQUAL: case GL_GEQUAL:
return PVR_DEPTHCMP_GEQUAL; return PVR_DEPTHCMP_LEQUAL;
break; break;
case GL_ALWAYS: case GL_ALWAYS:
default: default:

View File

@ -7,7 +7,7 @@ void InitGL(int Width, int Height) // We call this right after our OpenG
{ {
glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // This Will Clear The Background Color To Black glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // This Will Clear The Background Color To Black
glClearDepth(1.0); // Enables Clearing Of The Depth Buffer glClearDepth(1.0); // Enables Clearing Of The Depth Buffer
glDepthFunc(GL_LESS); // The Type Of Depth Test To Do glDepthFunc(GL_LEQUAL); // The Type Of Depth Test To Do
glEnable(GL_DEPTH_TEST); // Enables Depth Testing glEnable(GL_DEPTH_TEST); // Enables Depth Testing
glShadeModel(GL_SMOOTH); // Enables Smooth Color Shading glShadeModel(GL_SMOOTH); // Enables Smooth Color Shading
@ -60,22 +60,47 @@ void DrawGLScene()
glDepthFunc(GL_LEQUAL); glDepthFunc(GL_LEQUAL);
DrawSquare(1.0, 1, 0, 0, -5.0f); DrawSquare(1.0, 1, 0, 0, -5.0f);
glPushMatrix();
glTranslatef(0, -1.5, 0);
DrawSquare(1.0, 1, 0, 0, -4.9f);
glPopMatrix();
glTranslatef(1.1, 0, 0); glTranslatef(1.1, 0, 0);
glDepthFunc(GL_EQUAL); glDepthFunc(GL_EQUAL);
DrawSquare(1.0, 1, 0, 0, -5.0f); DrawSquare(1.0, 1, 0, 0, -5.0f);
glPushMatrix();
glTranslatef(0, -1.5, 0);
DrawSquare(1.0, 1, 0, 0, -5.0f);
glPopMatrix();
glTranslatef(1.1, 0, 0); glTranslatef(1.1, 0, 0);
glDepthFunc(GL_GEQUAL); glDepthFunc(GL_GEQUAL);
DrawSquare(1.0, 1, 0, 0, -5.0f); DrawSquare(1.0, 1, 0, 0, -5.0f);
glPushMatrix();
glTranslatef(0, -1.5, 0);
DrawSquare(1.0, 1, 0, 0, -5.1f);
glPopMatrix();
glTranslatef(1.1, 0, 0); glTranslatef(1.1, 0, 0);
glDepthFunc(GL_LESS); glDepthFunc(GL_LESS);
DrawSquare(1.0, 1, 0, 0, -4.9f); DrawSquare(1.0, 1, 0, 0, -4.9f);
glPushMatrix();
glTranslatef(0, -1.5, 0);
DrawSquare(1.0, 1, 0, 0, -4.8f);
glPopMatrix();
glTranslatef(1.1, 0, 0); glTranslatef(1.1, 0, 0);
glDepthFunc(GL_GREATER); glDepthFunc(GL_GREATER);
DrawSquare(1.0, 1, 0, 0, -5.1f); DrawSquare(1.0, 1, 0, 0, -5.1f);
glPushMatrix();
glTranslatef(0, -1.5, 0);
DrawSquare(1.0, 1, 0, 0, -5.2f);
glPopMatrix();
// swap buffers to display, since we're double buffered. // swap buffers to display, since we're double buffered.
glKosSwapBuffers(); glKosSwapBuffers();
} }

View File

@ -137,9 +137,9 @@ void InitGL(int Width, int Height) // We call this right after our OpenG
{ {
LoadGLTextures(); LoadGLTextures();
glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // This Will Clear The Background Color To Black glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // This Will Clear The Background Color To Black
glClearDepth(1.0); // Enables Clearing Of The Depth Buffer glClearDepth(1.0); // Enables Clearing Of The Depth Buffer
glDepthFunc(GL_LESS); // The Type Of Depth Test To Do glDepthFunc(GL_LEQUAL); // The Type Of Depth Test To Do
glEnable(GL_DEPTH_TEST); // Enables Depth Testing glEnable(GL_DEPTH_TEST); // Enables Depth Testing
glShadeModel(GL_SMOOTH); // Enables Smooth Color Shading glShadeModel(GL_SMOOTH); // Enables Smooth Color Shading
glEnable(GL_TEXTURE_2D); glEnable(GL_TEXTURE_2D);