aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/graphics/vertex_buffer.c10
-rw-r--r--src/system/clock.c27
2 files changed, 32 insertions, 5 deletions
diff --git a/src/graphics/vertex_buffer.c b/src/graphics/vertex_buffer.c
index ccdcd84..5a8e768 100644
--- a/src/graphics/vertex_buffer.c
+++ b/src/graphics/vertex_buffer.c
@@ -78,17 +78,17 @@ int mgl_vertex_buffer_update(mgl_vertex_buffer *self, const mgl_vertex *vertices
}
/* TODO: Optimize bind texture */
-void mgl_vertex_buffer_draw(mgl_context *context, mgl_vertex_buffer *self, const mgl_texture *texture) {
- if(self->vertex_count == 0 || self->id == 0)
+void mgl_vertex_buffer_draw(mgl_context *context, mgl_vertex_buffer *vertex_buffer, const mgl_texture *texture) {
+ if(vertex_buffer->vertex_count == 0 || vertex_buffer->id == 0)
return;
/* TODO: Optimize this */
context->gl.glPushMatrix();
- context->gl.glTranslatef(self->position.x, self->position.y, 0.0f);
+ context->gl.glTranslatef(vertex_buffer->position.x, vertex_buffer->position.y, 0.0f);
context->gl.glBindTexture(GL_TEXTURE_2D, texture ? texture->id : 0);
- context->gl.glBindBuffer(GL_ARRAY_BUFFER, self->id);
- context->gl.glDrawArrays(mgl_primitive_type_to_gl_mode(self->primitive_type), 0, self->vertex_count);
+ context->gl.glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer->id);
+ context->gl.glDrawArrays(mgl_primitive_type_to_gl_mode(vertex_buffer->primitive_type), 0, vertex_buffer->vertex_count);
context->gl.glBindBuffer(GL_ARRAY_BUFFER, 0);
context->gl.glBindTexture(GL_TEXTURE_2D, 0);
diff --git a/src/system/clock.c b/src/system/clock.c
new file mode 100644
index 0000000..3ec2276
--- /dev/null
+++ b/src/system/clock.c
@@ -0,0 +1,27 @@
+#include "../../include/mgl/system/clock.h"
+#include <time.h>
+
+/* TODO: Implement for macOS */
+
+static double clock_get_monotonic_seconds() {
+ struct timespec ts;
+ ts.tv_sec = 0;
+ ts.tv_nsec = 0;
+ clock_gettime(CLOCK_MONOTONIC, &ts);
+ return (double)ts.tv_sec + (double)ts.tv_nsec * 0.000000001;
+}
+
+void mgl_clock_init(mgl_clock *self) {
+ self->captured_seconds = clock_get_monotonic_seconds();
+}
+
+double mgl_clock_restart(mgl_clock *self) {
+ const double new_time_seconds = clock_get_monotonic_seconds();
+ const double elapsed_time_seconds = self->captured_seconds - new_time_seconds;
+ self->captured_seconds = new_time_seconds;
+ return elapsed_time_seconds;
+}
+
+double mgl_clock_get_elapsed_time_seconds(mgl_clock *self) {
+ return clock_get_monotonic_seconds() - self->captured_seconds;
+}