Refactor the perspective divide to work with glDepthRange

This commit is contained in:
Luke Benstead 2019-09-08 17:27:56 +01:00
parent 200db3593e
commit 3af18cb514
4 changed files with 14 additions and 7 deletions

View File

@ -811,6 +811,7 @@ static void generate(SubmissionTarget* target, const GLenum mode, const GLsizei
genTriangleStrip(_glSubmissionTargetStart(target), count);
break;
default:
fprintf(stderr, "Unhandled mode %d\n", (int) mode);
assert(0 && "Not Implemented");
}
@ -977,9 +978,12 @@ static void divide(SubmissionTarget* target) {
Vertex* vertex = _glSubmissionTargetStart(target);
ITERATE(target->count) {
vertex->xyz[2] = 1.0f / vertex->w;
vertex->xyz[0] *= vertex->xyz[2];
vertex->xyz[1] *= vertex->xyz[2];
// fprintf(stderr, "%f %f %f -> ", vertex->xyz[0], vertex->xyz[1], vertex->xyz[2]);
vertex->xyz[0] /= vertex->w;
vertex->xyz[1] /= vertex->w;
vertex->xyz[2] /= vertex->w;
vertex->xyz[2] = (DEPTH_RANGE_MULTIPLIER_L * (1.0f / vertex->xyz[2])) + DEPTH_RANGE_MULTIPLIER_H;
// fprintf(stderr, "%f %f %f %f\n", vertex->xyz[0], vertex->xyz[1], vertex->xyz[2], vertex->w);
++vertex;
}
}

View File

@ -15,7 +15,8 @@
static GLfloat gl_viewport_scale[3], gl_viewport_offset[3];
/* Depth range */
static GLclampf gl_depthrange_near, gl_depthrange_far;
GLfloat DEPTH_RANGE_MULTIPLIER_L = (1 - 0) / 2;
GLfloat DEPTH_RANGE_MULTIPLIER_H = (0 + 1) / 2;
/* Viewport size */
static GLint gl_viewport_x1, gl_viewport_y1, gl_viewport_width, gl_viewport_height;
@ -316,8 +317,8 @@ void APIENTRY glDepthRange(GLclampf n, GLclampf f) {
if(f < 0.0f) f = 0.0f;
else if(f > 1.0f) f = 1.0f;
gl_depthrange_near = n;
gl_depthrange_far = f;
DEPTH_RANGE_MULTIPLIER_L = (f - n) / 2.0f;
DEPTH_RANGE_MULTIPLIER_H = (n + f) / 2.0f;
}
/* Vector Cross Product - Used by glhLookAtf2 */

View File

@ -195,6 +195,9 @@ void _glMatrixLoadModelView();
void _glMatrixLoadTexture();
void _glApplyRenderMatrix();
extern GLfloat DEPTH_RANGE_MULTIPLIER_L;
extern GLfloat DEPTH_RANGE_MULTIPLIER_H;
matrix_t* _glGetProjectionMatrix();
matrix_t* _glGetModelViewMatrix();

View File

@ -421,7 +421,6 @@ GLAPI void APIENTRY glReadBuffer(GLenum mode) {
GLAPI void APIENTRY glDepthMask(GLboolean flag) {
GL_CONTEXT.depth.write = (flag == GL_TRUE) ? PVR_DEPTHWRITE_ENABLE : PVR_DEPTHWRITE_DISABLE;
GL_CONTEXT.depth.comparison = _calc_pvr_depth_test();
}
GLAPI void APIENTRY glDepthFunc(GLenum func) {