static bool gl_cg_load_plain(void *data, const char *path) { cg_shader_data_t *cg = (cg_shader_data_t*)data; if (!gl_cg_load_stock(cg)) return false; cg->shader = (struct video_shader*) calloc(1, sizeof(*cg->shader)); if (!cg->shader) return false; cg->shader->passes = 1; 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->shader->pass[0].source.path, path, sizeof(cg->shader->pass[0].source.path)); if (!gl_cg_compile_program(data, 1, &cg->prg[1], &program_info)) return false; } else { RARCH_LOG("Loading stock Cg file.\n"); cg->prg[1] = cg->prg[0]; } video_shader_resolve_parameters(NULL, cg->shader); return true; }
static void gl_cg_init_menu_shaders(void *data) { struct shader_program_info shader_prog_info; cg_shader_data_t *cg = (cg_shader_data_t*)data; if (!cg) return; #ifdef HAVE_SHADERPIPELINE shader_prog_info.combined = stock_xmb_ribbon_simple; shader_prog_info.is_file = false; gl_cg_compile_program( cg, VIDEO_SHADER_MENU, &cg->prg[VIDEO_SHADER_MENU], &shader_prog_info); gl_cg_set_program_base_attrib(cg, VIDEO_SHADER_MENU); shader_prog_info.combined = stock_xmb_ribbon_simple; shader_prog_info.is_file = false; gl_cg_compile_program( cg, VIDEO_SHADER_MENU_2, &cg->prg[VIDEO_SHADER_MENU_2], &shader_prog_info); gl_cg_set_program_base_attrib(cg, VIDEO_SHADER_MENU_2); shader_prog_info.combined = stock_xmb_snow; shader_prog_info.is_file = false; gl_cg_compile_program( cg, VIDEO_SHADER_MENU_3, &cg->prg[VIDEO_SHADER_MENU_3], &shader_prog_info); gl_cg_set_program_base_attrib(cg, VIDEO_SHADER_MENU_3); #endif }
static bool gl_cg_load_shader(void *data, unsigned i) { struct shader_program_info program_info; cg_shader_data_t *cg = (cg_shader_data_t*)data; program_info.combined = cg->shader->pass[i].source.path; program_info.is_file = true; RARCH_LOG("Loading Cg shader: \"%s\".\n", cg->shader->pass[i].source.path); if (!gl_cg_compile_program(data, i + 1, &cg->prg[i + 1],&program_info)) return false; return true; }
static bool gl_cg_load_stock(void *data) { struct shader_program_info program_info; cg_shader_data_t *cg = (cg_shader_data_t*)data; program_info.combined = stock_cg_gl_program; program_info.is_file = false; if (!gl_cg_compile_program(data, 0, &cg->prg[0], &program_info)) goto error; gl_cg_set_program_base_attrib(data, 0); return true; error: RARCH_ERR("Failed to compile passthrough shader, is something wrong with your environment?\n"); return false; }
static void *gl_cg_init(void *data, const char *path) { unsigned i; struct shader_program_info shader_prog_info; cg_shader_data_t *cg = (cg_shader_data_t*) calloc(1, sizeof(cg_shader_data_t)); if (!cg) return NULL; #ifdef HAVE_CG_RUNTIME_COMPILER cgRTCgcInit(); #endif cg->cgCtx = cgCreateContext(); if (!cg->cgCtx) { RARCH_ERR("Failed to create Cg context.\n"); goto error; } #ifdef RARCH_CG_DEBUG cgGLSetDebugMode(CG_TRUE); cgSetErrorHandler(cg_error_handler, NULL); #endif cg->cgFProf = cgGLGetLatestProfile(CG_GL_FRAGMENT); cg->cgVProf = cgGLGetLatestProfile(CG_GL_VERTEX); if ( cg->cgFProf == CG_PROFILE_UNKNOWN || cg->cgVProf == CG_PROFILE_UNKNOWN) { RARCH_ERR("Invalid profile type\n"); goto error; } RARCH_LOG("[Cg]: Vertex profile: %s\n", cgGetProfileString(cg->cgVProf)); RARCH_LOG("[Cg]: Fragment profile: %s\n", cgGetProfileString(cg->cgFProf)); cgGLSetOptimalOptions(cg->cgFProf); cgGLSetOptimalOptions(cg->cgVProf); cgGLEnableProfile(cg->cgFProf); cgGLEnableProfile(cg->cgVProf); memset(cg->alias_define, 0, sizeof(cg->alias_define)); if (path && string_is_equal(path_get_extension(path), "cgp")) { if (!gl_cg_load_preset(cg, path)) goto error; } else { if (!gl_cg_load_plain(cg, path)) goto error; } cg->prg[0].mvp = cgGetNamedParameter(cg->prg[0].vprg, "IN.mvp_matrix"); for (i = 1; i <= cg->shader->passes; i++) gl_cg_set_program_attributes(cg, i); /* If we aren't using last pass non-FBO shader, * this shader will be assumed to be "fixed-function". * * Just use prg[0] for that pass, which will be * pass-through. */ cg->prg[cg->shader->passes + 1] = cg->prg[0]; /* No need to apply Android hack in Cg. */ cg->prg[VIDEO_SHADER_STOCK_BLEND] = cg->prg[0]; gl_cg_set_shaders(cg->prg[1].fprg, cg->prg[1].vprg); shader_prog_info.combined = stock_xmb_simple; shader_prog_info.is_file = false; gl_cg_compile_program( cg, VIDEO_SHADER_MENU, &cg->prg[VIDEO_SHADER_MENU], &shader_prog_info); gl_cg_set_program_base_attrib(cg, VIDEO_SHADER_MENU); shader_prog_info.combined = stock_xmb_simple; shader_prog_info.is_file = false; gl_cg_compile_program( cg, VIDEO_SHADER_MENU_SEC, &cg->prg[VIDEO_SHADER_MENU_SEC], &shader_prog_info); gl_cg_set_program_base_attrib(cg, VIDEO_SHADER_MENU_SEC); gl_cg_reset_attrib(cg); return cg; error: gl_cg_destroy_resources(cg); if (!cg) free(cg); return NULL; }