changeset 1403:87493f585c7f

Allow selecting linear or nearet neighbor scaling for both the Open GL and SDL 2 renderers
author Michael Pavone <pavone@retrodev.com>
date Thu, 15 Jun 2017 22:51:28 -0700
parents 458df351af06
children f9fbd0d16df2
files default.cfg render_sdl.c
diffstat 2 files changed, 11 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/default.cfg	Thu Jun 15 19:24:16 2017 -0700
+++ b/default.cfg	Thu Jun 15 22:51:28 2017 -0700
@@ -146,6 +146,8 @@
 	#this is useful for those running on machines with Open GL 2.0 unavailable
 	#so the warning doesn't display on startup
 	gl on
+	#scaling can be linear (for linear interpolation) or nearest (for nearest neighbor)
+	scaling linear
 	ntsc {
 		overscan {
 			#these values will result in square pixels in H40 mode
--- a/render_sdl.c	Thu Jun 15 19:24:16 2017 -0700
+++ b/render_sdl.c	Thu Jun 15 22:51:28 2017 -0700
@@ -195,12 +195,15 @@
 #ifndef DISABLE_OPENGL
 static void gl_setup()
 {
+	tern_val def = {.ptrval = "linear"};
+	char *scaling = tern_find_path_default(config, "video\0scaling\0", def, TVAL_PTR).ptrval;
+	GLint filter = strcmp(scaling, "linear") ? GL_NEAREST : GL_LINEAR;
 	glGenTextures(3, textures);
 	for (int i = 0; i < 3; i++)
 	{
 		glBindTexture(GL_TEXTURE_2D, textures[i]);
-		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
-		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter);
+		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter);
 		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
 		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
 		if (i < 2) {
@@ -216,7 +219,7 @@
 	glBufferData(GL_ARRAY_BUFFER, sizeof(vertex_data), vertex_data, GL_STATIC_DRAW);
 	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffers[1]);
 	glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(element_data), element_data, GL_STATIC_DRAW);
-	tern_val def = {.ptrval = "default.v.glsl"};
+	def.ptrval = "default.v.glsl";
 	vshader = load_shader(tern_find_path_default(config, "video\0vertex_shader\0", def, TVAL_PTR).ptrval, GL_VERTEX_SHADER);
 	def.ptrval = "default.f.glsl";
 	fshader = load_shader(tern_find_path_default(config, "video\0fragment_shader\0", def, TVAL_PTR).ptrval, GL_FRAGMENT_SHADER);
@@ -254,7 +257,9 @@
 		gl_setup();
 	} else {
 #endif
-		
+		tern_val def = {.ptrval = "linear"};
+		char *scaling = tern_find_path_default(config, "video\0scaling\0", def, TVAL_PTR).ptrval;
+		SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, scaling);
 		//TODO: Fixme for invalid display mode
 		sdl_textures[0] = sdl_textures[1] = SDL_CreateTexture(main_renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, LINEBUF_SIZE, 588);
 #ifndef DISABLE_OPENGL