]> git.tdb.fi Git - libs/gl.git/blobdiff - source/core/texture.cpp
Require buffer to have storage for mapping
[libs/gl.git] / source / core / texture.cpp
index 5f21229fa8abc2d80c3e0029364bb519bd961bee..0d7a81512e7f73f5c0a49659b4feddc16739c582 100644 (file)
@@ -15,39 +15,14 @@ namespace Msp {
 namespace GL {
 
 Texture::Texture(unsigned t):
-       TextureBackend(t),
-       format(NO_PIXELFORMAT),
-       storage_fmt(format),
-       swizzle(NO_SWIZZLE),
-       use_srgb_format(false),
-       auto_gen_mipmap(false)
+       TextureBackend(t)
 { }
 
 void Texture::set_format(PixelFormat fmt)
 {
        PixelComponents comp = get_components(fmt);
-       PixelComponents st_comp = comp;
-       FormatSwizzle swiz = NO_SWIZZLE;
-       switch(comp)
-       {
-       case LUMINANCE:
-               st_comp = RED;
-               swiz = R_TO_LUMINANCE;
-               break;
-       case LUMINANCE_ALPHA:
-               st_comp = RG;
-               swiz = RG_TO_LUMINANCE_ALPHA;
-               break;
-       case BGR:
-               st_comp = RGB;
-               swiz = RGB_TO_BGR;
-               break;
-       case BGRA:
-               st_comp = RGBA;
-               swiz = RGB_TO_BGR;
-               break;
-       default:;
-       }
+       ComponentSwizzle swiz = get_required_swizzle(comp);
+       PixelComponents st_comp = unswizzle_components(comp, swiz);
 
        PixelFormat st_fmt = make_pixelformat(st_comp, get_component_type(fmt), is_srgb(fmt));
        require_pixelformat(st_fmt);
@@ -59,6 +34,13 @@ void Texture::set_format(PixelFormat fmt)
        swizzle = swiz;
 }
 
+unsigned Texture::count_levels(unsigned size)
+{
+       unsigned n = 0;
+       for(; size; size>>=1, ++n) ;
+       return n;
+}
+
 void Texture::load_image(const string &fn, unsigned lv)
 {
        Graphics::Image img;