|
|
@@ -13,8 +13,8 @@
|
|
|
using namespace graphics;
|
|
|
|
|
|
namespace {
|
|
|
- using key_t = std::pair<shaders::type, std::string>;
|
|
|
- std::unordered_map<std::string, flyweight<material>> g_materials;
|
|
|
+ using key_t = std::tuple<flyweight<shader_program>, std::string, std::string>;
|
|
|
+ std::unordered_map<key_t, flyweight<material>> g_materials;
|
|
|
}
|
|
|
|
|
|
static math::vec2i ZERO{{0, 0}};
|
|
|
@@ -41,12 +41,16 @@ flyweight<texture> get_texture(std::string const & texture,
|
|
|
flyweight<material> material::create(shader_program const & sp,
|
|
|
std::string const & texture,
|
|
|
std::string const & uniform) {
|
|
|
+ key_t key = std::make_tuple(sp, texture, uniform);
|
|
|
+ auto found = g_materials.find(key);
|
|
|
+ if (found != g_materials.end()) { return found->second; }
|
|
|
+
|
|
|
static unsigned int id{0};
|
|
|
material mat{++id, sp};
|
|
|
mat.uniforms.push_back({get_texture(texture, uniform),
|
|
|
shaders::uniform_location(sp.id, uniform)});
|
|
|
flyweight<material> fly{id, mat};
|
|
|
- return g_materials.emplace("", fly).first->second;
|
|
|
+ return g_materials.emplace(key, fly).first->second;
|
|
|
}
|
|
|
|
|
|
material::material(unsigned int id, shader_program const & sp)
|