Handle multiple triangle strips with single-vertices behind the plane

This commit is contained in:
Luke Benstead 2018-07-10 20:27:15 +01:00
parent 5387734e6c
commit 2067115385
3 changed files with 11 additions and 3 deletions

View File

@ -78,15 +78,18 @@ void clipTriangleStrip(AlignedVector* vertices, AlignedVector* outBuffer) {
aligned_vector_at(vertices, i)
};
ClipVertex* v1 = sourceTriangle[0];
ClipVertex* v2 = sourceTriangle[1];
/* If we're on an odd vertex, we need to swap the order of the first two vertices, as that's what
* triangle strips do */
ClipVertex* v1 = (i % 2 == 0) ? sourceTriangle[0] : sourceTriangle[1];
ClipVertex* v2 = (i % 2 == 0) ? sourceTriangle[1] : sourceTriangle[0];
ClipVertex* v3 = sourceTriangle[2];
uint8_t visible = ((v1->xyz[2] <= 0) ? 4 : 0) | ((v2->xyz[2] <= 0) ? 2 : 0) | ((v3->xyz[2] <= 0) ? 1 : 0);
uint8_t startOfStrip = (i == 2) || (outBuffer->size > 2 && ((ClipVertex*) aligned_vector_back(outBuffer))->flags == VERTEX_CMD_EOL);
/* All visible, we're fine! */
if(visible == 0b111) {
if(i == 2) {
if(startOfStrip) {
aligned_vector_push_back(outBuffer, v1, 1);
aligned_vector_push_back(outBuffer, v2, 1);
}

View File

@ -70,6 +70,10 @@ void* aligned_vector_at(const AlignedVector* vector, const unsigned int index) {
return &vector->data[index * vector->element_size];
}
void* aligned_vector_back(AlignedVector* vector) {
return aligned_vector_at(vector, vector->size - 1);
}
void* aligned_vector_extend(AlignedVector* vector, const unsigned int additional_count) {
const unsigned int current = vector->size;
aligned_vector_resize(vector, vector->size + additional_count);

View File

@ -23,6 +23,7 @@ void* aligned_vector_extend(AlignedVector* vector, const unsigned int additional
void aligned_vector_clear(AlignedVector* vector);
void aligned_vector_shrink_to_fit(AlignedVector* vector);
void aligned_vector_cleanup(AlignedVector* vector);
void* aligned_vector_back(AlignedVector* vector);
#ifdef __cplusplus
}