From: Brendan Hansen Date: Mon, 26 Oct 2020 03:40:11 +0000 (-0500) Subject: small refactor X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=3111638233efa4da1ccaeca32a7a8df69c193e4d;p=csc718.git small refactor --- 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) {