From 5299badf58fdc199d353e8f8070812df3e8b24ad Mon Sep 17 00:00:00 2001 From: Luke Benstead Date: Wed, 3 Apr 2024 22:09:35 +0100 Subject: [PATCH] Only submit trailing vertices if the previous triangle was visible --- GL/platforms/sh4.c | 24 ++++++++++++------------ samples/zclip_trianglestrip/main.c | 2 +- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/GL/platforms/sh4.c b/GL/platforms/sh4.c index 8503136..53227e4 100644 --- a/GL/platforms/sh4.c +++ b/GL/platforms/sh4.c @@ -216,7 +216,7 @@ void SceneListSubmit(Vertex* vertices, int n) { #define SUBMIT_QUEUED_VERTEX(sflags) \ do { if(queued_vertex) { queued_vertex->flags = (sflags); _glPushHeaderOrVertex(queued_vertex); queued_vertex = NULL; } } while(0) - uint8_t visible_mask = 0; + int visible_mask = 0; sq = SQ_BASE_ADDRESS; @@ -237,21 +237,21 @@ void SceneListSubmit(Vertex* vertices, int n) { // we need to finalize this strip and move on SUBMIT_QUEUED_VERTEX(qv.flags); - _glPerspectiveDivideVertex(v0, h); - _glPushHeaderOrVertex(v0); + // If the last triangle was all visible, we need + // to submit the last two vertices, any clipped triangles + // would've + if(visible_mask == ALL_VISIBLE) { + _glPerspectiveDivideVertex(v0, h); + _glPushHeaderOrVertex(v0); - _glPerspectiveDivideVertex(v1, h); - _glPushHeaderOrVertex(v1); - i += 2; + _glPerspectiveDivideVertex(v1, h); + _glPushHeaderOrVertex(v1); + i += 2; + } continue; } - assert(!is_header(v2)); - - // FIXME: What if v1 or v2 are headers? Should we handle that or just - // assume the user has done something weird and all bets are off? - - int visible_mask = ( + visible_mask = ( (v0->xyz[2] >= -v0->w) << 0 | (v1->xyz[2] >= -v1->w) << 1 | (v2->xyz[2] >= -v2->w) << 2 diff --git a/samples/zclip_trianglestrip/main.c b/samples/zclip_trianglestrip/main.c index 4960c1c..064add8 100644 --- a/samples/zclip_trianglestrip/main.c +++ b/samples/zclip_trianglestrip/main.c @@ -64,7 +64,7 @@ int check_start() { return 0; } -static GLfloat movement = 0.0f; +static GLfloat movement = -10.0f; static GLfloat rotation = 0.0f; void update_movement() {