]> git.tdb.fi Git - libs/gl.git/blobdiff - source/core/texture3d.cpp
Allow repeated storage calls with the same parameters
[libs/gl.git] / source / core / texture3d.cpp
index 03c58d0afdf05e6273cfbbea2892ea2d7e067ca9..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");
 
@@ -94,7 +98,7 @@ void Texture3D::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));
        glTexImage3D(target, level, storage_fmt, width, height, depth, 0, comp, type, data);
 
        allocated |= 1<<level;
@@ -121,7 +125,7 @@ void Texture3D::sub_image(unsigned level, int x, int y, int z, unsigned wd, unsi
        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)
                glTextureSubImage3D(id, level, x, y, z, wd, ht, dp, comp, type, data);
        else
@@ -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);