|
|
@@ -14,9 +14,11 @@ using namespace graphics;
|
|
|
|
|
|
namespace {
|
|
|
using key_t = std::pair<shaders::type, std::string>;
|
|
|
- std::unordered_map<std::string, material> g_materials;
|
|
|
+ std::unordered_map<std::string, flyweight<material>> g_materials;
|
|
|
}
|
|
|
|
|
|
+static math::vec2i ZERO{{0, 0}};
|
|
|
+
|
|
|
flyweight<texture> get_texture(std::string const & texture,
|
|
|
std::string const & uniform) {
|
|
|
if (!texture.empty()) {
|
|
|
@@ -43,8 +45,13 @@ flyweight<material> material::create(shader_program const & sp,
|
|
|
material mat{++id, sp};
|
|
|
mat.uniforms.push_back({get_texture(texture, uniform),
|
|
|
shaders::uniform_location(sp.id, uniform)});
|
|
|
- return g_materials.emplace("", std::move(mat)).first->second;
|
|
|
+ flyweight<material> fly{id, mat};
|
|
|
+ return g_materials.emplace("", fly).first->second;
|
|
|
}
|
|
|
|
|
|
material::material(unsigned int id, shader_program const & sp)
|
|
|
: identity<material>(id), shaders(sp) {}
|
|
|
+
|
|
|
+math::vec2i material::size() const {
|
|
|
+ return uniforms.empty() ? ZERO : uniforms.front().texture.actual().size;
|
|
|
+}
|