From: Mikko Rasa Date: Thu, 27 Oct 2016 07:59:34 +0000 (+0300) Subject: Add a datafile statement to use an external image for a texture X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=93fa68debcd6e416a1b20f43077f7a79525aaecb;p=libs%2Fgl.git Add a datafile statement to use an external image for a texture It can be useful for non-2D textures which can't be loaded directly from an image file by the resource collection. --- diff --git a/source/texture.cpp b/source/texture.cpp index bda29f05..97a73d9e 100644 --- a/source/texture.cpp +++ b/source/texture.cpp @@ -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 = get_collection().open_raw(fn); + img.load_io(*io); + + obj.image(img, srgb); +} + void Texture::Loader::filter(TextureFilter f) { obj.set_filter(f); diff --git a/source/texture.h b/source/texture.h index 3e050db5..44e12657 100644 --- a/source/texture.h +++ b/source/texture.h @@ -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 &); diff --git a/source/texturecube.cpp b/source/texturecube.cpp index 743eb986..3c6f23bd 100644 --- a/source/texturecube.cpp +++ b/source/texturecube.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -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 = 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; diff --git a/source/texturecube.h b/source/texturecube.h index 9adf0697..7510a716 100644 --- a/source/texturecube.h +++ b/source/texturecube.h @@ -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);