]> git.tdb.fi Git - libs/gl.git/blobdiff - source/texture3d.cpp
Separate abstract pixel compositions from concrete pixel formats
[libs/gl.git] / source / texture3d.cpp
index 5c09f1ea4249919bf526703365c730c48b11d4e7..010609a8e7a098c092524366990a9057efba1986 100644 (file)
@@ -69,13 +69,10 @@ void Texture3D::allocate(unsigned level)
                allocated |= (1<<levels)-1;
        }
        else
-       {
-               PixelFormat base_fmt = get_base_pixelformat(ifmt);
-               image(level, base_fmt, get_alloc_type(base_fmt), 0);
-       }
+               image(level, get_components(ifmt), get_component_type(ifmt), 0);
 }
 
-void Texture3D::image(unsigned level, PixelFormat fmt, DataType type, const void *data)
+void Texture3D::image(unsigned level, PixelComponents comp, DataType type, const void *data)
 {
        if(width==0 || height==0 || depth==0)
                throw invalid_operation("Texture3D::image");
@@ -86,7 +83,7 @@ void Texture3D::image(unsigned level, PixelFormat fmt, DataType type, const void
        get_level_size(level, w, h, d);
 
        if(ARB_texture_storage)
-               return sub_image(level, 0, 0, 0, w, h, d, fmt, type, data);
+               return sub_image(level, 0, 0, 0, w, h, d, comp, type, data);
 
        BindRestore _bind(this);
 
@@ -95,7 +92,7 @@ void Texture3D::image(unsigned level, PixelFormat fmt, DataType type, const void
                glTexParameteri(target, GL_TEXTURE_MAX_LEVEL, levels-1);
                apply_swizzle();
        }
-       glTexImage3D(target, level, ifmt, width, height, depth, 0, get_upload_format(fmt), type, data);
+       glTexImage3D(target, level, ifmt, width, height, depth, 0, get_upload_components(comp), type, data);
 
        allocated |= 1<<level;
        if(auto_gen_mipmap && level==0)
@@ -105,7 +102,7 @@ void Texture3D::image(unsigned level, PixelFormat fmt, DataType type, const void
        }
 }
 
-void Texture3D::sub_image(unsigned level, int x, int y, int z, unsigned wd, unsigned ht, unsigned dp, PixelFormat fmt, DataType type, const void *data)
+void Texture3D::sub_image(unsigned level, int x, int y, int z, unsigned wd, unsigned ht, unsigned dp, PixelComponents comp, DataType type, const void *data)
 {
        if(width==0 || height==0 || depth==0)
                throw invalid_operation("Texture3D::image");
@@ -113,11 +110,11 @@ void Texture3D::sub_image(unsigned level, int x, int y, int z, unsigned wd, unsi
        Conditional<BindRestore> _bind(!ARB_direct_state_access, this);
        allocate(level);
 
-       fmt = get_upload_format(fmt);
+       comp = get_upload_components(comp);
        if(ARB_direct_state_access)
-               glTextureSubImage3D(id, level, x, y, z, wd, ht, dp, fmt, type, data);
+               glTextureSubImage3D(id, level, x, y, z, wd, ht, dp, comp, type, data);
        else
-               glTexSubImage3D(target, level, x, y, z, wd, ht, dp, fmt, type, data);
+               glTexSubImage3D(target, level, x, y, z, wd, ht, dp, comp, type, data);
 
        if(auto_gen_mipmap && level==0)
                generate_mipmap();
@@ -144,16 +141,18 @@ void Texture3D::image(const Graphics::Image &img, unsigned lv, bool srgb)
                h = w;
        }
 
-       PixelFormat fmt = pixelformat_from_graphics(img.get_format());
+       PixelFormat fmt = pixelformat_from_image(img);
+       PixelComponents comp = get_components(fmt);
+       DataType type = get_component_type(fmt);
        if(width==0)
-               storage(storage_pixelformat_from_graphics(img.get_format(), srgb), w, h, d, lv);
+               storage(make_pixelformat(comp, type, srgb), w, h, d, lv);
        else if(w!=width || h!=height || d!=depth)
                throw incompatible_data("Texture3D::load_image");
 
        PixelStore pstore = PixelStore::from_image(img);
        BindRestore _bind_ps(pstore);
 
-       image(0, fmt, UNSIGNED_BYTE, img.get_data());
+       image(0, comp, type, img.get_data());
 }
 
 unsigned Texture3D::get_n_levels() const
@@ -208,7 +207,7 @@ void Texture3D::Loader::init()
 
 void Texture3D::Loader::raw_data(const string &data)
 {
-       obj.image(0, get_base_pixelformat(obj.ifmt), UNSIGNED_BYTE, data.data());
+       obj.image(0, get_components(obj.ifmt), get_component_type(obj.ifmt), data.data());
 }
 
 void Texture3D::Loader::storage(PixelFormat fmt, unsigned w, unsigned h, unsigned d)