5 #include "shader_manager.h"
6 #include "opengl/shader-gl.h"
8 ShaderManager::ShaderManager() {}
9 ShaderManager::~ShaderManager() {}
11 void ShaderManager::add_shader(Shader *sdr, const char *name)
16 Shader *ShaderManager::load_shader(const char *name, SType type)
18 std::map<std::string, Shader *>::const_iterator it;
19 it = shaders.find(name);
21 if(it != shaders.end()) {
25 Shader *sdr = gfx_create_shader();
27 std::string fname = path.empty() ? std::string(name) : path + "/" + std::string(name);
29 if(!sdr->load(fname.c_str(), type)) {
30 fprintf(stderr, "Failed to load shader: %s.\n", fname.c_str());
35 add_shader(sdr, name);
39 void ShaderManager::delete_shaders()
41 std::map<std::string, Shader *>::iterator it;
42 for(it=shaders.begin(); it != shaders.end(); it++) {
47 ShaderProgram *ShaderManager::create_shader_program(const char *vname, const char *fname)
49 path = std::string(gfx_get_shader_path());
51 Shader *vsdr = load_shader(vname, SDR_VERTEX);
55 Shader *fsdr = load_shader(fname, SDR_FRAGMENT);
59 ShaderProgram *sprog = gfx_create_shader_program();
61 if(!sprog->create()) {
65 sprog->attach_shader(vsdr);
66 sprog->attach_shader(fsdr);
76 void ShaderManager::set_path(const char *path)
81 this->path = std::string(path);