Skip to content

Commit c4d50ec

Browse files
committed
Refine code
1 parent f7b81f2 commit c4d50ec

File tree

1 file changed

+7
-14
lines changed

1 file changed

+7
-14
lines changed

renderer/core/graphics.c

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,12 @@ void framebuffer_release(framebuffer_t *framebuffer) {
3737

3838
void framebuffer_clear_color(framebuffer_t *framebuffer, vec4_t color) {
3939
int num_pixels = framebuffer->width * framebuffer->height;
40-
unsigned char r, g, b, a;
4140
int i;
42-
43-
r = float_to_uchar(color.x);
44-
g = float_to_uchar(color.y);
45-
b = float_to_uchar(color.z);
46-
a = float_to_uchar(color.w);
4741
for (i = 0; i < num_pixels; i++) {
48-
framebuffer->color_buffer[i * 4 + 0] = r;
49-
framebuffer->color_buffer[i * 4 + 1] = g;
50-
framebuffer->color_buffer[i * 4 + 2] = b;
51-
framebuffer->color_buffer[i * 4 + 3] = a;
42+
framebuffer->color_buffer[i * 4 + 0] = float_to_uchar(color.x);
43+
framebuffer->color_buffer[i * 4 + 1] = float_to_uchar(color.y);
44+
framebuffer->color_buffer[i * 4 + 2] = float_to_uchar(color.z);
45+
framebuffer->color_buffer[i * 4 + 3] = float_to_uchar(color.w);
5246
}
5347
}
5448

@@ -322,10 +316,9 @@ static int is_back_facing(vec3_t ndc_coords[3]) {
322316
vec3_t a = ndc_coords[0];
323317
vec3_t b = ndc_coords[1];
324318
vec3_t c = ndc_coords[2];
325-
float signed_area = 0;
326-
signed_area += a.x * b.y - a.y * b.x;
327-
signed_area += b.x * c.y - b.y * c.x;
328-
signed_area += c.x * a.y - c.y * a.x;
319+
float signed_area = a.x * b.y - a.y * b.x +
320+
b.x * c.y - b.y * c.x +
321+
c.x * a.y - c.y * a.x;
329322
return signed_area <= 0;
330323
}
331324

0 commit comments

Comments
 (0)