]> git.tdb.fi Git - libs/gl.git/blobdiff - source/texture2d.cpp
Include the local gl.h in types.h to make it work on win32
[libs/gl.git] / source / texture2d.cpp
index 455c7314cb4d2a04676b1ac6e6612884e95ef212..8a93d031b6fd36a781ab5916e7019ba6036b0388 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,33 @@ 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);
+       add("raw_data", &Loader::raw_data);
+       add("storage", &Loader::storage);
+}
+
+void Texture2D::Loader::image_data(const string &data)
+{
+       Image img;
+       img.load_lump(data.data(), data.size());
+
+       static_cast<Texture2D &>(tex).image(img);
+}
+
+void Texture2D::Loader::raw_data(const string &data)
+{
+       Texture2D &t2d=static_cast<Texture2D &>(tex);;
+       t2d.image(0, t2d.ifmt, GL_UNSIGNED_BYTE, data.data());
+}
+
+void Texture2D::Loader::storage(PixelFormat fmt, unsigned w, unsigned h, unsigned b)
+{
+       static_cast<Texture2D &>(tex).storage(fmt, w, h, b);
+}
+
 } // namespace GL
 } // namespace Msp