]> git.tdb.fi Git - libs/gl.git/blobdiff - source/core/texturecube.cpp
Store implementation limits in a central struct
[libs/gl.git] / source / core / texturecube.cpp
index 6ec3662523dea02903e024bb9113b91125e4b711..01820fa8766be6afa5235419c5da9d63062a6388 100644 (file)
@@ -1,4 +1,5 @@
 #include <msp/datafile/collection.h>
+#include <msp/gl/extensions/arb_seamless_cube_map.h>
 #include <msp/gl/extensions/arb_texture_cube_map.h>
 #include <msp/gl/extensions/arb_texture_storage.h>
 #include <msp/io/memory.h>
@@ -49,12 +50,18 @@ TextureCube::TextureCube():
        allocated(0)
 {
        static Require _req(ARB_texture_cube_map);
+       if(ARB_seamless_cube_map)
+               glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS);
 }
 
 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");
 
@@ -79,7 +86,7 @@ void TextureCube::allocate(unsigned level)
                BindRestore _bind(this);
                glTexStorage2D(target, levels, storage_fmt, size, size);
                apply_swizzle();
-               allocated |= (1<<levels)-1;
+               allocated |= (64<<levels)-1;
        }
        else
        {
@@ -109,7 +116,7 @@ void TextureCube::image(TextureCubeFace face, 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(face, level, storage_fmt, s, s, 0, comp, type, data);
 
        if(level==0)
@@ -151,7 +158,7 @@ void TextureCube::sub_image(TextureCubeFace face, unsigned level, int x, int y,
        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));
        glTexSubImage2D(face, level, x, y, wd, ht, comp, type, data);
 
        if(auto_gen_mipmap && level==0)
@@ -169,17 +176,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);