]> git.tdb.fi Git - libs/gl.git/blobdiff - source/core/texture2d.cpp
Redesign asynchronous buffer uploads
[libs/gl.git] / source / core / texture2d.cpp
index 04ad6ed8d25fe5f61ef7e7893a33d238fcf31df5..7ac1c5ec84f599fcef2285b94e8f5531c3631958 100644 (file)
@@ -6,12 +6,6 @@ using namespace std;
 namespace Msp {
 namespace GL {
 
-Texture2D::Texture2D(ResourceManager *m):
-       Texture2DBackend(m),
-       width(0),
-       height(0)
-{ }
-
 Texture2D::~Texture2D()
 {
        set_manager(0);
@@ -21,7 +15,7 @@ void Texture2D::storage(PixelFormat fmt, unsigned wd, unsigned ht, unsigned lv)
 {
        if(width>0)
        {
-               if(fmt!=format || wd!=width || ht!=height || (lv && lv!=levels))
+               if(fmt!=format || wd!=width || ht!=height || (lv && lv!=n_levels))
                        throw incompatible_data("Texture2D::storage");
                return;
        }
@@ -31,9 +25,9 @@ void Texture2D::storage(PixelFormat fmt, unsigned wd, unsigned ht, unsigned lv)
        set_format(fmt);
        width = wd;
        height = ht;
-       levels = get_n_levels();
+       n_levels = count_levels(max(width, height));
        if(lv>0)
-               levels = min(levels, lv);
+               n_levels = min(n_levels, lv);
 
        allocate();
 }
@@ -44,11 +38,11 @@ void Texture2D::image(unsigned level, const void *data)
        return sub_image(level, 0, 0, size.x, size.y, data);
 }
 
-void Texture2D::sub_image(unsigned level, int x, int y, unsigned wd, unsigned ht, const void *data)
+void Texture2D::sub_image(unsigned level, unsigned x, unsigned y, unsigned wd, unsigned ht, const void *data)
 {
        if(width==0 || height==0)
                throw invalid_operation("Texture2D::sub_image");
-       if(level>=levels)
+       if(level>=n_levels || x>width || x+wd>width || y>height || y+ht>height)
                throw out_of_range("Texture2D::sub_image");
 
        Texture2DBackend::sub_image(level, x, y, wd, ht, data);
@@ -60,13 +54,6 @@ void Texture2D::image(const Graphics::Image &img, unsigned lv)
        image(0, img.get_pixels());
 }
 
-unsigned Texture2D::get_n_levels() const
-{
-       unsigned n = 0;
-       for(unsigned s=max(width, height); s; s>>=1, ++n) ;
-       return n;
-}
-
 LinAl::Vector<unsigned, 2> Texture2D::get_level_size(unsigned level) const
 {
        unsigned w = width>>level;
@@ -80,16 +67,6 @@ LinAl::Vector<unsigned, 2> Texture2D::get_level_size(unsigned level) const
        return LinAl::Vector<unsigned, 2>(w, h);
 }
 
-Resource::AsyncLoader *Texture2D::load(IO::Seekable &io, const Resources *)
-{
-       return create_async_loader(io);
-}
-
-uint64_t Texture2D::get_data_size() const
-{
-       return id ? width*height*get_pixel_size(format) : 0;
-}
-
 
 Texture2D::Loader::Loader(Texture2D &t):
        DataFile::DerivedObjectLoader<Texture2D, Texture::Loader>(t)
@@ -105,22 +82,10 @@ Texture2D::Loader::Loader(Texture2D &t, Collection &c):
 
 void Texture2D::Loader::init()
 {
-       add("raw_data", &Loader::raw_data);
        add("storage", &Loader::storage);
        add("storage", &Loader::storage_levels);
 }
 
-void Texture2D::Loader::raw_data(const string &data)
-{
-       if(obj.manager)
-       {
-               obj.set_manager(0);
-               if(!obj.id)
-                       obj.generate_id();
-       }
-       obj.image(0, data.data());
-}
-
 void Texture2D::Loader::storage(PixelFormat fmt, unsigned w, unsigned h)
 {
        obj.storage(fmt, w, h);