(Shaders) Refactor shader program compiling code

This commit is contained in:
twinaphex 2016-04-13 20:14:25 +02:00
parent 1e9aed1683
commit 511fbcda93
2 changed files with 28 additions and 12 deletions

View File

@ -609,8 +609,9 @@ static void gl_cg_deinit(void *data)
listing_##type = strdup(list); \
}
static bool gl_cg_compile_program(void *data, unsigned idx,
const char *prog, bool path_is_file)
static bool gl_cg_compile_program(void *data,
unsigned idx,
struct shader_program_info *program_info)
{
const char *argv[2 + GFX_MAX_SHADERS];
bool ret = true;
@ -627,24 +628,24 @@ static bool gl_cg_compile_program(void *data, unsigned idx,
}
argv[argc] = NULL;
if (path_is_file)
if (program_info->is_file)
{
cg_data->prg[idx].fprg = cgCreateProgramFromFile(
cg_data->cgCtx, CG_SOURCE,
prog, cg_data->cgFProf, "main_fragment", argv);
program_info->combined, cg_data->cgFProf, "main_fragment", argv);
CG_GL_SET_LISTING(cg_data, f);
cg_data->prg[idx].vprg = cgCreateProgramFromFile(
cg_data->cgCtx, CG_SOURCE,
prog, cg_data->cgVProf, "main_vertex", argv);
program_info->combined, cg_data->cgVProf, "main_vertex", argv);
CG_GL_SET_LISTING(cg_data, v);
}
else
{
cg_data->prg[idx].fprg = cgCreateProgram(cg_data->cgCtx, CG_SOURCE,
prog, cg_data->cgFProf, "main_fragment", argv);
program_info->combined, cg_data->cgFProf, "main_fragment", argv);
CG_GL_SET_LISTING(cg_data, f);
cg_data->prg[idx].vprg = cgCreateProgram(cg_data->cgCtx, CG_SOURCE,
prog, cg_data->cgVProf, "main_vertex", argv);
program_info->combined, cg_data->cgVProf, "main_vertex", argv);
CG_GL_SET_LISTING(cg_data, v);
}
@ -722,7 +723,12 @@ static void gl_cg_set_program_base_attrib(void *data, unsigned i)
static bool gl_cg_load_stock(void *data)
{
if (!gl_cg_compile_program(data, 0, stock_cg_gl_program, false))
struct shader_program_info program_info;
program_info.combined = stock_cg_gl_program;
program_info.is_file = false;
if (!gl_cg_compile_program(data, 0, &program_info))
{
RARCH_ERR("Failed to compile passthrough shader, is something wrong with your environment?\n");
return false;
@ -747,10 +753,15 @@ static bool gl_cg_load_plain(void *data, const char *path)
if (path)
{
struct shader_program_info program_info;
program_info.combined = path;
program_info.is_file = true;
RARCH_LOG("Loading Cg file: %s\n", path);
strlcpy(cg_data->shader->pass[0].source.path, path,
sizeof(cg_data->shader->pass[0].source.path));
if (!gl_cg_compile_program(data, 1, path, true))
if (!gl_cg_compile_program(data, 1, &program_info))
return false;
}
else
@ -829,13 +840,16 @@ static bool gl_cg_load_imports(void *data)
static bool gl_cg_load_shader(void *data, unsigned i)
{
struct shader_program_info program_info;
cg_shader_data_t *cg_data = (cg_shader_data_t*)data;
program_info.combined = cg_data->shader->pass[i].source.path;
program_info.is_file = true;
RARCH_LOG("Loading Cg shader: \"%s\".\n",
cg_data->shader->pass[i].source.path);
if (!gl_cg_compile_program(cg_data, i + 1,
cg_data->shader->pass[i].source.path, true))
if (!gl_cg_compile_program(data, i + 1, &program_info))
return false;
return true;

View File

@ -419,12 +419,14 @@ static bool gl_glsl_link_program(GLuint prog)
return true;
}
static GLuint gl_glsl_compile_program(glsl_shader_data_t *glsl,
static GLuint gl_glsl_compile_program(
void *data,
unsigned idx,
struct shader_program_info *program_info)
{
GLuint vert = 0;
GLuint frag = 0;
glsl_shader_data_t *glsl = (glsl_shader_data_t*)data;
GLuint prog = glCreateProgram();
if (!prog)