00001
00002
00003 #ifndef _PIXEL_FORMAT_H_
00004 #define _PIXEL_FORMAT_H_
00005
00006 #include <EngineConfig.h>
00007 #include <core/Types.h>
00008
00009 namespace render
00010 {
00011 class Color;
00012 }
00013
00014 namespace resource
00015 {
00016
00017 enum PixelFormat
00018 {
00019 PF_UNKNOWN = 0,
00020 PF_L8 = 1,
00021 PF_BYTE_L = PF_L8,
00022 PF_L16 = 2,
00023 PF_SHORT_L = PF_L16,
00024 PF_A8 = 3,
00025 PF_BYTE_A = PF_A8,
00026 PF_A4L4 = 4,
00027 PF_BYTE_LA = 5,
00028 PF_R5G6B5 = 6,
00029 PF_B5G6R5 = 7,
00030 PF_R3G3B2 = 31,
00031 PF_A4R4G4B4 = 8,
00032 PF_A1R5G5B5 = 9,
00033 PF_R8G8B8 = 10,
00034 PF_B8G8R8 = 11,
00035 PF_A8R8G8B8 = 12,
00036 PF_A8B8G8R8 = 13,
00037 PF_B8G8R8A8 = 14,
00038 PF_R8G8B8A8 = 28,
00039 PF_X8R8G8B8 = 26,
00040 PF_X8B8G8R8 = 27,
00041 #if GAME_ARCHITECTURE_ENDIAN == ENDIAN_BIG
00042 PF_BYTE_RGB = PF_R8G8B8,
00043 PF_BYTE_BGR = PF_B8G8R8,
00044 PF_BYTE_BGRA = PF_B8G8R8A8,
00045 PF_BYTE_RGBA = PF_R8G8B8A8,
00046 #else
00047 PF_BYTE_RGB = PF_B8G8R8,
00048 PF_BYTE_BGR = PF_R8G8B8,
00049 PF_BYTE_BGRA = PF_A8R8G8B8,
00050 PF_BYTE_RGBA = PF_A8B8G8R8,
00051 #endif
00052 PF_A2R10G10B10 = 15,
00053 PF_A2B10G10R10 = 16,
00054 PF_DXT1 = 17,
00055 PF_DXT2 = 18,
00056 PF_DXT3 = 19,
00057 PF_DXT4 = 20,
00058 PF_DXT5 = 21,
00059 PF_FLOAT16_R = 32,
00060 PF_FLOAT16_RGB = 22,
00061 PF_FLOAT16_RGBA = 23,
00062 PF_FLOAT32_R = 33,
00063 PF_FLOAT32_RGB = 24,
00064 PF_FLOAT32_RGBA = 25,
00065 PF_FLOAT16_GR = 35,
00066 PF_FLOAT32_GR = 36,
00067 PF_DEPTH = 29,
00068 PF_SHORT_RGBA = 30,
00069 PF_SHORT_GR = 34,
00070 PF_SHORT_RGB = 37,
00071 PF_PVRTC_RGB2 = 38,
00072 PF_PVRTC_RGBA2 = 39,
00073 PF_PVRTC_RGB4 = 40,
00074 PF_PVRTC_RGBA4 = 41,
00075 PF_COUNT = 42
00076 };
00077
00079 enum PixelComponentType
00080 {
00081 PCT_BYTE,
00082 PCT_SHORT,
00083 PCT_FLOAT16,
00084 PCT_FLOAT32,
00085 PCT_COUNT
00086 };
00087
00089 enum PixelFormatFlags
00090 {
00091 PFF_HASALPHA = 0x00000001,
00092 PFF_COMPRESSED = 0x00000002,
00093 PFF_FLOAT = 0x00000004,
00094 PFF_DEPTH = 0x00000008,
00095 PFF_NATIVEENDIAN = 0x00000010,
00096 PFF_LUMINANCE = 0x00000020
00097 };
00098
00100 struct PixelFormatDescription
00101 {
00102 c8 *name;
00103 u8 elemBytes;
00104 u32 flags;
00105 PixelComponentType componentType;
00106 u8 componentCount;
00107 u8 rbits,gbits,bbits,abits;
00108 u32 rmask, gmask, bmask, amask;
00109 u8 rshift, gshift, bshift, ashift;
00110 };
00111
00112 class ENGINE_PUBLIC_EXPORT PixelUtil
00113 {
00114 public:
00115
00116 static const PixelFormatDescription& getDescriptionFor(const PixelFormat format);
00118 static u32 getNumElemBytes(PixelFormat format);
00119
00121 static u32 getNumElemBits(PixelFormat format);
00122
00124 static void getBitDepths(PixelFormat format, s32 rgba[4]);
00125
00127 static void getBitMasks(PixelFormat format, u32 rgba[4]);
00128
00130 static u32 getFlags(PixelFormat format);
00132 static bool hasAlpha(PixelFormat format);
00134 static bool isFloatingPoint(PixelFormat format);
00136 static bool isCompressed(PixelFormat format);
00138 static bool isDepth(PixelFormat format);
00140 static bool isNativeEndian(PixelFormat format);
00142 static bool isLuminance(PixelFormat format);
00143
00144 static void unpackColor(f32 *r, f32 *g, f32 *b, f32 *a, PixelFormat pf, const void* src);
00145 static void packColor(const f32 r, const f32 g, const f32 b, const f32 a, const PixelFormat pf, void* dest);
00146
00148 static u32 getMemorySize(u32 width, u32 height, u32 depth, PixelFormat format);
00149
00150
00151 static u32 calculateSize(u32 mipmaps, u32 faces, u32 width, u32 height, u32 depth, PixelFormat format);
00152
00153 private:
00154
00155 static PixelFormatDescription pixelFormats[PF_COUNT];
00156 };
00157
00158 }
00159
00160 #endif// _PIXELFORMAT_H_