diff --git a/GL/clip.c b/GL/clip.c index d0fafc2..bfa4775 100644 --- a/GL/clip.c +++ b/GL/clip.c @@ -23,11 +23,11 @@ void _glEnableClipping(unsigned char v) { ZCLIP_ENABLED = v; } -void inline _glClipLineToNearZ(const Vertex* v1, const Vertex* v2, Vertex* vout, float* t) { +inline float _glClipLineToNearZ(const Vertex* v1, const Vertex* v2, Vertex* vout) { const float d0 = v1->w + v1->xyz[2]; const float d1 = v2->w + v2->xyz[2]; - *t = d0 / (d0 - d1); + float t = d0 / (d0 - d1); const float vec [] = { v2->xyz[0] - v1->xyz[0], @@ -35,9 +35,11 @@ void inline _glClipLineToNearZ(const Vertex* v1, const Vertex* v2, Vertex* vout, v2->xyz[2] - v1->xyz[2] }; - vout->xyz[0] = MATH_fmac(vec[0], (*t), v1->xyz[0]); - vout->xyz[1] = MATH_fmac(vec[1], (*t), v1->xyz[1]); - vout->xyz[2] = MATH_fmac(vec[2], (*t), v1->xyz[2]); + vout->xyz[0] = MATH_fmac(vec[0], t, v1->xyz[0]); + vout->xyz[1] = MATH_fmac(vec[1], t, v1->xyz[1]); + vout->xyz[2] = MATH_fmac(vec[2], t, v1->xyz[2]); + + return t; } GL_FORCE_INLINE void interpolateFloat(const float v1, const float v2, const float t, float* out) { @@ -106,16 +108,15 @@ void _glClipTriangle(const Triangle* triangle, const uint8_t visible, Submission if(i > 0) { uint8_t lastIndex = (i == 3) ? 2 : thisIndex - 1; - if(lastVisible < 255 && lastVisible != thisVisible) { + if(lastVisible != thisVisible) { const Vertex* v1 = &vertices[lastIndex]; const Vertex* v2 = &vertices[thisIndex]; const VertexExtra* ve1 = &extras[lastIndex]; const VertexExtra* ve2 = &extras[thisIndex]; - float t; + float t = _glClipLineToNearZ(v1, v2, &next); - _glClipLineToNearZ(v1, v2, &next, &t); interpolateFloat(v1->w, v2->w, t, &next.w); interpolateVec2(v1->uv, v2->uv, t, next.uv); diff --git a/GL/draw.c b/GL/draw.c index 79a00ff..7aaa023 100644 --- a/GL/draw.c +++ b/GL/draw.c @@ -1219,7 +1219,7 @@ GL_FORCE_INLINE void push(PVRHeader* header, GLboolean multiTextureHeader, PolyL */ } -#define DEBUG_CLIPPING 0 +#define DEBUG_CLIPPING 1 GL_FORCE_INLINE void submitVertices(GLenum mode, GLsizei first, GLuint count, GLenum type, const GLvoid* indices) { TRACE(); @@ -1321,10 +1321,10 @@ GL_FORCE_INLINE void submitVertices(GLenum mode, GLsizei first, GLuint count, GL uint32_t i = 0; fprintf(stderr, "=========\n"); - for(i = offset; i < activeList->vector.size; ++i) { - ClipVertex* v = aligned_vector_at(&activeList->vector, i); + for(i = 0; i < target->count; ++i) { + Vertex* v = aligned_vector_at(&target->output->vector, target->start_offset + i); if(v->flags == 0xe0000000 || v->flags == 0xf0000000) { - fprintf(stderr, "(%f, %f, %f) -> %x\n", v->xyz[0], v->xyz[1], v->xyz[2], v->flags); + fprintf(stderr, "(%f, %f, %f, %f) -> %x\n", v->xyz[0], v->xyz[1], v->xyz[2], v->w, v->flags); } else { fprintf(stderr, "%x\n", *((uint32_t*)v)); } @@ -1337,10 +1337,10 @@ GL_FORCE_INLINE void submitVertices(GLenum mode, GLsizei first, GLuint count, GL #if DEBUG_CLIPPING fprintf(stderr, "--------\n"); - for(i = offset; i < activeList->vector.size; ++i) { - ClipVertex* v = aligned_vector_at(&activeList->vector, i); + for(i = 0; i < target->count; ++i) { + Vertex* v = aligned_vector_at(&target->output->vector, target->start_offset + i); if(v->flags == 0xe0000000 || v->flags == 0xf0000000) { - fprintf(stderr, "(%f, %f, %f) -> %x\n", v->xyz[0], v->xyz[1], v->xyz[2], v->flags); + fprintf(stderr, "(%f, %f, %f, %f) -> %x\n", v->xyz[0], v->xyz[1], v->xyz[2], v->w, v->flags); } else { fprintf(stderr, "%x\n", *((uint32_t*)v)); } diff --git a/GL/private.h b/GL/private.h index 92d0660..094f29b 100644 --- a/GL/private.h +++ b/GL/private.h @@ -239,7 +239,7 @@ typedef enum { struct SubmissionTarget; -void _glClipLineToNearZ(const Vertex* v1, const Vertex* v2, Vertex* vout, float* t); +float _glClipLineToNearZ(const Vertex* v1, const Vertex* v2, Vertex* vout); void _glClipTriangleStrip(SubmissionTarget* target, uint8_t fladeShade); PolyList *_glActivePolyList(); diff --git a/samples/zclip_triangle/main.c b/samples/zclip_triangle/main.c index b409773..46ea274 100644 --- a/samples/zclip_triangle/main.c +++ b/samples/zclip_triangle/main.c @@ -44,6 +44,7 @@ void ReSizeGLScene(int Width, int Height) /* The main drawing function. */ void DrawGLScene() { + static GLfloat rotation = 0.0f; static GLfloat movement = 0.0f; static GLboolean increasing = GL_TRUE; @@ -59,6 +60,9 @@ void DrawGLScene() movement -= 0.05f; } + rotation += 0.5f; + rotation = (rotation > 360.0f) ? rotation - 360.0f : rotation; + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer glLoadIdentity(); // Reset The View @@ -66,6 +70,7 @@ void DrawGLScene() glPushMatrix(); glTranslatef(0.0f, -1.0f, movement); + glRotatef(rotation, 0.0f, 1.0f, 0.0f); glBegin(GL_TRIANGLES); glColor3f(1.0f, 0.0f, 0.0f);