From 3111638233efa4da1ccaeca32a7a8df69c193e4d Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Sun, 25 Oct 2020 22:40:11 -0500 Subject: [PATCH] small refactor --- include/container.h | 4 ++++ src/sim.cpp | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/include/container.h b/include/container.h index 18bd5b3..3ff34cc 100644 --- a/include/container.h +++ b/include/container.h @@ -124,6 +124,10 @@ struct Array return false; } + u64 size_in_bytes() const + { + return sizeof(T) * count; + } T* begin() const { diff --git a/src/sim.cpp b/src/sim.cpp index 57ea297..a58bb09 100644 --- a/src/sim.cpp +++ b/src/sim.cpp @@ -244,7 +244,7 @@ draw(SimState* state) { // NOTE(Brendan): Rebuffer all the body data to the GPU. glBindBuffer(GL_ARRAY_BUFFER, body_buffer); - glBufferSubData(GL_ARRAY_BUFFER, 0, state->bodies.count * sizeof(Body), state->bodies.data); + glBufferSubData(GL_ARRAY_BUFFER, 0, state->bodies.size_in_bytes(), state->bodies.data); glBindBuffer(GL_ARRAY_BUFFER, -1); glUseProgram(body_program); @@ -324,7 +324,7 @@ main(i32 argc, char* argv[]) glGenBuffers(1, &body_buffer); glBindBuffer(GL_ARRAY_BUFFER, body_buffer); - glBufferData(GL_ARRAY_BUFFER, sizeof(Body) * state->bodies.count, state->bodies.data, GL_STREAM_DRAW); + glBufferData(GL_ARRAY_BUFFER, state->bodies.size_in_bytes(), state->bodies.data, GL_STREAM_DRAW); foreach (i, 1, 4) { -- 2.25.1