]> git.tdb.fi Git - libs/gl.git/blobdiff - source/texture2d.cpp
Support embedding textures in datafiles
[libs/gl.git] / source / texture2d.cpp
index 455c7314cb4d2a04676b1ac6e6612884e95ef212..fbf86a43b77fe79dc2f81120a98b516aeea05b85 100644 (file)
@@ -11,8 +11,6 @@ Distributed under the LGPL
 
 using namespace std;
 
-#include <iostream>
-
 namespace Msp {
 namespace GL {
 
@@ -60,8 +58,13 @@ void Texture2D::sub_image(int level, int x, int y, sizei wd, sizei ht, PixelForm
 void Texture2D::load_image(const string &fn)
 {
        Image img;
-       img.load(fn);
+       img.load_file(fn);
+
+       image(img);
+}
 
+void Texture2D::image(const Image &img)
+{
        unsigned w=img.get_width();
        unsigned h=img.get_height();
        PixelFormat fmt=img.get_format();
@@ -73,5 +76,20 @@ void Texture2D::load_image(const string &fn)
        image(0, fmt, GL_UNSIGNED_BYTE, img.get_data());
 }
 
+
+Texture2D::Loader::Loader(Texture2D &t):
+       Texture::Loader(t)
+{
+       add("image_data", &Loader::image_data);
+}
+
+void Texture2D::Loader::image_data(const string &data)
+{
+       Image img;
+       img.load_lump(data.data(), data.size());
+
+       static_cast<Texture2D &>(tex).image(img);
+}
+
 } // namespace GL
 } // namespace Msp