Experiment with shader parameters.

This commit is contained in:
Themaister 2014-05-22 21:24:52 +02:00
parent b19cf62c63
commit 4722b6af75
4 changed files with 72 additions and 4 deletions

View File

@ -489,6 +489,7 @@ static bool load_plain(const char *path)
prg[1] = prg[0];
}
gfx_shader_resolve_parameters(NULL, cg_shader);
return true;
}
@ -580,8 +581,9 @@ static bool load_preset(const char *path)
return false;
}
config_file_free(conf);
gfx_shader_resolve_relative(cg_shader, path);
gfx_shader_resolve_parameters(conf, cg_shader);
config_file_free(conf);
if (cg_shader->passes > GFX_MAX_SHADERS - 3)
{

View File

@ -662,6 +662,8 @@ static bool gl_glsl_init(void *data, const char *path)
if (!glsl_shader)
return false;
config_file_t *conf = NULL;
if (path)
{
bool ret;
@ -674,12 +676,11 @@ static bool gl_glsl_init(void *data, const char *path)
}
else if (strcmp(path_get_extension(path), "glslp") == 0)
{
config_file_t *conf = config_file_new(path);
conf = config_file_new(path);
if (conf)
{
ret = gfx_shader_read_conf_cgp(conf, glsl_shader);
glsl_shader->modern = true;
config_file_free(conf);
}
else
ret = false;
@ -703,6 +704,13 @@ static bool gl_glsl_init(void *data, const char *path)
}
gfx_shader_resolve_relative(glsl_shader, path);
gfx_shader_resolve_parameters(conf, glsl_shader);
if (conf)
{
config_file_free(conf);
conf = NULL;
}
const char *stock_vertex = glsl_shader->modern ?
stock_vertex_modern : stock_vertex_legacy;

View File

@ -268,10 +268,53 @@ static bool shader_parse_textures(config_file_t *conf, struct gfx_shader *shader
return true;
}
bool gfx_shader_resolve_parameters(config_file_t *conf, struct gfx_shader *shader)
{
char parameters[1024];
char *save = NULL;
const char *id;
unsigned i, line;
shader->num_parameters = 0;
struct gfx_shader_parameter *param = &shader->parameters[shader->num_parameters];
// Find all parameters in our shaders.
for (i = 0; i < shader->passes; i++)
{
char line[2048];
FILE *file = fopen(shader->pass[i].source.cg, "r");
if (!file)
continue;
while (shader->num_parameters < ARRAY_SIZE(shader->parameters) && fgets(line, sizeof(line), file))
{
int ret = sscanf(line, "#pragma parameter %64s \"%64[^\"]\" %f %f %f %f",
param->id, param->desc, &param->initial, &param->minimum, &param->maximum, &param->step);
if (ret == 6)
{
param->id[63] = '\0';
param->desc[63] = '\0';
RARCH_LOG("Found #pragma parameter %s (%s) %f %f %f %f\n",
param->desc, param->id, param->initial, param->minimum, param->maximum, param->step);
shader->num_parameters++;
param++;
}
}
fclose(file);
}
if (!config_get_array(conf, "parameters", parameters, sizeof(parameters)))
return true;
return true;
}
static bool shader_parse_imports(config_file_t *conf, struct gfx_shader *shader)
{
char imports[1024];
char *save;
char *save = NULL;
const char *id;
if (!config_get_array(conf, "imports", imports, sizeof(imports)))
return true;

View File

@ -65,6 +65,17 @@ struct gfx_fbo_scale
bool valid;
};
struct gfx_shader_parameter
{
char id[64];
char desc[64];
float current;
float minimum;
float initial;
float maximum;
float step;
};
struct gfx_shader_pass
{
struct
@ -108,6 +119,9 @@ struct gfx_shader
unsigned luts;
struct gfx_shader_lut lut[GFX_MAX_TEXTURES];
struct gfx_shader_parameter parameters[64];
unsigned num_parameters;
unsigned variables;
struct state_tracker_uniform_info variable[GFX_MAX_VARIABLES];
char script_path[PATH_MAX];
@ -119,6 +133,7 @@ bool gfx_shader_read_conf_cgp(config_file_t *conf, 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);
bool gfx_shader_resolve_parameters(config_file_t *conf, struct gfx_shader *shader);
enum rarch_shader_type gfx_shader_parse_type(const char *path, enum rarch_shader_type fallback);