From: Mikko Rasa Date: Sun, 18 Apr 2021 18:59:46 +0000 (+0300) Subject: Allow repeated storage calls with the same parameters X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=4ae2ffa3057af9524a84ba322c0db32d6fcae8f2;p=libs%2Fgl.git Allow repeated storage calls with the same parameters --- diff --git a/source/core/buffer.cpp b/source/core/buffer.cpp index 98625b81..17e833d7 100644 --- a/source/core/buffer.cpp +++ b/source/core/buffer.cpp @@ -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"); diff --git a/source/core/texture1d.cpp b/source/core/texture1d.cpp index 1e90b6f7..d472527c 100644 --- a/source/core/texture1d.cpp +++ b/source/core/texture1d.cpp @@ -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()); } diff --git a/source/core/texture2d.cpp b/source/core/texture2d.cpp index 6e7d9720..b3caf509 100644 --- a/source/core/texture2d.cpp +++ b/source/core/texture2d.cpp @@ -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); diff --git a/source/core/texture3d.cpp b/source/core/texture3d.cpp index 1681f83c..a268857d 100644 --- a/source/core/texture3d.cpp +++ b/source/core/texture3d.cpp @@ -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); diff --git a/source/core/texturecube.cpp b/source/core/texturecube.cpp index 3e0b9fc1..1c6c4962 100644 --- a/source/core/texturecube.cpp +++ b/source/core/texturecube.cpp @@ -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);