]> git.tdb.fi Git - libs/gl.git/commitdiff
Add a datafile statement to use an external image for a texture
authorMikko Rasa <tdb@tdb.fi>
Thu, 27 Oct 2016 07:59:34 +0000 (10:59 +0300)
committerMikko Rasa <tdb@tdb.fi>
Thu, 27 Oct 2016 07:59:34 +0000 (10:59 +0300)
It can be useful for non-2D textures which can't be loaded directly from
an image file by the resource collection.

source/texture.cpp
source/texture.h
source/texturecube.cpp
source/texturecube.h

index bda29f05cdd5a2c63f93f8cc334503c1c8e1ef97..97a73d9e6f59c81b3f8ca5f85f55219a02476da7 100644 (file)
@@ -288,6 +288,7 @@ void Texture::Loader::init()
        else
                srgb = false;
 
+       add("external_image", &Loader::external_image);
        add("filter", &Loader::filter);
        add("max_anisotropy", &Loader::max_anisotropy);
        add("generate_mipmap", &Loader::generate_mipmap);
@@ -300,6 +301,15 @@ void Texture::Loader::init()
        add("wrap_t",     &Loader::wrap_t);
 }
 
+void Texture::Loader::external_image(const string &fn)
+{
+       Graphics::Image img;
+       RefPtr<IO::Seekable> io = get_collection().open_raw(fn);
+       img.load_io(*io);
+
+       obj.image(img, srgb);
+}
+
 void Texture::Loader::filter(TextureFilter f)
 {
        obj.set_filter(f);
index 3e050db57f359cc0d3a9f514d828491c6a81cce0..44e126570b741a28e4cdd332523bf3d2b7436c0e 100644 (file)
@@ -81,6 +81,7 @@ protected:
        private:
                void init();
 
+               void external_image(const std::string &);
                void filter(TextureFilter);
                void generate_mipmap(bool);
                void image_data(const std::string &);
index 743eb986247eb95318c98490179b3fdb95683980..3c6f23bd94f05443fd5e872febca8edf19555875 100644 (file)
@@ -1,3 +1,4 @@
+#include <msp/datafile/collection.h>
 #include <msp/gl/extensions/arb_texture_cube_map.h>
 #include <msp/io/memory.h>
 #include <msp/strings/format.h>
@@ -212,11 +213,21 @@ TextureCube::Loader::Loader(TextureCube &t, Collection &c):
 
 void TextureCube::Loader::init()
 {
+       add("external_image", &Loader::external_image);
        add("image_data", &Loader::image_data);
        add("raw_data", &Loader::raw_data);
        add("storage", &Loader::storage);
 }
 
+void TextureCube::Loader::external_image(TextureCubeFace face, const string &fn)
+{
+       Graphics::Image img;
+       RefPtr<IO::Seekable> io = get_collection().open_raw(fn);
+       img.load_io(*io);
+
+       obj.image(face, img, srgb);
+}
+
 void TextureCube::Loader::image_data(TextureCubeFace face, const string &data)
 {
        Graphics::Image img;
index 9adf06978b4d396df7a906bcd881778d9f707ee4..7510a716a6be13dc6f884e4af41fe4d6b13ad143 100644 (file)
@@ -42,6 +42,7 @@ public:
        private:
                void init();
 
+               void external_image(TextureCubeFace, const std::string &);
                void image_data(TextureCubeFace, const std::string &);
                void raw_data(TextureCubeFace, const std::string &);
                void storage(PixelFormat, unsigned);