Преглед на файлове

Add mapping to color style for texture.

Sam Jaffe преди 6 години
родител
ревизия
e6f87a3401
променени са 1 файла, в които са добавени 12 реда и са изтрити 2 реда
  1. 12 2
      graphics/src/texture.cpp

+ 12 - 2
graphics/src/texture.cpp

@@ -25,6 +25,16 @@ namespace {
 }
 
 namespace graphics {
+  static detail::texture::format format(int comps) {
+    switch (comps) {
+    case 3:
+      return detail::texture::format::RGB;
+    case 4:
+      return detail::texture::format::RGBA;
+    default:
+      throw;
+    }
+  }
   texture texture::create(std::string const & imagefile) {
     auto found = g_textures.find(imagefile);
     if (found != g_textures.end()) { return found->second; }
@@ -34,12 +44,12 @@ namespace graphics {
     unsigned char * data =
         stbi_load(imagefile.c_str(), &size.x(), &size.y(), &components, 0);
     scope(exit) { stbi_image_free(data); };
-    texture tex{detail::texture::init({}, size, data), size};
+    texture tex{detail::texture::init(format(components), size, data), size};
     return g_textures.emplace(imagefile, std::move(tex)).first->second;
   }
 
   texture texture::create(unsigned char * data, math::vec2i size) {
-    return {detail::texture::init({}, size, data), size};
+    return {detail::texture::init(format(4), size, data), size};
   }
 
   texture::texture(unsigned int id, math::vec2i sz)