]> git.tdb.fi Git - libs/gl.git/blobdiff - source/texture2d.cpp
Move Image to mspgbase
[libs/gl.git] / source / texture2d.cpp
index 455c7314cb4d2a04676b1ac6e6612884e95ef212..b8f2f26b7076320f78f5ef792dc69a9acd7e1b82 100644 (file)
@@ -6,13 +6,10 @@ Distributed under the LGPL
 */
 
 #include "except.h"
-#include "ilwrap.h"
 #include "texture2d.h"
 
 using namespace std;
 
-#include <iostream>
-
 namespace Msp {
 namespace GL {
 
@@ -37,7 +34,7 @@ void Texture2D::storage(PixelFormat fmt, sizei wd, sizei ht, int brd)
        border=brd;
 }
 
-void Texture2D::image(int level, PixelFormat fmt, GLenum type, const void *data)
+void Texture2D::image(int level, PixelFormat fmt, DataType type, const void *data)
 {
        if(width==0)
                throw InvalidState("Texture storage has not been specified");
@@ -47,7 +44,7 @@ void Texture2D::image(int level, PixelFormat fmt, GLenum type, const void *data)
        glTexImage2D(target, level, ifmt, width, height, border, fmt, type, data);
 }
 
-void Texture2D::sub_image(int level, int x, int y, sizei wd, sizei ht, PixelFormat fmt, GLenum type, const void *data)
+void Texture2D::sub_image(int level, int x, int y, sizei wd, sizei ht, PixelFormat fmt, DataType type, const void *data)
 {
        if(width==0)
                throw InvalidState("Texture storage has not been specified");
@@ -59,18 +56,51 @@ 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);
+       Graphics::Image img;
+       img.load_file(fn);
+
+       image(img);
+}
 
+void Texture2D::image(const Graphics::Image &img)
+{
        unsigned w=img.get_width();
        unsigned h=img.get_height();
-       PixelFormat fmt=img.get_format();
+       PixelFormat fmt=pixelformat_from_graphics(img.get_format());
        if(width==0)
                storage(fmt, w, h, 0);
        else if(w!=width || h!=height)
                throw IncompatibleData("Image does not match texture storage");
 
-       image(0, fmt, GL_UNSIGNED_BYTE, img.get_data());
+       image(0, fmt, 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)
+{
+       Graphics::Image img;
+       img.load_memory(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, 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