optimize case of sequential shared radius circle drawing by reusing the geometry by just offsetting it
This commit is contained in:
parent
e4da4a8b7f
commit
26c75ffd7c
@ -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 });
|
||||
}
|
||||
|
||||
|
||||
|
@ -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};
|
||||
|
||||
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);
|
||||
|
Loading…
Reference in New Issue
Block a user