Shader enabling, and automatic resolution detection.

This commit is contained in:
Themaister 2011-02-28 16:59:31 +01:00
parent de9dc686ac
commit 7c16424ba3
6 changed files with 91 additions and 15 deletions

View File

@ -94,8 +94,8 @@ static const float yscale = 3.0; // Real y res = 224 * yscale
// Fullscreen
static const bool fullscreen = false; // To start in Fullscreen or not
static const unsigned fullscreen_x = 1280;
static const unsigned fullscreen_y = 720;
static const unsigned fullscreen_x = 0; // Fullscreen resolution. A value of 0 uses the desktop resolution.
static const unsigned fullscreen_y = 0;
// Video VSYNC (recommended)
static const bool vsync = true;

View File

@ -41,6 +41,7 @@ enum
SSNES_PAUSE_TOGGLE,
};
struct snes_keybind
{
int id;

View File

@ -44,6 +44,14 @@
#define MAX_BINDS 25 // Needs to be increased every time there are new binds added.
#define SSNES_NO_JOYPAD 0xFFFF
enum ssnes_shader_type
{
SSNES_SHADER_CG,
SSNES_SHADER_BSNES,
SSNES_SHADER_AUTO,
SSNES_SHADER_NONE
};
// All config related settings go here.
struct settings
{
@ -62,6 +70,7 @@ struct settings
char cg_shader_path[256];
char bsnes_shader_path[256];
unsigned filter;
enum ssnes_shader_type shader_type;
char font_path[256];
unsigned font_size;
@ -111,6 +120,7 @@ enum ssnes_game_type
SSNES_CART_SUFAMI,
};
// All run-time- / command line flag-related globals go here.
struct global
{

View File

@ -82,6 +82,8 @@ typedef struct gl
bool quitting;
bool keep_aspect;
unsigned full_x, full_y;
unsigned win_width;
unsigned win_height;
unsigned vp_width;
@ -99,20 +101,46 @@ typedef struct gl
} gl_t;
////////////////// Shaders
static inline bool gl_shader_init(void)
static bool gl_shader_init(void)
{
if (strlen(g_settings.video.cg_shader_path) > 0 && strlen(g_settings.video.bsnes_shader_path) > 0)
SSNES_WARN("Both Cg and bSNES XML shader are defined in config file. Cg shader will be selected by default.\n");
switch (g_settings.video.shader_type)
{
case SSNES_SHADER_AUTO:
{
if (strlen(g_settings.video.cg_shader_path) > 0 && strlen(g_settings.video.bsnes_shader_path) > 0)
SSNES_WARN("Both Cg and bSNES XML shader are defined in config file. Cg shader will be selected by default.\n");
#ifdef HAVE_CG
if (strlen(g_settings.video.cg_shader_path) > 0)
return gl_cg_init(g_settings.video.cg_shader_path);
if (strlen(g_settings.video.cg_shader_path) > 0)
return gl_cg_init(g_settings.video.cg_shader_path);
#endif
#ifdef HAVE_XML
if (strlen(g_settings.video.bsnes_shader_path) > 0)
return gl_glsl_init(g_settings.video.bsnes_shader_path);
if (strlen(g_settings.video.bsnes_shader_path) > 0)
return gl_glsl_init(g_settings.video.bsnes_shader_path);
#endif
break;
}
#ifdef HAVE_CG
case SSNES_SHADER_CG:
{
return gl_cg_init(g_settings.video.cg_shader_path);
break;
}
#endif
#ifdef HAVE_XML
case SSNES_SHADER_BSNES:
{
return gl_glsl_init(g_settings.video.bsnes_shader_path);
break;
}
#endif
default:
break;
}
return true;
}
@ -445,6 +473,10 @@ static void* gl_init(video_info_t *video, const input_driver_t **input, void **i
if (SDL_Init(SDL_INIT_VIDEO) < 0)
return NULL;
const SDL_VideoInfo *video_info = SDL_GetVideoInfo();
unsigned full_x = video_info->current_w;
unsigned full_y = video_info->current_h;
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, video->vsync ? 1 : 0);
@ -465,8 +497,20 @@ static void* gl_init(video_info_t *video, const input_driver_t **input, void **i
if (!gl)
return NULL;
gl->win_width = video->width;
gl->win_height = video->height;
gl->full_x = full_x;
gl->full_y = full_y;
if (video->fullscreen)
{
gl->win_width = video->width ? video->width : gl->full_x;
gl->win_height = video->height ? video->height : gl->full_y;
}
else
{
gl->win_width = video->width;
gl->win_height = video->height;
}
gl->vsync = video->vsync;
gl->keep_aspect = video->force_aspect;
set_viewport(gl);

View File

@ -107,6 +107,7 @@ static void set_defaults(void)
#ifdef HAVE_FILTER
g_settings.video.filter = FILTER_NONE;
#endif
g_settings.video.shader_type = SSNES_SHADER_AUTO;
#ifdef HAVE_FREETYPE
g_settings.video.font_size = font_size;
@ -320,6 +321,22 @@ static void parse_config_file(void)
}
#endif
#if defined(HAVE_CG) || defined(HAVE_XML)
if (config_get_string(conf, "video_shader_type", &tmp_str))
{
if (strcmp("cg", tmp_str) == 0)
g_settings.video.shader_type = SSNES_SHADER_CG;
else if (strcmp("bsnes", tmp_str) == 0)
g_settings.video.shader_type = SSNES_SHADER_BSNES;
else if (strcmp("auto", tmp_str) == 0)
g_settings.video.shader_type = SSNES_SHADER_AUTO;
else if (strcmp("none", tmp_str) == 0)
g_settings.video.shader_type = SSNES_SHADER_NONE;
free(tmp_str);
}
#endif
CONFIG_GET_DOUBLE(input.axis_threshold, "input_axis_threshold");
CONFIG_GET_BOOL(input.netplay_client_swap_input, "netplay_client_swap_input");
CONFIG_GET_INT(input.joypad_map[0], "input_player1_joypad_index");

View File

@ -9,9 +9,9 @@
# video_xscale = 3.0
# video_yscale = 3.0
# Fullscreen resolution
# video_fullscreen_x = 1920
# video_fullscreen_y = 1200
# Fullscreen resolution. Resolution of 0 uses the resolution of the desktop.
# video_fullscreen_x = 0
# video_fullscreen_y = 0
# Start in fullscreen. Can be changed at runtime.
# video_fullscreen = false
@ -31,9 +31,13 @@
# Path to Cg shader.
# video_cg_shader = "/path/to/cg/shader.cg"
# Path to bSNES-style XML shader (GLSL only). If both Cg shader path and XML shader path are defined, Cg shader will take priority.
# Path to bSNES-style XML shader (GLSL only). If both Cg shader path and XML shader path are defined,
# Cg shader will take priority unless overridden in video_shader_type.
# video_bsnes_shader = "/path/to/bsnes/xml/shader.shader"
# Which shader type to use. Valid values are "cg", "bsnes", "none" and "auto"
# video_shader_type = auto
# CPU-based filter. Valid ones are: hq2x, hq4x, grayscale, bleed, ntsc.
# video_filter = ntsc