summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Pavone <pavone@retrodev.com>2016-05-01 14:59:40 -0700
committerMichael Pavone <pavone@retrodev.com>2016-05-01 14:59:40 -0700
commitd2cf54c6a06190f374ede3fc3a378ed8b72051dd (patch)
treea6d7ba8cd371b66676f33592c0709d305a192b98
parent67f8fafd20b36f955d50e95a3145676442e210ae (diff)
Set vsync state based on config file rather than just using whatever the system decides for us.
-rw-r--r--default.cfg3
-rwxr-xr-xrender_sdl.c30
2 files changed, 26 insertions, 7 deletions
diff --git a/default.cfg b/default.cfg
index b6e26cc..6dba026 100644
--- a/default.cfg
+++ b/default.cfg
@@ -108,7 +108,8 @@ video {
width 640
vertex_shader default.v.glsl
fragment_shader default.f.glsl
- scanlines false
+ scanlines off
+ vsync off
}
audio {
diff --git a/render_sdl.c b/render_sdl.c
index d2ce7e7..12369dc 100755
--- a/render_sdl.c
+++ b/render_sdl.c
@@ -268,6 +268,8 @@ void render_init(int width, int height, char * title, uint32_t fps, uint8_t full
is_fullscreen = fullscreen;
render_gl = 0;
+ tern_val def = {.ptrval = "off"};
+ char *vsync = tern_find_path_default(config, "video\0vsync\0", def).ptrval;
#ifndef DISABLE_OPENGL
flags |= SDL_WINDOW_OPENGL;
@@ -288,11 +290,27 @@ void render_init(int width, int height, char * title, uint32_t fps, uint8_t full
if (res == GLEW_OK && GLEW_VERSION_2_0) {
render_gl = 1;
+ if (!strcmp("tear", vsync)) {
+ if (SDL_GL_SetSwapInterval(-1) < 0) {
+ warning("late tear is not available (%s), using normal vsync\n", SDL_GetError());
+ vsync = "on";
+ } else {
+ vsync = NULL;
+ }
+ }
+ if (vsync) {
+ if (SDL_GL_SetSwapInterval(!strcmp("on", vsync)) < 0) {
+ warning("Failed to set vsync to %s: %s\n", vsync, SDL_GetError());
+ }
+ }
} else {
- SDL_DestroyWindow(main_window);
- warning("OpenGL 2.0 is unavailable, falling back to SDL2 renderer\n", stderr);
+ warning("OpenGL 2.0 is unavailable, falling back to SDL2 renderer\n");
#endif
- SDL_CreateWindowAndRenderer(width, height, flags, &main_window, &main_renderer);
+ flags = SDL_RENDERER_ACCELERATED;
+ if (!strcmp("on", vsync) || !strcmp("tear", vsync)) {
+ flags |= SDL_RENDERER_PRESENTVSYNC;
+ }
+ main_renderer = SDL_CreateRenderer(main_window, -1, flags);
if (!main_window || !main_renderer) {
fatal_error("unable to create SDL window: %s\n", SDL_GetError());
@@ -308,7 +326,7 @@ void render_init(int width, int height, char * title, uint32_t fps, uint8_t full
printf("Window created with size: %d x %d\n", width, height);
float src_aspect = 4.0/3.0;
float aspect = (float)width / height;
- tern_val def = {.ptrval = "normal"};
+ def.ptrval = "normal";
int stretch = fabs(aspect - src_aspect) > 0.01 && !strcmp(tern_find_path_default(config, "video\0aspect\0", def).ptrval, "stretch");
if (!stretch) {
@@ -335,8 +353,8 @@ void render_init(int width, int height, char * title, uint32_t fps, uint8_t full
}
#endif
}
- def.ptrval = "false";
- scanlines = !strcmp(tern_find_path_default(config, "video\0scanlines\0", def).ptrval, "true");
+ def.ptrval = "off";
+ scanlines = !strcmp(tern_find_path_default(config, "video\0scanlines\0", def).ptrval, "on");
caption = title;
min_delay = 0;