CrystalSpace

Public API Reference

csgfx/textureformatstrings.h

Go to the documentation of this file.
00001 /*
00002     Copyright (C) 2006 by Jorrit Tyberghein
00003 
00004     This library is free software; you can redistribute it and/or
00005     modify it under the terms of the GNU Library General Public
00006     License as published by the Free Software Foundation; either
00007     version 2 of the License, or (at your option) any later version.
00008 
00009     This library is distributed in the hope that it will be useful,
00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012     Library General Public License for more details.
00013 
00014     You should have received a copy of the GNU Library General Public
00015     License along with this library; if not, write to the Free
00016     Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00017 */
00018 
00019 #ifndef __CS_CSGFX_TEXTUREFORMATSTRINGS_H__
00020 #define __CS_CSGFX_TEXTUREFORMATSTRINGS_H__
00021 
00022 #include "csextern.h"
00023 
00024 #include "csutil/csstring.h"
00025 
00030 namespace CS
00031 {
00126   class CS_CRYSTALSPACE_EXPORT StructuredTextureFormat
00127   {
00128   public:
00130     enum TextureFormat
00131     {
00133       Invalid = '-',
00135       Integer = 'i',
00137       Float = 'f',
00139       Special = '*'
00140     };
00141   private:
00142     uint64 coded_components;
00143     TextureFormat format;
00144     csString special;
00145 
00146   public:
00148     StructuredTextureFormat ();
00149 
00153     void SetSpecial (const char* special)
00154     {
00155       StructuredTextureFormat::special = special;
00156       format = Special;
00157     }
00158 
00166     bool AddComponent (char cmp, int size);
00167 
00171     void SetFormat (TextureFormat format)
00172     {
00173       StructuredTextureFormat::format = format;
00174     }
00175 
00180     void FixSizes (int size);
00181 
00186     csString GetCanonical ();
00187 
00188     bool operator== (const StructuredTextureFormat& other) const
00189     {
00190       if (coded_components != other.coded_components) return false;
00191       if (format != other.format) return false;
00192       return (special == other.special);
00193     }
00194 
00196     bool IsValid () { return format != Invalid; }
00197 
00202     int GetComponentCount () const
00203     {
00204       if ((format == Special) || (format == Invalid)) return 0;
00205       int n = 0;
00206       uint64 comp = coded_components;
00207       while (comp != 0) 
00208       {
00209         comp >>= 16;
00210         n++;
00211       }
00212       return n;
00213     }
00214 
00218     char GetComponent (int n) const
00219     {
00220       int num = GetComponentCount ();
00221       if ((n < 0) || (n >= num)) return 0;
00222       return (coded_components >> (16 * (num - 1 - n) + 8)) & 255;
00223     }
00224 
00233     char GetComponentSize (int n) const
00234     {
00235       int num = GetComponentCount ();
00236       if ((n < 0) || (n >= num)) return 0;
00237       return (coded_components >> (16 * (num - 1 - n))) & 255;
00238     }
00239 
00244     TextureFormat GetFormat() const { return format; }
00245 
00247     const char* GetSpecial() const
00248     {
00249       if (format != Special) return 0;
00250       return special;
00251     }
00252 
00257     enum
00258     {
00260       compR = 0x01,
00262       compG = 0x02,
00264       compB = 0x04,
00266       compA = 0x08,
00268       compX = 0x10,
00270       compL = 0x20,
00272       compD = 0x40,
00274       compS = 0x80,
00275 
00277       compRGB = compR | compB | compG,
00279       compRGBA = compR | compB | compG | compA,
00281       compLumA = compL | compA,
00283       compDepthStencil = compD | compS,
00284 
00286       compUnknown = 0x80000000
00287     };
00288 
00306     uint GetComponentMask () const;
00307   };
00308 
00312   class CS_CRYSTALSPACE_EXPORT TextureFormatStrings
00313   {
00314   public:
00319     static csString ConvertCanonical (const char* in);
00320 
00325     static StructuredTextureFormat ConvertStructured (const char* in);
00326   };
00327 }
00328 
00331 #endif // __CS_CSGFX_TEXTUREFORMATSTRINGS_H__
00332 

Generated for Crystal Space 1.2.1 by doxygen 1.5.3