Browse Source

Fix a bug where we have not yet started openGL properly when we load the default textures.

Sam Jaffe 6 years ago
parent
commit
761761dd90
3 changed files with 18 additions and 11 deletions
  1. 3 3
      graphics/include/game/graphics/texture.hpp
  2. 3 3
      graphics/src/material.cpp
  3. 12 5
      graphics/src/texture.cpp

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

@@ -14,9 +14,9 @@
 namespace graphics {
   class texture : public identity<texture> {
   public:
-    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();
     math::vec2i const size;
 
   public:

+ 3 - 3
graphics/src/material.cpp

@@ -30,11 +30,11 @@ flyweight<texture> get_texture(std::string const & texture,
     }
   }
   if (uniform == "u_normalMap") {
-    return texture::LIGHT_BLUE;
+    return texture::LIGHT_BLUE();
   } else if (uniform == "u_specularMap") {
-    return texture::DARK_YELLOW;
+    return texture::DARK_YELLOW();
   } else if (uniform == "u_diffuseMap") {
-    return texture::WHITE;
+    return texture::WHITE();
   }
   throw;
 }

+ 12 - 5
graphics/src/texture.cpp

@@ -61,8 +61,15 @@ texture texture::create(char const * data, math::vec2i size) {
 texture::texture(unsigned int id, math::vec2i sz)
     : identity<texture>(id), size(sz) {}
 
-texture const texture::WHITE = texture::create("\xFF\xFF\xFF\xFF", {{1, 1}});
-texture const texture::DARK_YELLOW =
-    texture::create("\x80\x80\x00\xFF", {{1, 1}});
-texture const texture::LIGHT_BLUE =
-    texture::create("\x80\x80\xFF\xFF", {{1, 1}});
+texture const texture::WHITE() {
+  static auto t = texture::create("\xFF\xFF\xFF\xFF", {{1, 1}});
+  return t;
+}
+texture const texture::DARK_YELLOW() {
+  static auto t = texture::create("\x80\x80\x00\xFF", {{1, 1}});
+  return t;
+}
+texture const texture::LIGHT_BLUE() {
+  static auto t = texture::create("\x80\x80\xFF\xFF", {{1, 1}});
+  return t;
+}