changeset 1328:70faad89d491

Add config file option to disable Open GL rendering
author Michael Pavone <pavone@retrodev.com>
date Sun, 23 Apr 2017 00:54:33 -0700
parents 57637d17b59e
children 85a90964b557
files default.cfg render_sdl.c
diffstat 2 files changed, 40 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/default.cfg	Sat Apr 22 01:22:47 2017 -0700
+++ b/default.cfg	Sun Apr 23 00:54:33 2017 -0700
@@ -138,6 +138,10 @@
 	scanlines off
 	vsync off
 	fullscreen off
+	#setting gl to off, will force use of the SDL2 fallback renderer
+	#this is useful for those running on machines with Open GL 2.0 unavailable
+	#so the warning doesn't display on startup
+	gl on
 	ntsc {
 		overscan {
 			#these values will result in square pixels in H40 mode
--- a/render_sdl.c	Sat Apr 22 01:22:47 2017 -0700
+++ b/render_sdl.c	Sun Apr 23 00:54:33 2017 -0700
@@ -386,41 +386,51 @@
 	}
 
 #ifndef DISABLE_OPENGL
-	flags |= SDL_WINDOW_OPENGL;
-	SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
-	SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
-	SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
-	SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 0);
-	SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
+	char *gl_enabled_str = tern_find_path_default(config, "video\0gl\0", def, TVAL_PTR).ptrval;
+	uint8_t gl_enabled = strcmp(gl_enabled_str, "off") != 0;
+	if (gl_enabled)
+	{
+		flags |= SDL_WINDOW_OPENGL;
+		SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
+		SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
+		SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
+		SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 0);
+		SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
+	}
 #endif
 	main_window = SDL_CreateWindow(title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, flags);
 	if (!main_window) {
 		fatal_error("Unable to create SDL window: %s\n", SDL_GetError());
 	}
 #ifndef DISABLE_OPENGL
-	main_context = SDL_GL_CreateContext(main_window);
-	GLenum res = glewInit();
-	if (res != GLEW_OK) {
-		warning("Initialization of GLEW failed with code %d\n", res);
-	}
+	if (gl_enabled)
+	{
+		main_context = SDL_GL_CreateContext(main_window);
+		GLenum res = glewInit();
+		if (res != GLEW_OK) {
+			warning("Initialization of GLEW failed with code %d\n", res);
+		}
 
-	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 (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 {
+			warning("OpenGL 2.0 is unavailable, falling back to SDL2 renderer\n");
 		}
-		if (vsync) {
-			if (SDL_GL_SetSwapInterval(!strcmp("on", vsync)) < 0) {
-				warning("Failed to set vsync to %s: %s\n", vsync, SDL_GetError());
-			}
-		}
-	} else {
-		warning("OpenGL 2.0 is unavailable, falling back to SDL2 renderer\n");
+	}
+	if (!render_gl) {
 #endif
 		flags = SDL_RENDERER_ACCELERATED;
 		if (!strcmp("on", vsync) || !strcmp("tear", vsync)) {