]> git.tdb.fi Git - libs/gl.git/blobdiff - source/texture.cpp
Separate abstract pixel compositions from concrete pixel formats
[libs/gl.git] / source / texture.cpp
index 90e3bb17f11de1c318f6670a28ce61a17a13a88b..f0c55999250263f641e546341e22b7545177748b 100644 (file)
@@ -24,7 +24,7 @@ int Texture::swizzle_orders[] =
 Texture::Texture(GLenum t, ResourceManager *m):
        id(0),
        target(t),
-       ifmt(RGB),
+       ifmt(RGB8),
        swizzle(NO_SWIZZLE),
        auto_gen_mipmap(false),
        default_sampler(*this)
@@ -46,41 +46,37 @@ Texture::~Texture()
                glDeleteTextures(1, &id);
 }
 
-DataType Texture::get_alloc_type(PixelFormat fmt)
-{
-       return (get_base_pixelformat(fmt)==DEPTH_COMPONENT ? UNSIGNED_SHORT : UNSIGNED_BYTE);
-}
-
 void Texture::set_internal_format(PixelFormat fmt)
 {
-       swizzle = NO_SWIZZLE;
-       if(ARB_texture_rg && ARB_texture_swizzle)
+       PixelComponents comp = get_components(fmt);
+       FormatSwizzle swiz = NO_SWIZZLE;
+       switch(comp)
        {
-               if(fmt==LUMINANCE)
-               {
-                       fmt = RED;
-                       swizzle = R_TO_LUMINANCE;
-               }
-               else if(fmt==LUMINANCE_ALPHA)
-               {
-                       fmt = RG;
-                       swizzle = RG_TO_LUMINANCE_ALPHA;
-               }
+       case LUMINANCE:
+               comp = RED;
+               swiz = R_TO_LUMINANCE;
+               break;
+       case LUMINANCE_ALPHA:
+               comp = RG;
+               swiz = RG_TO_LUMINANCE_ALPHA;
+               break;
+       default:;
        }
 
-       if(!get_component_size(fmt) && OES_required_internalformat)
-               fmt = get_default_sized_pixelformat(fmt);
-
+       fmt = make_pixelformat(comp, get_component_type(fmt));
        require_pixelformat(fmt);
+       if(swiz!=NO_SWIZZLE)
+               static Require _req(ARB_texture_swizzle);
        ifmt = fmt;
+       swizzle = swiz;
 }
 
-PixelFormat Texture::get_upload_format(PixelFormat fmt) const
+PixelComponents Texture::get_upload_components(PixelComponents comp) const
 {
-       if(fmt==LUMINANCE || fmt==LUMINANCE_ALPHA)
-               return get_base_pixelformat(ifmt);
+       if(comp==LUMINANCE || comp==LUMINANCE_ALPHA)
+               return get_components(ifmt);
        else
-               return fmt;
+               return comp;
 }
 
 void Texture::apply_swizzle()