diff options
Diffstat (limited to 'src/core/clip.c')
-rw-r--r-- | src/core/clip.c | 44 |
1 files changed, 21 insertions, 23 deletions
diff --git a/src/core/clip.c b/src/core/clip.c index 23e18ce..37aa9d2 100644 --- a/src/core/clip.c +++ b/src/core/clip.c @@ -37,13 +37,16 @@ static LinearInterpolator clip_interpolator[REG_TOTAL] = { ssrS_lerpvec4, }; -uint clip_element_size[REG_TOTAL] = { - 4,4,4,4, /*float*/ - 8, 8, 8, 8,8, 8, 8, 8, /*Vec2*/ - 12,12,12,12,12,12,12,12,12,12,12,12, /*Vec3*/ - 16,16,16,16,16,16,16,16 /*Vec4*/ +static uint clip_element_size[REG_TOTAL] = { + sizeof(float),sizeof(float),sizeof(float),sizeof(float), /*float*/ + sizeof(Vec2), sizeof(Vec2), sizeof(Vec2), sizeof(Vec2),sizeof(Vec2), sizeof(Vec2), sizeof(Vec2), sizeof(Vec2), /*Vec2*/ + sizeof(Vec3),sizeof(Vec3),sizeof(Vec3),sizeof(Vec3),sizeof(Vec3),sizeof(Vec3),sizeof(Vec3),sizeof(Vec3),sizeof(Vec3),sizeof(Vec3),sizeof(Vec3),sizeof(Vec3), /*Vec3*/ + sizeof(Vec4),sizeof(Vec4),sizeof(Vec4),sizeof(Vec4),sizeof(Vec4),sizeof(Vec4),sizeof(Vec4),sizeof(Vec4) /*Vec4*/ }; +ClippedBuffer clip_buffer; +static ClippedBuffer temp_clip_buffer; + /*用来访问临时寄存器*/ byte* clip_buffer_data[REG_TOTAL] = { @@ -82,7 +85,7 @@ byte* clip_buffer_data[REG_TOTAL] = }; /*用来访问临时寄存器*/ -byte* temp_clip_buffer_data[REG_TOTAL] = +static byte* temp_clip_buffer_data[REG_TOTAL] = { temp_clip_buffer.temp_reg_num[0], temp_clip_buffer.temp_reg_num[1], @@ -198,8 +201,8 @@ static bool clip_against_plane( prev = &src_buffer->vertices[(i - 1 + src_buffer->count) % src_buffer->count]; curr = &src_buffer->vertices[i]; - previ = prev->vertex.index; - curri = curr->vertex.index; + previ = prev->index; + curri = curr->index; prev_inside = is_inside_plane(&prev->clip_coord, plane); curr_inside = is_inside_plane(&curr->clip_coord, plane); @@ -208,7 +211,7 @@ static bool clip_against_plane( t = get_intersect_ratio(&prev->clip_coord, &curr->clip_coord, plane); dst = &dst_buffer->vertices[idx]; ssrS_lerpvec4(t, &prev->clip_coord, &curr->clip_coord, &dst->clip_coord); - dst->vertex.index = idx; + dst->index = idx; /*set varying variables*/ if (varying) { for (j = 0; j < REG_TOTAL; ++j) { @@ -224,7 +227,7 @@ static bool clip_against_plane( if (curr_inside) { dst = &dst_buffer->vertices[idx]; *dst = *curr; - dst->vertex.index = idx; + dst->index = idx; /*copy varying variables*/ if (varying) { for (j = 0; j < REG_TOTAL; ++j) { @@ -247,18 +250,15 @@ static bool clip_against_plane( return 1; \ } -ClippedBuffer clip_buffer; -ClippedBuffer temp_clip_buffer; - bool clip_triangle( Vec4* c0, Vec4* c1, Vec4* c2 - , Vert* v0, Vert* v1, Vert* v2 + , uint i0, uint i1, uint i2 , uint varying_flag , ClippedBuffer* buffer ) { bool is_visible = is_vertex_visible(c0) - && is_vertex_visible(c1) - && is_vertex_visible(c2); + && is_vertex_visible(c1) + && is_vertex_visible(c2); if (is_visible) return 0; /*no need to clip*/ @@ -269,24 +269,22 @@ bool clip_triangle( temp_clip_buffer.count = 3; #define COPY_VERT(i) \ temp_clip_buffer.vertices[i].clip_coord = *c##i; \ - temp_clip_buffer.vertices[i].vertex = *v##i; \ - temp_clip_buffer.vertices[i].vertex.index = ##i; \ + temp_clip_buffer.vertices[i].index = ##i; \ COPY_VERT(0); COPY_VERT(1); COPY_VERT(2); -#undef COPY_VERT - int i, index, size; for (i = 0; i < REG_TOTAL; ++i) { index = open_regsi[i]; if (index == -1) break; size = registers[index].element_size; - ssrM_copy(&temp_clip_buffer_data[index][0], ®isters[index].data[v0->index*size], size); - ssrM_copy(&temp_clip_buffer_data[index][size], ®isters[index].data[v1->index*size], size); - ssrM_copy(&temp_clip_buffer_data[index][2*size], ®isters[index].data[v2->index*size], size); + ssrM_copy(&temp_clip_buffer_data[index][0], ®isters[index].data[i0*size], size); + ssrM_copy(&temp_clip_buffer_data[index][size], ®isters[index].data[i1*size], size); + ssrM_copy(&temp_clip_buffer_data[index][2*size], ®isters[index].data[i2*size], size); } +#undef COPY_VERT CLIP(POSITIVE_W, &temp_clip_buffer, buffer, temp_clip_buffer_data, clip_buffer_data); CLIP(POSITIVE_X, buffer, &temp_clip_buffer, clip_buffer_data, temp_clip_buffer_data); |