Results 1 to 3 of 3

Thread: Detect texture bit depth

  1. #1

    Detect texture bit depth

    Hello everyone,

    is there some native function in GLScene to detect an image's bit depth? In particular, I'm interested in checking if the alpha channel is present or not as I noticed that once loaded into memory they are treated as RGBA regardless of their "real" pixel format. To save memory and processing power I would like to do something like this

    Code:
    MaterialName := 'Texture.tga';
    MaterialPath := 'Textures\';
    LibMaterial := MaterialLibrary.Materials.GetLibMaterialByName(MaterialName);
    
    MaterialLibrary.AddTextureMaterial(MaterialName, MaterialPath + MaterialName);
    LibMaterial.Material.Texture.Image.LoadFromFile(MaterialPath + MaterialName);
    
    If ImageOnDiskHasAlpha(MaterialPath + MaterialName) Then
    Begin
       LibMaterial.Material.Texture.TextureFormat := tfRGBA; //Probably superfluous
       LibMaterial.Material.BlendingMode := bmAlphaTest50;
    End
    Else
    Begin
       LibMaterial.Material.Texture.TextureFormat := tfRGB;
    End;
    It was probably asked countless times in the past, but for the life of me I could not find anything. Maybe I was using the wrong search words...

    Thanks in advance!
    Sorry if my english sounds weird: it's not my primary language

  2. #2
    Source code is indeed the best way to gather information: there's a TTGAImage class in TGA.pas which contains the image header's specifications, though I simply ended up renaming all the textures that had an alpha channel as ImageName_.tga and using the file name to decide what texture format to use.
    Sorry if my english sounds weird: it's not my primary language

  3. #3
    So you made a workaround to actual problem. It's ok and often good thing. In this case it's actually even more performance friendly that you don't need to load the header and then decide if it's got alpha or not. It's even a multi-format solution as a bonus, not just TGA. Many of us don't use GLScene either, so knowledge on the matter is limited.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Comodo SSL