Shader directory looks for Cg/Cgp shaders.

This commit is contained in:
Themaister 2012-09-21 21:20:30 +02:00
parent 52cde797c1
commit 102d30473e
6 changed files with 53 additions and 24 deletions

View File

@ -528,7 +528,7 @@ static void init_shader_dir(void)
if (!*g_settings.video.shader_dir)
return;
g_extern.shader_dir.list = dir_list_new(g_settings.video.shader_dir, "shader", false);
g_extern.shader_dir.list = dir_list_new(g_settings.video.shader_dir, "shader|cg|cgp", false);
if (g_extern.shader_dir.list->size == 0)
{
deinit_shader_dir();

View File

@ -105,6 +105,14 @@ struct retro_keybind
uint32_t joyaxis;
};
enum rarch_shader_type
{
RARCH_SHADER_CG,
RARCH_SHADER_BSNES,
RARCH_SHADER_AUTO,
RARCH_SHADER_NONE
};
typedef struct video_info
{
unsigned width;
@ -177,7 +185,7 @@ typedef struct video_driver
// Is the window still active?
bool (*alive)(void *data);
bool (*focus)(void *data); // Does the window have focus?
bool (*xml_shader)(void *data, const char *path); // Sets XML-shader. Might not be implemented.
bool (*set_shader)(void *data, enum rarch_shader_type type, const char *path); // Sets shader. Might not be implemented.
void (*free)(void *data);
const char *ident;
@ -281,7 +289,7 @@ extern const input_driver_t input_null;
#define video_set_nonblock_state_func(state) driver.video->set_nonblock_state(driver.video_data, state)
#define video_alive_func() driver.video->alive(driver.video_data)
#define video_focus_func() driver.video->focus(driver.video_data)
#define video_xml_shader_func(path) driver.video->xml_shader(driver.video_data, path)
#define video_set_shader_func(type, path) driver.video->set_shader(driver.video_data, type, path)
#define video_set_rotation_func(rotate) driver.video->set_rotation(driver.video_data, rotate)
#define video_set_aspect_ratio_func(aspect_idx) driver.video->set_aspect_ratio(driver.video_data, aspect_idx)
#define video_viewport_size_func(width, height) driver.video->viewport_size(driver.video_data, width, height)

View File

@ -73,14 +73,6 @@
#define MAX_PLAYERS 8
enum rarch_shader_type
{
RARCH_SHADER_CG,
RARCH_SHADER_BSNES,
RARCH_SHADER_AUTO,
RARCH_SHADER_NONE
};
// All config related settings go here.
struct settings
{

View File

@ -1447,8 +1447,8 @@ static bool gl_focus(void *data)
return gfx_ctx_window_has_focus();
}
#ifdef HAVE_XML
static bool gl_xml_shader(void *data, const char *path)
#if defined(HAVE_XML) || defined(HAVE_CG)
static bool gl_set_shader(void *data, enum rarch_shader_type type, const char *path)
{
gl_t *gl = (gl_t*)data;
@ -1459,8 +1459,26 @@ static bool gl_xml_shader(void *data, const char *path)
gl_shader_deinit();
if (!gl_glsl_init(path))
return false;
switch (type)
{
#ifdef HAVE_XML
case RARCH_SHADER_BSNES:
if (!gl_glsl_init(path))
return false;
break;
#endif
#ifdef HAVE_CG
case RARCH_SHADER_CG:
if (!gl_cg_init(path))
return false;
break;
#endif
default:
RARCH_ERR("Invalid shader type in gl_set_shader().\n");
return false;
}
#ifdef HAVE_FBO
// Set up render to texture again.
@ -1607,8 +1625,8 @@ const video_driver_t video_gl = {
gl_alive,
gl_focus,
#ifdef HAVE_XML
gl_xml_shader,
#if defined(HAVE_XML) || defined(HAVE_CG)
gl_set_shader,
#else
NULL,
#endif

View File

@ -2264,7 +2264,7 @@ static void check_shader_dir(void)
static bool old_pressed_next = false;
static bool old_pressed_prev = false;
if (!g_extern.shader_dir.list || !driver.video->xml_shader)
if (!g_extern.shader_dir.list || !driver.video->set_shader)
return;
bool should_apply = false;
@ -2286,18 +2286,29 @@ static void check_shader_dir(void)
if (should_apply)
{
const char *shader = g_extern.shader_dir.list->elems[g_extern.shader_dir.ptr].data;
const char *shader = g_extern.shader_dir.list->elems[g_extern.shader_dir.ptr].data;
enum rarch_shader_type type = RARCH_SHADER_NONE;
strlcpy(g_settings.video.bsnes_shader_path, shader, sizeof(g_settings.video.bsnes_shader_path));
g_settings.video.shader_type = RARCH_SHADER_BSNES;
const char *ext = strrchr(shader, '.');
if (ext)
{
if (strcmp(ext, ".shader") == 0)
type = RARCH_SHADER_BSNES;
else if (strcmp(ext, ".cg") == 0 || strcmp(ext, ".cgp") == 0)
type = RARCH_SHADER_CG;
}
if (type == RARCH_SHADER_NONE)
return;
msg_queue_clear(g_extern.msg_queue);
char msg[512];
snprintf(msg, sizeof(msg), "XML shader #%u: \"%s\"", (unsigned)g_extern.shader_dir.ptr, shader);
snprintf(msg, sizeof(msg), "Shader #%u: \"%s\"", (unsigned)g_extern.shader_dir.ptr, shader);
msg_queue_push(g_extern.msg_queue, msg, 1, 120);
RARCH_LOG("Applying shader \"%s\"\n", shader);
if (!video_xml_shader_func(shader))
if (!video_set_shader_func(type, shader))
RARCH_WARN("Failed to apply shader.\n");
}

View File

@ -285,7 +285,7 @@
# input_rate_step_up = kp_plus
# input_rate_step_down = kp_minus
# Applies next and previous XML shader in directory.
# Applies next and previous XML/Cg shader in directory.
# input_shader_next = m
# input_shader_prev = n