]> git.tdb.fi Git - libs/gl.git/blobdiff - source/core/texture1d.cpp
Refactor get_level_size in various texture classes
[libs/gl.git] / source / core / texture1d.cpp
index 742857be725b4ed205b369c43d823f5b0812af14..71c736f04da4ecb7971d22461434169445614f6b 100644 (file)
@@ -22,7 +22,11 @@ Texture1D::Texture1D():
 void Texture1D::storage(PixelFormat fmt, unsigned wd, unsigned lv)
 {
        if(width>0)
-               throw invalid_operation("Texture1D::storage");
+       {
+               if(fmt!=format || wd!=width || (lv && lv!=levels))
+                       throw incompatible_data("Texture1D::storage");
+               return;
+       }
        if(wd==0)
                throw invalid_argument("Texture1D::storage");
 
@@ -60,6 +64,8 @@ void Texture1D::image(unsigned level, const void *data)
 {
        if(width==0)
                throw invalid_operation("Texture1D::image");
+       if(level>=levels)
+               throw out_of_range("Texture1D::image");
 
        unsigned w = get_level_size(level);
 
@@ -75,7 +81,7 @@ void Texture1D::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));
        glTexImage1D(target, level, storage_fmt, w, 0, comp, type, data);
 
        allocated |= 1<<level;
@@ -96,13 +102,15 @@ void Texture1D::image(unsigned level, PixelComponents comp, DataType type, const
 void Texture1D::sub_image(unsigned level, int x, unsigned wd, const void *data)
 {
        if(width==0)
-               throw invalid_operation("Texture3D::image");
+               throw invalid_operation("Texture1D::sub_image");
+       if(level>=levels)
+               throw out_of_range("Texture1D::sub_image");
 
        Conditional<BindRestore> _bind(!ARB_direct_state_access, this);
        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)
                glTextureSubImage1D(id, level, x, wd, comp, type, data);
        else
@@ -126,10 +134,7 @@ void Texture1D::image(const Graphics::Image &img, unsigned lv)
 
        unsigned w = img.get_width();
        PixelFormat fmt = pixelformat_from_image(img);
-       if(width==0)
-               storage(make_pixelformat(get_components(fmt), get_component_type(fmt), use_srgb_format), w, lv);
-       else if(w!=width)
-               throw incompatible_data("Texture1D::image");
+       storage(make_pixelformat(get_components(fmt), get_component_type(fmt), use_srgb_format), w, lv);
 
        image(0, img.get_pixels());
 }