diff --git a/apps/demos/platformer/player.c b/apps/demos/platformer/player.c index ec94dd9..93f95c0 100644 --- a/apps/demos/platformer/player.c +++ b/apps/demos/platformer/player.c @@ -255,6 +255,10 @@ static void drawdef(Player *player) { draw_circle((Vec2) { 256, 128 }, 24, (Color) { 255, 0, 0, 255 }); + + draw_circle((Vec2) { 304, 128 }, + 24, + (Color) { 255, 0, 0, 255 }); } diff --git a/src/rendering/twn_gl_15_rendering.c b/src/rendering/twn_gl_15_rendering.c index 13180e0..00b0fa7 100644 --- a/src/rendering/twn_gl_15_rendering.c +++ b/src/rendering/twn_gl_15_rendering.c @@ -911,12 +911,26 @@ static void load_cubemap_side(const char *path, GLenum target) { void render_circle(const CirclePrimitive *circle) { static Vec2 vertices[CIRCLE_VERTICES_MAX]; - int num_vertices = MIN((int)circle->radius, CIRCLE_VERTICES_MAX); + static int prev_num_vertices = 0; + static Vec2 prev_position = {0}; - create_circle_geometry(circle->position, - circle->radius, - num_vertices, - vertices); + int const num_vertices = MIN((int)circle->radius, CIRCLE_VERTICES_MAX); + + if (prev_num_vertices != num_vertices) { + create_circle_geometry(circle->position, + circle->radius, + num_vertices, + vertices); + prev_num_vertices = num_vertices; + prev_position = circle->position; + } else { + /* reuse the data, but offset it by difference with previously generated position */ + /* no evil cos sin ops this way, if radius is shared in sequential calls */ + Vec2 const d = { prev_position.x - circle->position.x, prev_position.y - circle->position.y }; + for (int i = 0; i < num_vertices; ++i) + vertices[i] = (Vec2){ vertices[i].x - d.x, vertices[i].y - d.y }; + prev_position = circle->position; + } VertexBuffer buffer = get_scratch_vertex_array(); specify_vertex_buffer(buffer, vertices, sizeof (Vec2) * num_vertices);