use static, fixed arrays for circle geometry data instead of allocating for each one
This commit is contained in:
@ -58,6 +58,9 @@ typedef enum {
|
||||
static Pipeline pipeline_last_used = PIPELINE_NO;
|
||||
|
||||
|
||||
#define CIRCLE_VERTICES_MAX 2048
|
||||
|
||||
|
||||
void use_space_pipeline(void) {
|
||||
if (pipeline_last_used == PIPELINE_SPACE)
|
||||
return;
|
||||
@ -164,16 +167,16 @@ void render_rectangle(const RectPrimitive *rectangle) {
|
||||
|
||||
|
||||
void render_circle(const CirclePrimitive *circle) {
|
||||
SDL_Vertex *vertices = NULL;
|
||||
int *indices = NULL;
|
||||
int num_vertices = (int)circle->radius;
|
||||
static SDL_Vertex vertices[CIRCLE_VERTICES_MAX];
|
||||
static int indices[CIRCLE_VERTICES_MAX * 3];
|
||||
int num_vertices = MIN((int)circle->radius, CIRCLE_VERTICES_MAX-1);
|
||||
|
||||
create_circle_geometry(circle->position,
|
||||
circle->color,
|
||||
circle->radius,
|
||||
num_vertices,
|
||||
&vertices,
|
||||
&indices);
|
||||
vertices,
|
||||
indices);
|
||||
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glVertexPointer(2,
|
||||
@ -194,9 +197,6 @@ void render_circle(const CirclePrimitive *circle) {
|
||||
|
||||
glDisableClientState(GL_COLOR_ARRAY);
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
|
||||
SDL_free(vertices);
|
||||
SDL_free(indices);
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user