| 123456789101112131415161718192021222324252627282930313233 |
- //
- // shader.cpp
- // graphics
- //
- // Created by Sam Jaffe on 7/5/16.
- //
- #include "game/graphics/shader.hpp"
- #include <unordered_map>
- #include "game/util/hash.hpp"
- #include "helper.hpp"
- using namespace graphics;
- namespace {
- using key_t = std::pair<shaders::type, std::string>;
- std::unordered_map<key_t, flyweight<shader>> g_shaders;
- }
- flyweight<shader> shader::create(shaders::type tp, std::string const & path) {
- auto key = std::make_pair(tp, path);
- auto found = g_shaders.find(key);
- if (found != g_shaders.end()) { return found->second; }
- auto id = shaders::init(tp, path);
- flyweight<shader> fly{id, {id, tp, path}};
- return g_shaders.emplace(key, fly).first->second;
- }
- shader::shader(unsigned int id, shaders::type type, std::string const & path)
- : identity<shader>(id), type(type), path(path) {}
|