]> git.tdb.fi Git - libs/gl.git/commitdiff
Allow repeated storage calls with the same parameters
authorMikko Rasa <tdb@tdb.fi>
Sun, 18 Apr 2021 18:59:46 +0000 (21:59 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sun, 18 Apr 2021 19:11:38 +0000 (22:11 +0300)
source/core/buffer.cpp
source/core/texture1d.cpp
source/core/texture2d.cpp
source/core/texture3d.cpp
source/core/texturecube.cpp

index 98625b813bdfd9a626d8be87f52e6a2d7db228d6..17e833d71dfee347e7f3b46c885bc674aa0de864 100644 (file)
@@ -49,7 +49,11 @@ void Buffer::require_buffer_type(BufferType type)
 void Buffer::storage(unsigned sz)
 {
        if(size>0)
-               throw invalid_operation("Buffer::storage");
+       {
+               if(sz!=size)
+                       throw incompatible_data("Buffer::storage");
+               return;
+       }
        if(sz==0)
                throw invalid_argument("Buffer::storage");
 
index 1e90b6f7264d56d1f37c32afc9255157eca743b3..d472527c92322f4d05b0fe39640f7f91905133a9 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");
 
@@ -126,10 +130,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());
 }
index 6e7d97202f341cc12e2a76d9e94b92f840c3ff94..b3caf509ec3108b1d418c8298186d1e795d2cb03 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");
 
@@ -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);
index 1681f83c6f528b949be627adb9fddf311556806a..a268857d4996cd9bc08d98d9d5c8918bc7d25a3c 100644 (file)
@@ -36,7 +36,11 @@ Texture3D::Texture3D():
 void Texture3D::storage(PixelFormat fmt, unsigned wd, unsigned ht, unsigned dp, unsigned lv)
 {
        if(width>0)
-               throw invalid_operation("Texture3D::storage");
+       {
+               if(fmt!=format || wd!=width || ht!=height || dp!=depth || (lv && lv!=levels))
+                       throw incompatible_data("Texture3D::storage");
+               return;
+       }
        if(wd==0 || ht==0 || dp==0)
                throw invalid_argument("Texture3D::storage");
 
@@ -149,10 +153,7 @@ void Texture3D::image(const Graphics::Image &img, unsigned lv)
        h = w;
 
        PixelFormat fmt = pixelformat_from_image(img);
-       if(width==0)
-               storage(make_pixelformat(get_components(fmt), get_component_type(fmt), use_srgb_format), w, h, d, lv);
-       else if(w!=width || h!=height || d!=depth)
-               throw incompatible_data("Texture3D::load_image");
+       storage(make_pixelformat(get_components(fmt), get_component_type(fmt), use_srgb_format), w, h, d, lv);
 
        PixelStore pstore = PixelStore::from_image(img);
        BindRestore _bind_ps(pstore);
index 3e0b9fc14d2b430cd16040f743294b0aae502419..1c6c4962e46a1a3eb4b0c8817beed3dcfb726b9f 100644 (file)
@@ -54,7 +54,11 @@ TextureCube::TextureCube():
 void TextureCube::storage(PixelFormat fmt, unsigned sz, unsigned lv)
 {
        if(size>0)
-               throw invalid_operation("TextureCube::storage");
+       {
+               if(fmt!=format || sz!=size || (lv && lv!=levels))
+                       throw incompatible_data("TextureCube::storage");
+               return;
+       }
        if(sz==0)
                throw invalid_argument("TextureCube::storage");
 
@@ -169,17 +173,12 @@ void TextureCube::image(TextureCubeFace face, const Graphics::Image &img)
 {
        unsigned w = img.get_width();
        unsigned h = img.get_height();
-       PixelFormat fmt = pixelformat_from_image(img);
-       if(size==0)
-       {
-               if(w!=h)
-                       throw incompatible_data("TextureCube::image");
-
-               storage(make_pixelformat(get_components(fmt), get_component_type(fmt), use_srgb_format), w);
-       }
-       else if(w!=size || h!=size)
+       if(w!=h)
                throw incompatible_data("TextureCube::image");
 
+       PixelFormat fmt = pixelformat_from_image(img);
+       storage(make_pixelformat(get_components(fmt), get_component_type(fmt), use_srgb_format), w);
+
        PixelStore pstore = PixelStore::from_image(img);
        BindRestore _bind_ps(pstore);