Pārlūkot izejas kodu

Fixing texture size fetching for materials.

Sam Jaffe 6 gadi atpakaļ
vecāks
revīzija
a86fb00358

+ 1 - 0
graphics/include/game/graphics/manager.hpp

@@ -31,6 +31,7 @@ namespace graphics {
     object create_object(identity<material> fromMaterial, math::vec2 atPosition,
                          math::vec2 frameWidth) const;
     material const & get(identity<material> identity) const;
+    texture const & get(identity<texture> identity) const;
 
   private:
     identity<texture> texture_or_uniform(std::string const & path,

+ 3 - 3
graphics/include/game/graphics/texture.hpp

@@ -16,9 +16,9 @@ namespace graphics {
   public:
     texture(std::string const & str);
 
-    static texture const WHITE();
-    static texture const DARK_YELLOW();
-    static texture const LIGHT_BLUE();
+    static texture const & WHITE();
+    static texture const & DARK_YELLOW();
+    static texture const & LIGHT_BLUE();
 
   private:
     texture(std::pair<unsigned int, math::vec2i>);

+ 8 - 1
graphics/src/manager.cxx

@@ -66,7 +66,7 @@ identity<material> manager::get(identity<shader_program> program,
   std::vector<struct uniform> uniforms;
   uniforms.push_back({texture_or_uniform(texture, uniform),
                       shaders::uniform_location(program, uniform)});
-  math::vec2i size = make_vector(1, 1);
+  math::vec2i size = get(uniforms[0].texture).size;
   //  if (!uniforms.empty()) { size = ...; }
   return cache.emplace(key, material(program, size, uniforms));
 }
@@ -76,6 +76,13 @@ material const & manager::get(identity<material> identity) const {
   return cache.values.find(cache.keys.find(identity)->second)->second;
 }
 
+texture const & manager::get(identity<texture> identity) const {
+  auto & cache = pimpl_->textures;
+  auto it = cache.keys.find(identity);
+  if (it == cache.keys.end()) { return texture::WHITE(); }
+  return cache.values.find(it->second)->second;
+}
+
 identity<shader> manager::get(shaders::type type,
                               std::string const & path) const {
   auto key = std::make_pair(type, path);

+ 3 - 3
graphics/src/texture.cpp

@@ -54,15 +54,15 @@ texture::texture(std::pair<unsigned int, math::vec2i> pair)
 texture::texture(char const * data, math::vec2i size)
     : identity<texture>(textures::init(format(4), size, data)), size(size) {}
 
-texture const texture::WHITE() {
+texture const & texture::WHITE() {
   static auto t = texture("\xFF\xFF\xFF\xFF", {{1, 1}});
   return t;
 }
-texture const texture::DARK_YELLOW() {
+texture const & texture::DARK_YELLOW() {
   static auto t = texture("\x80\x80\x00\xFF", {{1, 1}});
   return t;
 }
-texture const texture::LIGHT_BLUE() {
+texture const & texture::LIGHT_BLUE() {
   static auto t = texture("\x80\x80\xFF\xFF", {{1, 1}});
   return t;
 }