summaryrefslogtreecommitdiff
path: root/graphics.c
diff options
context:
space:
mode:
Diffstat (limited to 'graphics.c')
-rwxr-xr-xgraphics.c38
1 files changed, 37 insertions, 1 deletions
diff --git a/graphics.c b/graphics.c
index e46dca5..79e3a6c 100755
--- a/graphics.c
+++ b/graphics.c
@@ -333,6 +333,8 @@ void draw_pixels_to_buffer(Pixel_Buffer dst, Box area, Pixel_Buffer src) {
if (area.width < EPSILON || area.height < EPSILON)
return;
+ PROFILER_begin(PROFILE_DRAW_PIXELS);
+
i64 i0 = (i64) floor(area.x);
i64 i1 = (i64) floor(area.x + area.width);
i64 j0 = (i64) floor(area.y);
@@ -356,9 +358,13 @@ void draw_pixels_to_buffer(Pixel_Buffer dst, Box area, Pixel_Buffer src) {
for (; d < d_end; ++d, ii += di)
put_pixel_(d, s[(i64) ii]);
}
+
+ PROFILER_end(PROFILE_DRAW_PIXELS);
}
void fill_rectangle_to_buffer(Pixel_Buffer dst, vec4_f32 color, Box area) {
+ PROFILER_begin(PROFILE_FILL_RECTANGLE);
+
i64 i0 = (i64) floor(area.x);
i64 i1 = (i64) floor(area.x + area.width);
i64 j0 = (i64) floor(area.y);
@@ -375,9 +381,13 @@ void fill_rectangle_to_buffer(Pixel_Buffer dst, vec4_f32 color, Box area) {
for (; p < p_end; ++p)
put_pixel_(p, color);
}
+
+ PROFILER_end(PROFILE_FILL_RECTANGLE);
}
void fill_triangle_to_buffer(Pixel_Buffer dst, vec4_f32 color, vec2 vertices[3]) {
+ PROFILER_begin(PROFILE_FILL_TRIANGLE);
+
f64 x0 = vertices[0].x;
f64 y0 = vertices[0].y;
f64 x1 = vertices[1].x;
@@ -418,6 +428,8 @@ void fill_triangle_to_buffer(Pixel_Buffer dst, vec4_f32 color, vec2 vertices[3])
for (; p < p_end; ++p)
put_pixel_(p, color);
}
+
+ PROFILER_end(PROFILE_FILL_TRIANGLE);
}
static void triangles_area_(f64 *x0, f64 *y0, f64 *x1, f64 *y1, vec2 p, vec2 s, i64 num, vec2 *v) {
@@ -438,6 +450,8 @@ static void triangles_area_(f64 *x0, f64 *y0, f64 *x1, f64 *y1, vec2 p, vec2 s,
}
void fill_triangles_to_buffer(Pixel_Buffer dst, vec4_f32 color, vec2 position, vec2 scale, i64 num_triangles, vec2 *vertices) {
+ PROFILER_begin(PROFILE_FILL_TRIANGLES);
+
f64 x0, y0, x1, y1;
triangles_area_(&x0, &y0, &x1, &y1, position, scale, num_triangles, vertices);
@@ -455,9 +469,13 @@ void fill_triangles_to_buffer(Pixel_Buffer dst, vec4_f32 color, vec2 position, v
put_pixel_(dst.pixels + j * dst.stride + i, color);
break;
}
+
+ PROFILER_end(PROFILE_FILL_TRIANGLES);
}
void fill_quad_to_buffer(Pixel_Buffer dst, vec4_f32 color, vec2 vertices[4]) {
+ PROFILER_begin(PROFILE_FILL_QUAD);
+
f64 x0 = vertices[0].x;
f64 y0 = vertices[0].y;
f64 x1 = vertices[1].x;
@@ -500,9 +518,13 @@ void fill_quad_to_buffer(Pixel_Buffer dst, vec4_f32 color, vec2 vertices[4]) {
for (; p < p_end; ++p)
put_pixel_(p, color);
}
+
+ PROFILER_end(PROFILE_FILL_QUAD);
}
void fill_ellipse_to_buffer(Pixel_Buffer dst, vec4_f32 color, Box area) {
+ PROFILER_begin(PROFILE_FILL_ELLIPSE);
+
f64 y1 = area.y + area.height;
i64 j0 = (i64) floor(area.y);
@@ -515,7 +537,7 @@ void fill_ellipse_to_buffer(Pixel_Buffer dst, vec4_f32 color, Box area) {
f64 half_h = area.height / 2.0;
if (half_h < EPSILON)
- return;
+ goto _finish;
f64 inv_half_h = 1.0 / half_h;
f64 cx = area.x + half_w;
@@ -539,6 +561,9 @@ void fill_ellipse_to_buffer(Pixel_Buffer dst, vec4_f32 color, Box area) {
for (; p < p_end; ++p)
put_pixel_(p, color);
}
+
+_finish:
+ PROFILER_end(PROFILE_FILL_ELLIPSE);
}
static b8 quad_from_line_(vec2 *dst, vec2 vertices[2], f64 width) {
@@ -572,11 +597,14 @@ static b8 quad_from_line_(vec2 *dst, vec2 vertices[2], f64 width) {
void fill_line_to_buffer(Pixel_Buffer dst, vec4_f32 color, vec2 vertices[2], f64 width) {
if (width < EPSILON) return;
+ PROFILER_begin(PROFILE_FILL_LINE);
+
vec2 quad[4];
if (!quad_from_line_(quad, vertices, width)) return;
fill_quad_to_buffer(dst, color, quad);
// TODO: Also render line ends as circles.
+ PROFILER_end(PROFILE_FILL_LINE);
}
static i64 char_column_offset_(c32 c, i64 column_index) {
@@ -816,6 +844,8 @@ void draw_text_area_to_buffer(Pixel_Buffer dst, i32 font, vec4_f32 color, Box ar
if (text == NULL || num_chars <= 0 || max_size.x < EPSILON || max_size.y < EPSILON)
return;
+ PROFILER_begin(PROFILE_DRAW_TEXT_AREA);
+
i64 num_columns = enum_text_columns_(num_chars, text);
i64 num_rows = enum_text_rows_(num_chars, text);
@@ -831,12 +861,16 @@ void draw_text_area_to_buffer(Pixel_Buffer dst, i32 font, vec4_f32 color, Box ar
ky = k * max_size.y;
draw_text_(dst, color, area.x, area.y, kx, ky, num_chars, text);
+
+ PROFILER_end(PROFILE_DRAW_TEXT_AREA);
}
void draw_text_cursor_to_buffer(Pixel_Buffer dst, i32 font, vec4_f32 color, Box area, vec2 max_size, i64 num_chars, c32 *text, i64 cursor, i64 selection) {
if (max_size.x < EPSILON || max_size.y < EPSILON)
return;
+ PROFILER_begin(PROFILE_DRAW_TEXT_CURSOR);
+
i64 num_columns = enum_text_columns_(num_chars, text);
i64 num_rows = enum_text_rows_(num_chars, text);
i64 cursor_x = text_cursor_(cursor, text);
@@ -921,6 +955,8 @@ void draw_text_cursor_to_buffer(Pixel_Buffer dst, i32 font, vec4_f32 color, Box
.height = ky * (CHAR_NUM_BITS_Y_ - 1),
}
);
+
+ PROFILER_end(PROFILE_DRAW_TEXT_CURSOR);
}
// ================================================================