Skip to content

Commit

Permalink
Print vertex buffer size to stdout
Browse files Browse the repository at this point in the history
 - The vertex buffer is FAR larger than the L-system itself, so I
   figured it may be useful status information, to keep an eye on prior
   to iterating the L-system again.
  • Loading branch information
Nathan O authored and Nathan O committed Feb 17, 2022
1 parent 3e646d8 commit 5006321
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions l_system_3d.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,13 @@ static void ReloadConfig(ApplicationState *s) {
printf("Config updated OK.\n");
}

static void PrintMemoryUsage(ApplicationState *s) {
float vbo_size_mb = ToMB(sizeof(MeshVertex) * s->mesh->vertex_count);
printf("L-system size is now %.02f MB.\n", ToMB(s->l_system_length));
printf("Drawing %u vertices, taking %.02f MB.\n",
(unsigned) s->mesh->vertex_count, vbo_size_mb);
}

static int ProcessInputs(ApplicationState *s) {
int pressed;
if (glfwGetKey(s->window, GLFW_KEY_ESCAPE) == GLFW_PRESS) {
Expand All @@ -229,7 +236,7 @@ static int ProcessInputs(ApplicationState *s) {
// Nothing pressed -> up pressed
s->key_pressed_tmp = GLFW_KEY_UP;
if (!(IncreaseIterations(s) && GenerateVertices(s))) return 0;
printf("New L-system length: %.02f MB.\n", ToMB(s->l_system_length));
PrintMemoryUsage(s);
} else if ((s->key_pressed_tmp == GLFW_KEY_UP) && !pressed) {
// Up pressed -> up released
s->key_pressed_tmp = 0;
Expand All @@ -239,7 +246,7 @@ static int ProcessInputs(ApplicationState *s) {
// Nothing pressed -> down pressed
s->key_pressed_tmp = GLFW_KEY_DOWN;
if (!(DecreaseIterations(s) && GenerateVertices(s))) return 0;
printf("New L-system length: %.02f MB.\n", ToMB(s->l_system_length));
PrintMemoryUsage(s);
} else if ((s->key_pressed_tmp == GLFW_KEY_DOWN) && !pressed) {
// Down pressed -> down released
s->key_pressed_tmp = 0;
Expand Down

0 comments on commit 5006321

Please sign in to comment.