diff --git a/GL/draw.c b/GL/draw.c index 04e2c3e..c4b3f17 100644 --- a/GL/draw.c +++ b/GL/draw.c @@ -925,25 +925,6 @@ static void light(SubmissionTarget* target) { _glPerformLighting(vertex, ES, target->count); } -#define PVR_MIN_Z 0.2f -#define PVR_MAX_Z 1.0 + PVR_MIN_Z - -GL_FORCE_INLINE void divide(SubmissionTarget* target) { - TRACE(); - - /* Perform perspective divide on each vertex */ - Vertex* vertex = _glSubmissionTargetStart(target); - - ITERATE(target->count) { - float f = MATH_Fast_Invert(vertex->w); - vertex->xyz[0] *= f; - vertex->xyz[1] *= f; - vertex->xyz[2] *= f; - vertex->xyz[2] = MAX(1.0f - (vertex->xyz[2] * 0.5f + 0.5f), 0.0001f); - ++vertex; - } -} - GL_FORCE_INLINE void push(PVRHeader* header, GLboolean multiTextureHeader, PolyList* activePolyList, GLshort textureUnit) { TRACE(); @@ -1088,7 +1069,6 @@ GL_FORCE_INLINE void submitVertices(GLenum mode, GLsizei first, GLuint count, GL } - divide(target); push(_glSubmissionTargetHeader(target), GL_FALSE, target->output, 0); /* diff --git a/GL/flush.c b/GL/flush.c index 14d4426..c1c1e96 100644 --- a/GL/flush.c +++ b/GL/flush.c @@ -45,6 +45,21 @@ static inline ListIterator* begin(void* src, int n) { return (n) ? it : NULL; } +GL_FORCE_INLINE isVertex(const Vertex* vertex) { + return ( + vertex->flags == PVR_CMD_VERTEX || + vertex->flags == PVR_CMD_VERTEX_EOL + ); +} + +static inline void perspective_divide(Vertex* vertex) { + float f = MATH_Fast_Invert(vertex->w); + vertex->xyz[0] *= f; + vertex->xyz[1] *= f; + vertex->xyz[2] *= f; + vertex->xyz[2] = MAX(1.0f - (vertex->xyz[2] * 0.5f + 0.5f), 0.0001f); +} + static void pvr_list_submit(void *src, int n) { GLuint *d = TA_SQ_ADDR; @@ -53,6 +68,10 @@ static void pvr_list_submit(void *src, int n) { while(it) { __asm__("pref @%0" : : "r"(it->current + 1)); /* prefetch 64 bytes for next loop */ if(it->current->flags != DEAD) { + if(isVertex(it->current)) { + perspective_divide(it->current); + } + GLuint* s = (GLuint*) it->current; d[0] = *(s++);