mirror of
https://github.com/libretro/RetroArch
synced 2025-03-05 19:13:45 +00:00
Add gfx_shader_resolve_relative.
Translates relative paths (from CGP) into absolute paths, suitable for loading files, and saving cgp some place else.
This commit is contained in:
parent
80d249cd61
commit
2c8ddeb109
@ -1408,7 +1408,8 @@ static void shader_manager_init(rgui_handle_t *rgui)
|
||||
conf = config_file_new(g_settings.video.shader_path);
|
||||
if (conf)
|
||||
{
|
||||
gfx_shader_read_conf_cgp(conf, &rgui->shader);
|
||||
if (gfx_shader_read_conf_cgp(conf, &rgui->shader))
|
||||
gfx_shader_resolve_relative(&rgui->shader, g_settings.video.shader_path);
|
||||
config_file_free(conf);
|
||||
}
|
||||
}
|
||||
@ -1434,7 +1435,8 @@ static void shader_manager_init(rgui_handle_t *rgui)
|
||||
|
||||
if (conf)
|
||||
{
|
||||
gfx_shader_read_conf_cgp(conf, &rgui->shader);
|
||||
if (gfx_shader_read_conf_cgp(conf, &rgui->shader))
|
||||
gfx_shader_resolve_relative(&rgui->shader, cgp_path);
|
||||
config_file_free(conf);
|
||||
}
|
||||
}
|
||||
|
@ -508,7 +508,7 @@ static void load_texture_data(GLuint obj, const struct texture_image *img, bool
|
||||
free(img->pixels);
|
||||
}
|
||||
|
||||
static bool load_textures(const char *cgp_path)
|
||||
static bool load_textures(void)
|
||||
{
|
||||
if (!cg_shader->luts)
|
||||
return true;
|
||||
@ -517,14 +517,11 @@ static bool load_textures(const char *cgp_path)
|
||||
|
||||
for (unsigned i = 0; i < cg_shader->luts; i++)
|
||||
{
|
||||
char image_path[PATH_MAX];
|
||||
fill_pathname_resolve_relative(image_path, cgp_path,
|
||||
cg_shader->lut[i].path, sizeof(image_path));
|
||||
|
||||
RARCH_LOG("Loading image from: \"%s\".\n", image_path);
|
||||
RARCH_LOG("Loading image from: \"%s\".\n",
|
||||
cg_shader->lut[i].path);
|
||||
|
||||
struct texture_image img;
|
||||
if (!texture_image_load(image_path, &img))
|
||||
if (!texture_image_load(cg_shader->lut[i].path, &img))
|
||||
{
|
||||
RARCH_ERR("Failed to load picture ...\n");
|
||||
return false;
|
||||
@ -538,7 +535,7 @@ static bool load_textures(const char *cgp_path)
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool load_imports(const char *cgp_path)
|
||||
static bool load_imports(void)
|
||||
{
|
||||
struct state_tracker_info tracker_info = {0};
|
||||
|
||||
@ -567,12 +564,9 @@ static bool load_imports(const char *cgp_path)
|
||||
tracker_info.info_elem = cg_shader->variables;
|
||||
|
||||
#ifdef HAVE_PYTHON
|
||||
char script_path[PATH_MAX];
|
||||
if (*cg_shader->script_path)
|
||||
{
|
||||
fill_pathname_resolve_relative(script_path, cgp_path,
|
||||
cg_shader->script_path, sizeof(script_path));
|
||||
tracker_info.script = script_path;
|
||||
tracker_info.script = cg_shader->script_path;
|
||||
tracker_info.script_is_file = true;
|
||||
}
|
||||
|
||||
@ -586,15 +580,12 @@ static bool load_imports(const char *cgp_path)
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool load_shader(const char *cgp_path, unsigned i)
|
||||
static bool load_shader(unsigned i)
|
||||
{
|
||||
char path_buf[PATH_MAX];
|
||||
fill_pathname_resolve_relative(path_buf, cgp_path,
|
||||
cg_shader->pass[i].source.cg, sizeof(path_buf));
|
||||
RARCH_LOG("Loading Cg shader: \"%s\".\n",
|
||||
cg_shader->pass[i].source.cg);
|
||||
|
||||
RARCH_LOG("Loading Cg shader: \"%s\".\n", path_buf);
|
||||
|
||||
if (!load_program(i + 1, path_buf, true))
|
||||
if (!load_program(i + 1, cg_shader->pass[i].source.cg, true))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
@ -626,13 +617,7 @@ static bool load_preset(const char *path)
|
||||
}
|
||||
|
||||
config_file_free(conf);
|
||||
|
||||
#if 0 // Debugging
|
||||
config_file_t *save_test = config_file_new(NULL);
|
||||
gfx_shader_write_conf_cgp(conf, cg_shader);
|
||||
config_file_write(save_test, "/tmp/load.cgp");
|
||||
config_file_free(save_test);
|
||||
#endif
|
||||
gfx_shader_resolve_relative(cg_shader, path);
|
||||
|
||||
if (cg_shader->passes > RARCH_CG_MAX_SHADERS - 3)
|
||||
{
|
||||
@ -641,20 +626,20 @@ static bool load_preset(const char *path)
|
||||
}
|
||||
for (unsigned i = 0; i < cg_shader->passes; i++)
|
||||
{
|
||||
if (!load_shader(path, i))
|
||||
if (!load_shader(i))
|
||||
{
|
||||
RARCH_ERR("Failed to load shaders ...\n");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!load_textures(path))
|
||||
if (!load_textures())
|
||||
{
|
||||
RARCH_ERR("Failed to load lookup textures ...\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!load_imports(path))
|
||||
if (!load_imports())
|
||||
{
|
||||
RARCH_ERR("Failed to load imports ...\n");
|
||||
return false;
|
||||
|
@ -252,7 +252,7 @@ static GLint get_attrib(GLuint prog, const char *base)
|
||||
return -1;
|
||||
}
|
||||
|
||||
static bool load_luts(const char *shader_path)
|
||||
static bool load_luts(void)
|
||||
{
|
||||
if (!glsl_shader->luts)
|
||||
return true;
|
||||
@ -261,16 +261,13 @@ static bool load_luts(const char *shader_path)
|
||||
|
||||
for (unsigned i = 0; i < glsl_shader->luts; i++)
|
||||
{
|
||||
char tex_path[PATH_MAX];
|
||||
fill_pathname_resolve_relative(tex_path,
|
||||
shader_path, glsl_shader->lut[i].path, sizeof(tex_path));
|
||||
|
||||
RARCH_LOG("Loading texture image from: \"%s\" ...\n", tex_path);
|
||||
RARCH_LOG("Loading texture image from: \"%s\" ...\n",
|
||||
glsl_shader->lut[i].path);
|
||||
|
||||
struct texture_image img = {0};
|
||||
if (!texture_image_load(tex_path, &img))
|
||||
if (!texture_image_load(glsl_shader->lut[i].path, &img))
|
||||
{
|
||||
RARCH_ERR("Failed to load texture image from: \"%s\"\n", tex_path);
|
||||
RARCH_ERR("Failed to load texture image from: \"%s\"\n", glsl_shader->lut[i].path);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -422,18 +419,16 @@ static GLuint compile_program(const char *vertex, const char *fragment, unsigned
|
||||
return prog;
|
||||
}
|
||||
|
||||
static bool load_source_path(struct gfx_shader_pass *pass, const char *base, const char *path)
|
||||
static bool load_source_path(struct gfx_shader_pass *pass, const char *path)
|
||||
{
|
||||
char fullpath[PATH_MAX];
|
||||
fill_pathname_resolve_relative(fullpath, base, path, sizeof(fullpath));
|
||||
if (read_file(fullpath, (void**)&pass->source.xml.vertex) <= 0)
|
||||
if (read_file(path, (void**)&pass->source.xml.vertex) <= 0)
|
||||
return false;
|
||||
|
||||
pass->source.xml.fragment = strdup(pass->source.xml.vertex);
|
||||
return pass->source.xml.fragment && pass->source.xml.vertex;
|
||||
}
|
||||
|
||||
static bool compile_programs(const char *base, GLuint *gl_prog)
|
||||
static bool compile_programs(GLuint *gl_prog)
|
||||
{
|
||||
for (unsigned i = 0; i < glsl_shader->passes; i++)
|
||||
{
|
||||
@ -442,7 +437,7 @@ static bool compile_programs(const char *base, GLuint *gl_prog)
|
||||
// If we load from GLSLP (CGP),
|
||||
// load the file here, and pretend
|
||||
// we were really using XML all along.
|
||||
if (*pass->source.cg && !load_source_path(pass, base, pass->source.cg))
|
||||
if (*pass->source.cg && !load_source_path(pass, pass->source.cg))
|
||||
{
|
||||
RARCH_ERR("Failed to load GLSL shader: %s.\n", pass->source.cg);
|
||||
return false;
|
||||
@ -658,6 +653,8 @@ static bool gl_glsl_init(const char *path)
|
||||
glsl_shader->modern = true;
|
||||
}
|
||||
|
||||
gfx_shader_resolve_relative(glsl_shader, path);
|
||||
|
||||
#ifdef HAVE_OPENGLES2
|
||||
if (!glsl_shader->modern)
|
||||
{
|
||||
@ -678,13 +675,13 @@ static bool gl_glsl_init(const char *path)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!compile_programs(path, &gl_program[1]))
|
||||
if (!compile_programs(&gl_program[1]))
|
||||
{
|
||||
gl_glsl_free_shader();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!load_luts(path))
|
||||
if (!load_luts())
|
||||
{
|
||||
RARCH_ERR("[GL]: Failed to load LUTs.\n");
|
||||
gl_glsl_free_shader();
|
||||
|
@ -1069,3 +1069,31 @@ enum rarch_shader_type gfx_shader_parse_type(const char *path, enum rarch_shader
|
||||
return fallback;
|
||||
}
|
||||
|
||||
void gfx_shader_resolve_relative(struct gfx_shader *shader, const char *ref_path)
|
||||
{
|
||||
char tmp_path[PATH_MAX];
|
||||
for (unsigned i = 0; i < shader->passes; i++)
|
||||
{
|
||||
if (!*shader->pass[i].source.cg)
|
||||
continue;
|
||||
|
||||
strlcpy(tmp_path, shader->pass[i].source.cg, sizeof(tmp_path));
|
||||
fill_pathname_resolve_relative(shader->pass[i].source.cg,
|
||||
ref_path, tmp_path, sizeof(shader->pass[i].source.cg));
|
||||
}
|
||||
|
||||
for (unsigned i = 0; i < shader->luts; i++)
|
||||
{
|
||||
strlcpy(tmp_path, shader->lut[i].path, sizeof(tmp_path));
|
||||
fill_pathname_resolve_relative(shader->lut[i].path,
|
||||
ref_path, tmp_path, sizeof(shader->lut[i].path));
|
||||
}
|
||||
|
||||
if (*shader->script_path)
|
||||
{
|
||||
strlcpy(tmp_path, shader->script_path, sizeof(tmp_path));
|
||||
fill_pathname_resolve_relative(shader->script_path,
|
||||
ref_path, tmp_path, sizeof(shader->script_path));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -105,6 +105,8 @@ bool gfx_shader_read_conf_cgp(config_file_t *conf, struct gfx_shader *shader);
|
||||
bool gfx_shader_read_xml(const char *path, struct gfx_shader *shader);
|
||||
void gfx_shader_write_conf_cgp(config_file_t *conf, const struct gfx_shader *shader);
|
||||
|
||||
void gfx_shader_resolve_relative(struct gfx_shader *shader, const char *ref_path);
|
||||
|
||||
enum rarch_shader_type gfx_shader_parse_type(const char *path, enum rarch_shader_type fallback);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
Loading…
x
Reference in New Issue
Block a user