]> git.tdb.fi Git - libs/gl.git/blobdiff - source/texture.cpp
Require texture data to be uploaded in a format matching the storage
[libs/gl.git] / source / texture.cpp
index cf32ca301cab4bf10bc513ad65de9546c1b757e4..b747a2a6b0d7001b3d06e7a2811f91e93f075e78 100644 (file)
@@ -25,7 +25,8 @@ int Texture::swizzle_orders[] =
 Texture::Texture(GLenum t, ResourceManager *m):
        id(0),
        target(t),
-       ifmt(RGB8),
+       format(RGB8),
+       storage_fmt(RGB8),
        swizzle(NO_SWIZZLE),
        auto_gen_mipmap(false),
        default_sampler(*this)
@@ -47,45 +48,40 @@ Texture::~Texture()
                glDeleteTextures(1, &id);
 }
 
-void Texture::set_internal_format(PixelFormat fmt)
+void Texture::set_format(PixelFormat fmt)
 {
        PixelComponents comp = get_components(fmt);
+       PixelComponents st_comp = comp;
        FormatSwizzle swiz = NO_SWIZZLE;
        switch(comp)
        {
        case LUMINANCE:
-               comp = RED;
+               st_comp = RED;
                swiz = R_TO_LUMINANCE;
                break;
        case LUMINANCE_ALPHA:
-               comp = RG;
+               st_comp = RG;
                swiz = RG_TO_LUMINANCE_ALPHA;
                break;
        case BGR:
-               comp = RGB;
+               st_comp = RGB;
                swiz = RGB_TO_BGR;
                break;
        case BGRA:
-               comp = RGBA;
+               st_comp = RGBA;
                swiz = RGB_TO_BGR;
                break;
        default:;
        }
 
-       fmt = make_pixelformat(comp, get_component_type(fmt));
-       require_pixelformat(fmt);
+       PixelFormat st_fmt = make_pixelformat(st_comp, get_component_type(fmt));
+       require_pixelformat(st_fmt);
        if(swiz!=NO_SWIZZLE)
                static Require _req(ARB_texture_swizzle);
-       ifmt = fmt;
-       swizzle = swiz;
-}
 
-PixelComponents Texture::get_upload_components(PixelComponents comp) const
-{
-       if(comp==LUMINANCE || comp==LUMINANCE_ALPHA || comp==BGR || comp==BGRA)
-               return get_components(ifmt);
-       else
-               return comp;
+       format = fmt;
+       storage_fmt = st_fmt;
+       swizzle = swiz;
 }
 
 void Texture::apply_swizzle()