Allow display wrapping to be specified per shape

This commit is contained in:
Camden Dixie O'Brien
2025-10-13 22:11:30 +01:00
parent bbb13108e0
commit 794a149f00
3 changed files with 39 additions and 22 deletions

View File

@@ -28,11 +28,11 @@ static void page_flip_handler(int, unsigned, unsigned, unsigned, void *)
static void set_pixel(uint32_t x, uint32_t y)
{
const uint32_t offset = y * (fbs[back].pitch / 4) + x;
const uint32_t offset = y * (fbs[back].pitch / 4) + x;
fbs[back].buf[offset] = 0xff'ff'ff;
}
static void draw_line(vec3_t v1, vec3_t v2)
static void draw_line(vec3_t v1, vec3_t v2, uint8_t flags)
{
const float delta_x = v2.x - v1.x;
const float delta_y = v2.y - v1.y;
@@ -43,16 +43,20 @@ static void draw_line(vec3_t v1, vec3_t v2)
for (unsigned i = 0; i <= step; ++i) {
float x = roundf(v1.x + i * step_x);
if (x >= width)
x -= width;
else if (x < 0)
x += width;
float y = roundf(v1.y + i * step_y);
if (y >= height)
y -= height;
else if (y < 0)
y += height;
if (flags & WRAP) {
if (x >= width)
x -= width;
else if (x < 0)
x += width;
if (y >= height)
y -= height;
else if (y < 0)
y += height;
} else if (x >= width || x < 0 || y >= height || y < 0) {
continue;
}
set_pixel(x, y);
}
@@ -141,13 +145,17 @@ void renderer_swap()
back = (back + 1) & 1;
}
void renderer_draw(const vec2_t *vs, unsigned count, mat3_t model)
void renderer_draw(
const vec2_t *vs, unsigned count, mat3_t model, uint8_t flags)
{
mat3_t transform = mat3_mul_mat3(view, model);
assert(count < MAX_VERTS);
for (unsigned i = 0; i < count; ++i)
vert_buf[i] = mat3_mul_vec3(transform, vec2_extend(vs[i]));
for (unsigned i = 1; i < count; ++i)
draw_line(vert_buf[i - 1], vert_buf[i]);
draw_line(vert_buf[count - 1], vert_buf[0]);
draw_line(vert_buf[i - 1], vert_buf[i], flags);
if (flags & CONNECT)
draw_line(vert_buf[count - 1], vert_buf[0], flags);
}