]> git.tdb.fi Git - libs/gl.git/blobdiff - source/texture1d.cpp
Separate abstract pixel compositions from concrete pixel formats
[libs/gl.git] / source / texture1d.cpp
index b50f8cf444c0c9fb1435ce97e756ffc1330b59c2..24266150672a90fab1f1a5acd4fd8cb4d16f849a 100644 (file)
@@ -53,13 +53,10 @@ void Texture1D::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 Texture1D::image(unsigned level, PixelFormat fmt, DataType type, const void *data)
+void Texture1D::image(unsigned level, PixelComponents comp, DataType type, const void *data)
 {
        if(width==0)
                throw invalid_operation("Texture1D::image");
@@ -67,7 +64,7 @@ void Texture1D::image(unsigned level, PixelFormat fmt, DataType type, const void
        unsigned w = get_level_size(level);
 
        if(ARB_texture_storage)
-               return sub_image(level, 0, w, fmt, type, data);
+               return sub_image(level, 0, w, comp, type, data);
 
        BindRestore _bind(this);
 
@@ -76,7 +73,7 @@ void Texture1D::image(unsigned level, PixelFormat fmt, DataType type, const void
                glTexParameteri(target, GL_TEXTURE_MAX_LEVEL, levels-1);
                apply_swizzle();
        }
-       glTexImage1D(target, level, ifmt, w, 0, get_upload_format(fmt), type, data);
+       glTexImage1D(target, level, ifmt, w, 0, get_upload_components(comp), type, data);
 
        allocated |= 1<<level;
        if(auto_gen_mipmap && level==0)
@@ -86,7 +83,7 @@ void Texture1D::image(unsigned level, PixelFormat fmt, DataType type, const void
        }
 }
 
-void Texture1D::sub_image(unsigned level, int x, unsigned wd, PixelFormat fmt, DataType type, const void *data)
+void Texture1D::sub_image(unsigned level, int x, unsigned wd, PixelComponents comp, DataType type, const void *data)
 {
        if(width==0)
                throw invalid_operation("Texture3D::image");
@@ -94,11 +91,11 @@ void Texture1D::sub_image(unsigned level, int x, unsigned wd, PixelFormat fmt, D
        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)
-               glTextureSubImage1D(id, level, x, wd, fmt, type, data);
+               glTextureSubImage1D(id, level, x, wd, comp, type, data);
        else
-               glTexSubImage1D(target, level, x, wd, fmt, type, data);
+               glTexSubImage1D(target, level, x, wd, comp, type, data);
 
        if(auto_gen_mipmap && level==0)
                generate_mipmap();
@@ -110,13 +107,15 @@ void Texture1D::image(const Graphics::Image &img, unsigned lv, bool srgb)
                throw incompatible_data("Texture1D::image");
 
        unsigned w = img.get_width();
-       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, lv);
+               storage(make_pixelformat(comp, type, srgb), w, lv);
        else if(w!=width)
                throw incompatible_data("Texture1D::image");
 
-       image(0, fmt, UNSIGNED_BYTE, img.get_data());
+       image(0, comp, type, img.get_data());
 }
 
 unsigned Texture1D::get_n_levels() const
@@ -158,7 +157,7 @@ void Texture1D::Loader::init()
 
 void Texture1D::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 Texture1D::Loader::storage(PixelFormat fmt, unsigned w)