PDA

View Full Version : Detect texture bit depth



Lucas
09-11-2014, 05:13 PM
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



MaterialName := 'Texture.tga';
MaterialPath := 'Textures\';
LibMaterial := MaterialLibrary.Materials.GetLibMaterialByName(Mat erialName);

MaterialLibrary.AddTextureMaterial(MaterialName, MaterialPath + MaterialName);
LibMaterial.Material.Texture.Image.LoadFromFile(Ma terialPath + 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! ;)

Lucas
03-12-2014, 07:56 PM
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.

User137
11-12-2014, 02:23 PM
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.