summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMitya Selivanov <automainint@guattari.tech>2025-03-23 23:19:03 +0100
committerMitya Selivanov <automainint@guattari.tech>2025-03-23 23:19:03 +0100
commitc5f64725155bb954e2ec5003e8eb5cad5ba861c4 (patch)
tree9e73c7cbece63c8e492709947dbcd42cf87babb6
parent9e716fef26f8bf871e877b1de6f16b0ed0d9713c (diff)
downloadreduced_system_layer-c5f64725155bb954e2ec5003e8eb5cad5ba861c4.zip
Fix triangles area
-rwxr-xr-xgraphics.c61
-rwxr-xr-xreduced_system_layer.c33
2 files changed, 50 insertions, 44 deletions
diff --git a/graphics.c b/graphics.c
index 34d3021..1b079ec 100755
--- a/graphics.c
+++ b/graphics.c
@@ -122,7 +122,8 @@ typedef struct graphics_request_ {
} triangle;
struct {
vec4_f32 color;
- Box area;
+ vec2 position;
+ vec2 scale;
i64 num_triangles;
vec2 * vertices;
} triangles;
@@ -213,7 +214,7 @@ b8 hit_line (vec2 vertices[2], f64 width, vec2 point);
void draw_pixels_to_buffer (Pixel_Buffer dst, Box area, Pixel_Buffer src);
void fill_rectangle_to_buffer (Pixel_Buffer dst, vec4_f32 color, Box area);
void fill_triangle_to_buffer (Pixel_Buffer dst, vec4_f32 color, vec2 vertices[3]);
-void fill_triangles_to_buffer (Pixel_Buffer dst, vec4_f32 color, Box area, i64 num_triangles, vec2 *vertices);
+void fill_triangles_to_buffer (Pixel_Buffer dst, vec4_f32 color, vec2 position, vec2 scale, i64 num_triangles, vec2 *vertices);
void fill_quad_to_buffer (Pixel_Buffer dst, vec4_f32 color, vec2 vertices[4]);
void fill_ellipse_to_buffer (Pixel_Buffer dst, vec4_f32 color, Box area);
void fill_line_to_buffer (Pixel_Buffer dst, vec4_f32 color, vec2 vertices[2], f64 width);
@@ -223,7 +224,7 @@ void draw_text_cursor_to_buffer(Pixel_Buffer dst, vec4_f32 color, Box area, vec2
void draw_pixels_cached (Box area, Pixel_Buffer src);
void fill_rectangle_cached (vec4_f32 color, Box area);
void fill_triangle_cached (vec4_f32 color, vec2 vertices[3]);
-void fill_triangles_cached (vec4_f32 color, Box area, i64 num_triangles, vec2 *vertices);
+void fill_triangles_cached (vec4_f32 color, vec2 position, vec2 scale, i64 num_triangles, vec2 *vertices);
void fill_quad_cached (vec4_f32 color, vec2 vertices[4]);
void fill_ellipse_cached (vec4_f32 color, Box area);
void fill_line_cached (vec4_f32 color, vec2 vertices[2], f64 width);
@@ -233,7 +234,7 @@ void draw_text_cursor_cached(vec4_f32 color, Box area, vec2 max_size, i64 num_ch
void draw_pixels (Box area, Pixel_Buffer src);
void fill_rectangle (vec4_f32 color, Box area);
void fill_triangle (vec4_f32 color, vec2 vertices[3]);
-void fill_triangles (vec4_f32 color, Box area, i64 num_triangles, vec2 *vertices);
+void fill_triangles (vec4_f32 color, vec2 position, vec2 scale, i64 num_triangles, vec2 *vertices);
void fill_quad (vec4_f32 color, vec2 vertices[4]);
void fill_ellipse (vec4_f32 color, Box area);
void fill_line (vec4_f32 color, vec2 vertices[2], f64 width);
@@ -416,26 +417,26 @@ void fill_triangle_to_buffer(Pixel_Buffer dst, vec4_f32 color, vec2 vertices[3])
}
}
-static void triangles_area_(f64 *x0, f64 *y0, f64 *x1, f64 *y1, i64 num, vec2 *v) {
+static void triangles_area_(f64 *x0, f64 *y0, f64 *x1, f64 *y1, vec2 p, vec2 s, i64 num, vec2 *v) {
if (num <= 0)
return;
- *x0 = min3_(v[0].x, v[1].x, v[2].x);
- *y0 = min3_(v[0].y, v[1].y, v[2].y);
- *x1 = max3_(v[0].x, v[1].x, v[2].x);
- *y1 = max3_(v[0].y, v[1].y, v[2].y);
+ *x0 = min3_(p.x + v[0].x * s.x, p.x + v[1].x * s.x, p.x + v[2].x * s.x);
+ *y0 = min3_(p.y + v[0].y * s.y, p.y + v[1].y * s.y, p.y + v[2].y * s.y);
+ *x1 = max3_(p.x + v[0].x * s.x, p.x + v[1].x * s.x, p.x + v[2].x * s.x);
+ *y1 = max3_(p.y + v[0].y * s.y, p.y + v[1].y * s.y, p.y + v[2].y * s.y);
for (i64 i = 1; i < num; ++i) {
- *x0 = min4_(*x0, v[i * 3].x, v[i * 3 + 1].x, v[i * 3 + 2].x);
- *y0 = min4_(*y0, v[i * 3].y, v[i * 3 + 1].y, v[i * 3 + 2].y);
- *x1 = max4_(*x1, v[i * 3].x, v[i * 3 + 1].x, v[i * 3 + 2].x);
- *y1 = max4_(*y1, v[i * 3].y, v[i * 3 + 1].y, v[i * 3 + 2].y);
+ *x0 = min4_(*x0, p.x + v[i * 3].x * s.x, p.x + v[i * 3 + 1].x * s.x, p.x + v[i * 3 + 2].x * s.x);
+ *y0 = min4_(*y0, p.y + v[i * 3].y * s.y, p.y + v[i * 3 + 1].y * s.y, p.y + v[i * 3 + 2].y * s.y);
+ *x1 = max4_(*x1, p.x + v[i * 3].x * s.x, p.x + v[i * 3 + 1].x * s.x, p.x + v[i * 3 + 2].x * s.x);
+ *y1 = max4_(*y1, p.y + v[i * 3].y * s.y, p.y + v[i * 3 + 1].y * s.y, p.y + v[i * 3 + 2].y * s.y);
}
}
-void fill_triangles_to_buffer(Pixel_Buffer dst, vec4_f32 color, Box area, i64 num_triangles, vec2 *vertices) {
+void fill_triangles_to_buffer(Pixel_Buffer dst, vec4_f32 color, vec2 position, vec2 scale, i64 num_triangles, vec2 *vertices) {
f64 x0, y0, x1, y1;
- triangles_area_(&x0, &y0, &x1, &y1, num_triangles, vertices);
+ triangles_area_(&x0, &y0, &x1, &y1, position, scale, num_triangles, vertices);
i64 i0 = (i64) x0;
i64 j0 = (i64) y0;
@@ -1285,14 +1286,15 @@ void fill_triangle_cached(vec4_f32 color, vec2 vertices[3]) {
);
}
-void fill_triangles_cached(vec4_f32 color, Box area, i64 num_triangles, vec2 *vertices) {
+void fill_triangles_cached(vec4_f32 color, vec2 position, vec2 scale, i64 num_triangles, vec2 *vertices) {
perform_graphics_request(
(Graphics_Context) {0},
(Graphics_Request) {
.op = GRAPHICS_FILL_TRIANGLES,
.triangles = {
.color = color,
- .area = area,
+ .position = position,
+ .scale = scale,
.num_triangles = num_triangles,
.vertices = vertices,
},
@@ -1422,14 +1424,15 @@ void fill_triangle(vec4_f32 color, vec2 vertices[3]) {
);
}
-void fill_triangles(vec4_f32 color, Box area, i64 num_triangles, vec2 *vertices) {
+void fill_triangles(vec4_f32 color, vec2 position, vec2 scale, i64 num_triangles, vec2 *vertices) {
perform_graphics_request(
(Graphics_Context) { .disable_cache = 1, },
(Graphics_Request) {
.op = GRAPHICS_FILL_TRIANGLES,
.triangles = {
.color = color,
- .area = area,
+ .position = position,
+ .scale = scale,
.num_triangles = num_triangles,
.vertices = vertices,
},
@@ -1549,7 +1552,8 @@ static void graphics_request_hash_(Blake2b_State *S, Graphics_Request req) {
switch (req.op) {
case GRAPHICS_FILL_TRIANGLES:
blake2b_update(S, (u8 *) &req.triangles.color, sizeof req.triangles.color);
- blake2b_update(S, (u8 *) &req.triangles.area, sizeof req.triangles.area);
+ blake2b_update(S, (u8 *) &req.triangles.position, sizeof req.triangles.position);
+ blake2b_update(S, (u8 *) &req.triangles.scale, sizeof req.triangles.scale);
blake2b_update(S, (u8 *) &req.triangles.num_triangles, sizeof req.triangles.num_triangles);
blake2b_update(S, (u8 *) req.triangles.vertices, req.triangles.num_triangles * 3 * sizeof *req.triangles.vertices);
break;
@@ -1635,10 +1639,10 @@ static Graphics_Request graphics_request_scaled_(Graphics_Request req, vec2 scal
break;
case GRAPHICS_FILL_TRIANGLES:
- scaled.triangles.area.x *= scale.x;
- scaled.triangles.area.y *= scale.y;
- scaled.triangles.area.width *= scale.x;
- scaled.triangles.area.height *= scale.y;
+ scaled.triangles.position.x *= scale.x;
+ scaled.triangles.position.y *= scale.y;
+ scaled.triangles.scale.x *= scale.x;
+ scaled.triangles.scale.y *= scale.y;
break;
case GRAPHICS_FILL_QUAD:
@@ -1730,8 +1734,8 @@ static Graphics_Request graphics_request_moved_(Graphics_Request req, vec2 offse
break;
case GRAPHICS_FILL_TRIANGLES:
- moved.triangles.area.x += offset.x;
- moved.triangles.area.y += offset.y;
+ moved.triangles.position.x += offset.x;
+ moved.triangles.position.y += offset.y;
break;
case GRAPHICS_FILL_QUAD:
@@ -1794,7 +1798,7 @@ static Box graphics_request_area_(Graphics_Request req) {
case GRAPHICS_FILL_TRIANGLES:
if (req.triangles.num_triangles > 0) {
f64 x0, y0, x1, y1;
- triangles_area_(&x0, &y0, &x1, &y1, req.triangles.num_triangles, req.triangles.vertices);
+ triangles_area_(&x0, &y0, &x1, &y1, req.triangles.position, req.triangles.scale, req.triangles.num_triangles, req.triangles.vertices);
area.x = x0;
area.y = y0;
@@ -1874,7 +1878,8 @@ static void perform_graphics_request_to_buffer_(Pixel_Buffer dst, Graphics_Reque
fill_triangles_to_buffer(
dst,
req.triangles.color,
- req.triangles.area,
+ req.triangles.position,
+ req.triangles.scale,
req.triangles.num_triangles,
req.triangles.vertices
);
diff --git a/reduced_system_layer.c b/reduced_system_layer.c
index e8fa43f..eee1093 100755
--- a/reduced_system_layer.c
+++ b/reduced_system_layer.c
@@ -99,7 +99,6 @@
#/ - Device selection
#/ - Networking
#/ - Windows sockets
-#/ - TCP
#/ - fetch - via libcurl on native platforms
#/ - Lattice-based cipher suite
#/ - dlopen - load libraries conditionally
@@ -619,17 +618,19 @@ typedef struct {
i32 frame_height;
f64 pixel_size;
i32 antialiasing_scale;
- b8 exact_resolution : 1;
- b8 graceful_shutdown : 1;
- b8 enable_clipboard_text : 1;
- b8 enable_clipboard_image : 1;
- b8 enable_clipboard_sound : 1;
-
- b8 done : 1;
- b8 has_focus : 1;
- b8 has_cursor : 1;
- b8 files_dragged : 1;
- b8 files_dropped : 1;
+
+ b8 exact_resolution : 1;
+ b8 graceful_shutdown : 1;
+ b8 enable_clipboard_text : 1;
+ b8 enable_clipboard_image : 1;
+ b8 enable_clipboard_sound : 1;
+
+ b8 done : 1;
+ b8 has_focus : 1;
+ b8 has_cursor : 1;
+ b8 files_dragged : 1;
+ b8 files_dropped : 1;
+
i32 real_width;
i32 real_height;
i32 cursor_x;
@@ -736,10 +737,10 @@ extern Platform g_platform;
Platform g_platform = {0};
-static i64 _sound_clock_time = 0;
-static i64 _sound_clock_carry = 0;
-static i64 _sound_position = 0;
-static i64 _frame_index = 0;
+static i64 _sound_clock_time = 0;
+static i64 _sound_clock_carry = 0;
+static i64 _sound_position = 0;
+static i64 _frame_index = 0;
static f32 _sound_ring [MAX_NUM_PRIMARY_SOUND_FRAMES] = {0};
static i64 _frame_duration [NUM_FRAMES_AVERAGED] = {0};