]> git.tdb.fi Git - libs/gl.git/blobdiff - source/core/texture.cpp
Fix reflection of image types from Spir-V modules
[libs/gl.git] / source / core / texture.cpp
index 175e76a2365688c8aef1f30592759d8addbefab1..b8a2614a1da9b697410067a7daaad807476ace7c 100644 (file)
@@ -1,3 +1,4 @@
+#include <msp/datafile/rawdata.h>
 #include <msp/io/memory.h>
 #include "error.h"
 #include "resourcemanager.h"
@@ -25,28 +26,8 @@ Texture::Texture(unsigned t):
 void Texture::set_format(PixelFormat fmt)
 {
        PixelComponents comp = get_components(fmt);
-       PixelComponents st_comp = comp;
-       FormatSwizzle swiz = NO_SWIZZLE;
-       switch(comp)
-       {
-       case LUMINANCE:
-               st_comp = RED;
-               swiz = R_TO_LUMINANCE;
-               break;
-       case LUMINANCE_ALPHA:
-               st_comp = RG;
-               swiz = RG_TO_LUMINANCE_ALPHA;
-               break;
-       case BGR:
-               st_comp = RGB;
-               swiz = RGB_TO_BGR;
-               break;
-       case BGRA:
-               st_comp = RGBA;
-               swiz = RGB_TO_BGR;
-               break;
-       default:;
-       }
+       ComponentSwizzle swiz = get_required_swizzle(comp);
+       PixelComponents st_comp = unswizzle_components(comp, swiz);
 
        PixelFormat st_fmt = make_pixelformat(st_comp, get_component_type(fmt), is_srgb(fmt));
        require_pixelformat(st_fmt);
@@ -87,6 +68,7 @@ Texture::Loader::Loader(Texture &t, Collection *c):
        CollectionObjectLoader<Texture>(t, c),
        levels(0)
 {
+       add("external_data", &Loader::external_data);
        add("external_image", &Loader::external_image, false);
        add("external_image_srgb", &Loader::external_image, true);
        add("generate_mipmap", &Loader::generate_mipmap);
@@ -109,6 +91,19 @@ void Texture::Loader::load_external_image(Graphics::Image &img, const string &fn
        img.load_io(*io);
 }
 
+void Texture::Loader::external_data(const string &fn)
+{
+       if(obj.manager)
+               obj.manager->set_resource_location(obj, get_collection(), fn);
+       else
+       {
+               DataFile::RawData rd;
+               rd.open_file(get_collection(), fn);
+               rd.load();
+               obj.image(0, rd.get_data());
+       }
+}
+
 void Texture::Loader::external_image(bool srgb, const string &fn)
 {
        obj.use_srgb_format = srgb;