]> git.tdb.fi Git - libs/gl.git/blobdiff - source/core/texture2d.cpp
Remove default sampler from Texture
[libs/gl.git] / source / core / texture2d.cpp
index 0e76128c7bc5666da5828f11fe98f5398ecaf380..1e9ec90344e242608caa55501268a08775a54aa2 100644 (file)
@@ -50,7 +50,11 @@ Texture2D::~Texture2D()
 void Texture2D::storage(PixelFormat fmt, unsigned wd, unsigned ht, unsigned lv)
 {
        if(width>0)
-               throw invalid_operation("Texture2D::storage");
+       {
+               if(fmt!=format || wd!=width || ht!=height || (lv && lv!=levels))
+                       throw incompatible_data("Texture2D::storage");
+               return;
+       }
        if(wd==0 || ht==0)
                throw invalid_argument("Texture2D::storage");
 
@@ -106,7 +110,7 @@ void Texture2D::image(unsigned level, const void *data)
        }
 
        PixelComponents comp = get_components(storage_fmt);
-       DataType type = get_component_type(storage_fmt);
+       GLenum type = get_gl_type(get_component_type(storage_fmt));
        glTexImage2D(target, level, storage_fmt, w, h, 0, comp, type, data);
 
        allocated |= 1<<level;
@@ -133,7 +137,7 @@ void Texture2D::sub_image(unsigned level, int x, int y, unsigned wd, unsigned ht
        allocate(level);
 
        PixelComponents comp = get_components(storage_fmt);
-       DataType type = get_component_type(storage_fmt);
+       GLenum type = get_gl_type(get_component_type(storage_fmt));
        if(ARB_direct_state_access)
                glTextureSubImage2D(id, level, x, y, wd, ht, comp, type, data);
        else
@@ -160,10 +164,7 @@ void Texture2D::image(const Graphics::Image &img, unsigned lv, bool from_buffer)
        unsigned w = img.get_width();
        unsigned h = img.get_height();
        PixelFormat fmt = pixelformat_from_image(img);
-       if(width==0)
-               storage(make_pixelformat(get_components(fmt), get_component_type(fmt), use_srgb_format), w, h, lv);
-       else if(w!=width || h!=height || (lv && lv!=levels))
-               throw incompatible_data("Texture2D::image");
+       storage(make_pixelformat(get_components(fmt), get_component_type(fmt), use_srgb_format), w, h, lv);
 
        PixelStore pstore = PixelStore::from_image(img);
        BindRestore _bind_ps(pstore);
@@ -205,7 +206,6 @@ void Texture2D::unload()
        glDeleteTextures(1, &id);
        id = 0;
        allocated = 0;
-       default_sampler.unload();
 }
 
 
@@ -230,6 +230,12 @@ void Texture2D::Loader::init()
 
 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());
 }
 
@@ -247,7 +253,6 @@ void Texture2D::Loader::storage_levels(PixelFormat fmt, unsigned w, unsigned h,
 Texture2D::AsyncLoader::AsyncLoader(Texture2D &t, IO::Seekable &i):
        texture(t),
        io(i),
-       pixel_buffer(PIXEL_UNPACK_BUFFER),
        mapped_address(0),
        img_loader(Graphics::ImageLoader::open_io(io)),
        phase(0)
@@ -290,12 +295,7 @@ bool Texture2D::AsyncLoader::process()
                }
 
                if(!texture.id)
-               {
-                       if(ARB_direct_state_access)
-                               glCreateTextures(texture.target, 1, &texture.id);
-                       else
-                               glGenTextures(1, &texture.id);
-               }
+                       texture.generate_id();
                texture.image(image, 0, true);
        }