aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2023-08-25 11:03:02 +0200
committerdec05eba <dec05eba@protonmail.com>2023-08-25 11:03:02 +0200
commit5e50a5249f089f44b568e7dd4ba0782521e67e0b (patch)
tree90ccbe16b5df0d72d14a3fc82d9eb3940d0eaf39
parenta6c350cd014fc57cefc4beb6698ac80781ca028c (diff)
Dont enable low latency mode by default since it increases cpu usage
-rw-r--r--include/mgl/window/window.h6
-rw-r--r--src/window/window.c15
2 files changed, 18 insertions, 3 deletions
diff --git a/include/mgl/window/window.h b/include/mgl/window/window.h
index 35b677d..cbcdb1a 100644
--- a/include/mgl/window/window.h
+++ b/include/mgl/window/window.h
@@ -48,12 +48,13 @@ struct mgl_window {
bool open;
bool focused;
bool key_repeat_enabled;
- bool vsync_enabled;
+ bool vsync_enabled; /* true by default */
double frame_time_limit;
double frame_time_limit_monitor;
mgl_clock frame_timer;
char *clipboard_string;
size_t clipboard_size;
+ bool low_latency; /* false by default */
mgl_monitor *monitors; /* TODO: Move these to mgl file */
int num_monitors;
@@ -132,6 +133,9 @@ void mgl_window_set_vsync_enabled(mgl_window *self, bool enabled);
bool mgl_window_is_vsync_enabled(const mgl_window *self);
void mgl_window_set_fullscreen(mgl_window *self, bool fullscreen);
bool mgl_window_is_fullscreen(const mgl_window *self);
+/* Enabling low latency may slightly increase cpu usage */
+void mgl_window_set_low_latency(mgl_window *self, bool low_latency);
+bool mgl_window_is_low_latency_enabled(const mgl_window *self);
void mgl_window_set_position(mgl_window *self, mgl_vec2i position);
void mgl_window_set_size(mgl_window *self, mgl_vec2i size);
diff --git a/src/window/window.c b/src/window/window.c
index d0c9cc0..00bcf57 100644
--- a/src/window/window.c
+++ b/src/window/window.c
@@ -487,6 +487,7 @@ static int mgl_window_init(mgl_window *self, const char *title, const mgl_window
self->monitors = NULL;
self->num_monitors = 0;
self->pos = (mgl_vec2i){ 0, 0 };
+ self->low_latency = false;
mgl_vec2i window_size = params ? params->size : (mgl_vec2i){ 0, 0 };
if(window_size.x <= 0 || window_size.y <= 0) {
@@ -1190,8 +1191,10 @@ bool mgl_window_poll_event(mgl_window *self, mgl_event *event) {
void mgl_window_display(mgl_window *self) {
mgl_context *context = mgl_get_context();
context->gl.glXSwapBuffers(context->connection, self->window);
- context->gl.glFlush();
- context->gl.glFinish();
+ if(self->low_latency) {
+ context->gl.glFlush();
+ context->gl.glFinish();
+ }
if(self->frame_time_limit > 0.000001) {
double time_left_to_sleep = self->frame_time_limit - mgl_clock_get_elapsed_time_seconds(&self->frame_timer);
@@ -1368,6 +1371,14 @@ bool mgl_window_is_fullscreen(const mgl_window *self) {
return is_fullscreen;
}
+void mgl_window_set_low_latency(mgl_window *self, bool low_latency) {
+ self->low_latency = low_latency;
+}
+
+bool mgl_window_is_low_latency_enabled(const mgl_window *self) {
+ return self->low_latency;
+}
+
void mgl_window_set_position(mgl_window *self, mgl_vec2i position) {
XMoveWindow(mgl_get_context()->connection, self->window, position.x, position.y);
}