shader.cpp 827 B

123456789101112131415161718192021222324252627282930313233
  1. //
  2. // shader.cpp
  3. // graphics
  4. //
  5. // Created by Sam Jaffe on 7/5/16.
  6. //
  7. #include "game/graphics/shader.hpp"
  8. #include <unordered_map>
  9. #include "game/util/hash.hpp"
  10. #include "helper.hpp"
  11. using namespace graphics;
  12. namespace {
  13. using key_t = std::pair<shaders::type, std::string>;
  14. std::unordered_map<key_t, flyweight<shader>> g_shaders;
  15. }
  16. flyweight<shader> shader::create(shaders::type tp, std::string const & path) {
  17. auto key = std::make_pair(tp, path);
  18. auto found = g_shaders.find(key);
  19. if (found != g_shaders.end()) { return found->second; }
  20. auto id = shaders::init(tp, path);
  21. flyweight<shader> fly{id, {id, tp, path}};
  22. return g_shaders.emplace(key, fly).first->second;
  23. }
  24. shader::shader(unsigned int id, shaders::type type, std::string const & path)
  25. : identity<shader>(id), type(type), path(path) {}