PVRTexLibGlobals.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549
  1. /******************************************************************************
  2. @File PVRTexLibGlobals.h
  3. @Title Console Log
  4. @Version @Version Name : etc_conversion.cpp
  5. @Copyright Copyright (C) Imagination Technologies Limited.
  6. @Platform ANSI
  7. @Description Macros, enums and constants for PVRTexLib.
  8. ******************************************************************************/
  9. #ifndef PVRTEXLIBGLOBALS_H
  10. #define PVRTEXLIBGLOBALS_H
  11. #include "PVRTexLibVersion.h"
  12. /*****************************************************************************
  13. * Includes
  14. *****************************************************************************/
  15. namespace pvrtexlib
  16. {
  17. #ifdef __APPLE__
  18. /* The classes below are exported */
  19. #pragma GCC visibility push(default)
  20. #endif
  21. // DLL defines. Define _WINDLL_IMPORT to use the PVRTexLib dll under Windows
  22. #ifndef PVR_DLL
  23. #ifdef _WINDLL_EXPORT
  24. #define PVR_DLL __declspec(dllexport)
  25. #elif _WINDLL_IMPORT
  26. #define PVR_DLL __declspec(dllimport)
  27. #else
  28. #define PVR_DLL
  29. #endif
  30. #endif
  31. /*****************************************************************************
  32. * PVRTexLib Version
  33. *****************************************************************************/
  34. const char* const TEXTOOLVERSION_STRING = "";
  35. /*****************************************************************************
  36. * Arithmetic Macros
  37. *****************************************************************************/
  38. #define _CLAMP_(X,Xmin,Xmax) ( (X)<(Xmax) ? ( (X)<(Xmin)?(Xmin):(X) ) : (Xmax) )
  39. /*****************************************************************************
  40. * Memory Macros
  41. *****************************************************************************/
  42. #ifndef PVRFREE
  43. #define PVRFREE(A) { if(A) {free(A); A=NULL;} }
  44. #endif
  45. #ifndef PVRDELETE
  46. #define PVRDELETE(A) { if(A) {delete(A); A=NULL;}}
  47. #endif
  48. #ifndef PVRDELETEARRAY
  49. #define PVRDELETEARRAY(A) { if(A) {delete[](A); A=NULL;}}
  50. #endif
  51. // This macro is used to check at compile time that types are of a certain size
  52. // If the size does not equal the expected size, this typedefs an array of size 0
  53. // which causes a compile error
  54. #define PVRTSIZEASSERT(T, size) typedef int (sizeof_##T)[sizeof(T) == (size)]
  55. /*****************************************************************************
  56. * typedefs for standard pixel type channels
  57. *****************************************************************************/
  58. typedef signed char int8;
  59. typedef signed short int16;
  60. typedef signed int int32;
  61. typedef signed long long int64;
  62. typedef unsigned char uint8;
  63. typedef unsigned short uint16;
  64. typedef unsigned int uint32;
  65. typedef unsigned long long uint64;
  66. typedef float float32;
  67. typedef double float64;
  68. // check_standard_type is a struct where only the specialisations have a standard declaration (complete type)
  69. // if this struct is instantiated with a different type then the compiler will choke on it
  70. // Place a line like: " check_standard_type<channelType>(); " in a template function
  71. // to ensure it won't be called using an non-standard type.
  72. template<class T> struct check_standard_type;
  73. template<> struct check_standard_type<uint8> {};
  74. template<> struct check_standard_type<uint16> {};
  75. template<> struct check_standard_type<uint32> {};
  76. template<> struct check_standard_type<float32> {};
  77. template<> struct check_standard_type<float64> {};
  78. // simple float16 class
  79. class float16
  80. {
  81. uint16 fVal;
  82. public:
  83. float16(){}
  84. // direct constructor
  85. template <typename t>
  86. float16(const t& F)
  87. {
  88. fVal = F;
  89. }
  90. // conversion to float32 is special
  91. float16(const float32& F)
  92. {
  93. unsigned long uF = *((unsigned long*)&F);
  94. unsigned long uSign = (uF & 0x10000000) >> 31;
  95. unsigned long uExponent = (uF & 0x7F800000) >> 23;
  96. unsigned long uMantissa = (uF & 0x007FFFFF);
  97. int uExp = uExponent - 127 + 15;
  98. if(uExp < 1) uExp = 1;
  99. if(uExp > 30) uExp = 30;
  100. fVal = (unsigned short)((uSign << 15) |((unsigned int)uExp << 10) | (uMantissa >> 13));
  101. }
  102. // Overloading brackets operator to return float32 from float16 value.
  103. operator float32() const
  104. {
  105. union
  106. {
  107. unsigned int uL;
  108. float32 fL;
  109. } uuu;
  110. uuu.uL = ((fVal & 0x1000) << 16) | //sign
  111. (( (fVal & 0x7C00) >> 10) - 15 + 127 ) << 23| //5 bit exponent.
  112. (fVal & 0x03FF) << 13 ; //10 bit mantissa.
  113. return uuu.fL;
  114. }
  115. };
  116. // check type sizes
  117. PVRTSIZEASSERT(uint8,1);
  118. PVRTSIZEASSERT(uint16,2);
  119. PVRTSIZEASSERT(uint32,4);
  120. PVRTSIZEASSERT(uint64,8);
  121. PVRTSIZEASSERT(int8,1);
  122. PVRTSIZEASSERT(int16,2);
  123. PVRTSIZEASSERT(int32,4);
  124. PVRTSIZEASSERT(int64,8);
  125. PVRTSIZEASSERT(float16,2);
  126. PVRTSIZEASSERT(float32,4);
  127. PVRTSIZEASSERT(float64,8);
  128. // default working type for combining channels (to avoid overflows)
  129. template<class T> struct combine_type
  130. {
  131. typedef float64 type;
  132. };
  133. // specialisation for uint32 to avoid overflows
  134. template<> struct combine_type<uint32>
  135. {
  136. typedef float64 type;
  137. };
  138. // specialisation for float16 to avoid overflows
  139. template<> struct combine_type<float16>
  140. {
  141. typedef float64 type;
  142. };
  143. // specialisation for float32 to avoid overflows
  144. template<> struct combine_type<float32>
  145. {
  146. typedef float64 type;
  147. };
  148. // Returns the maximum value before overflow for these types (in the context of texture channels)
  149. template<typename tType>
  150. tType getMaximumValue();
  151. template<>
  152. inline float64 getMaximumValue<float64>(){return 1.0;}
  153. template<>
  154. inline float32 getMaximumValue<float32>(){return 1.0f;}
  155. template<>
  156. inline float16 getMaximumValue<float16>(){return 1.0f;}
  157. template<>
  158. inline uint64 getMaximumValue<uint64>(){return 0xffffffffffffffffULL;}
  159. template<>
  160. inline uint32 getMaximumValue<uint32>(){return 0xffffffff;}
  161. template<>
  162. inline uint16 getMaximumValue<uint16>(){return 0xffff;}
  163. template<>
  164. inline uint8 getMaximumValue<uint8>(){return 0xff;}
  165. template<>
  166. inline int64 getMaximumValue<int64>(){return 0x7fffffffffffffffLL;}
  167. template<>
  168. inline int32 getMaximumValue<int32>(){return 0x7fffffff;}
  169. template<>
  170. inline int16 getMaximumValue<int16>(){return 0x7fff;}
  171. template<>
  172. inline int8 getMaximumValue<int8>(){return 0x7f;}
  173. /*****************************************************************************
  174. * PixelType - corresponds to all pixel formats understood by PVRTexLib
  175. *****************************************************************************/
  176. enum PixelType
  177. {
  178. MGLPT_ARGB_4444 = 0x00,
  179. MGLPT_ARGB_1555,
  180. MGLPT_RGB_565,
  181. MGLPT_RGB_555,
  182. MGLPT_RGB_888,
  183. MGLPT_ARGB_8888,
  184. MGLPT_ARGB_8332,
  185. MGLPT_I_8,
  186. MGLPT_AI_88,
  187. MGLPT_1_BPP,
  188. MGLPT_VY1UY0,
  189. MGLPT_Y1VY0U,
  190. MGLPT_PVRTC2,
  191. MGLPT_PVRTC4,
  192. // OpenGL version of pixel types
  193. OGL_RGBA_4444= 0x10,
  194. OGL_RGBA_5551,
  195. OGL_RGBA_8888,
  196. OGL_RGB_565,
  197. OGL_RGB_555,
  198. OGL_RGB_888,
  199. OGL_I_8,
  200. OGL_AI_88,
  201. OGL_PVRTC2,
  202. OGL_PVRTC4,
  203. // OGL_BGRA_8888 extension
  204. OGL_BGRA_8888,
  205. OGL_A_8,
  206. OGL_PVRTCII4,
  207. OGL_PVRTCII2,
  208. #ifdef _WIN32
  209. // S3TC Encoding
  210. D3D_DXT1 = 0x20,
  211. D3D_DXT2,
  212. D3D_DXT3,
  213. D3D_DXT4,
  214. D3D_DXT5,
  215. #endif
  216. //RGB Formats
  217. D3D_RGB_332
  218. #ifndef _WIN32
  219. = 0x20
  220. #endif
  221. ,
  222. D3D_ABGR_2101010,
  223. D3D_ARGB_2101010,
  224. D3D_ABGR_16161616,
  225. //<3 Channels
  226. D3D_GR_1616,
  227. //Float Formats
  228. D3D_R16F,
  229. D3D_GR_1616F,
  230. D3D_ABGR_16161616F,
  231. D3D_R32F,
  232. D3D_GR_3232F,
  233. D3D_ABGR_32323232F,
  234. //Luminance/Alpha Formats
  235. D3D_AL_44,
  236. D3D_AL_88,
  237. D3D_A8,
  238. D3D_L8,
  239. D3D_L16,
  240. //Y'UV Colourspace
  241. D3D_UYVY,
  242. D3D_YUY2,
  243. //Bumpmap Formats
  244. D3D_LVU_655,
  245. D3D_XLVU_8888,
  246. D3D_QWVU_8888,
  247. D3D_AWVU_2101010,
  248. D3D_VU_1616,
  249. D3D_V8U8,
  250. // Ericsson
  251. ETC_RGB_4BPP,
  252. ETC_RGBA_EXPLICIT, // unimplemented
  253. ETC_RGBA_INTERPOLATED, // unimplemented
  254. // DX10
  255. DX10_R32G32B32A32_FLOAT= 0x50,
  256. DX10_R32G32B32A32_UINT ,
  257. DX10_R32G32B32A32_SINT,
  258. DX10_R32G32B32_FLOAT,
  259. DX10_R32G32B32_UINT,
  260. DX10_R32G32B32_SINT,
  261. DX10_R16G16B16A16_FLOAT ,
  262. DX10_R16G16B16A16_UNORM,
  263. DX10_R16G16B16A16_UINT ,
  264. DX10_R16G16B16A16_SNORM ,
  265. DX10_R16G16B16A16_SINT ,
  266. DX10_R32G32_FLOAT ,
  267. DX10_R32G32_UINT ,
  268. DX10_R32G32_SINT ,
  269. DX10_R10G10B10A2_UNORM ,
  270. DX10_R10G10B10A2_UINT ,
  271. DX10_R11G11B10_FLOAT , // unimplemented
  272. DX10_R8G8B8A8_UNORM ,
  273. DX10_R8G8B8A8_UNORM_SRGB ,
  274. DX10_R8G8B8A8_UINT ,
  275. DX10_R8G8B8A8_SNORM ,
  276. DX10_R8G8B8A8_SINT ,
  277. DX10_R16G16_FLOAT ,
  278. DX10_R16G16_UNORM ,
  279. DX10_R16G16_UINT ,
  280. DX10_R16G16_SNORM ,
  281. DX10_R16G16_SINT ,
  282. DX10_R32_FLOAT ,
  283. DX10_R32_UINT ,
  284. DX10_R32_SINT ,
  285. DX10_R8G8_UNORM ,
  286. DX10_R8G8_UINT ,
  287. DX10_R8G8_SNORM ,
  288. DX10_R8G8_SINT ,
  289. DX10_R16_FLOAT ,
  290. DX10_R16_UNORM ,
  291. DX10_R16_UINT ,
  292. DX10_R16_SNORM ,
  293. DX10_R16_SINT ,
  294. DX10_R8_UNORM,
  295. DX10_R8_UINT,
  296. DX10_R8_SNORM,
  297. DX10_R8_SINT,
  298. DX10_A8_UNORM,
  299. DX10_R1_UNORM,
  300. DX10_R9G9B9E5_SHAREDEXP, // unimplemented
  301. DX10_R8G8_B8G8_UNORM, // unimplemented
  302. DX10_G8R8_G8B8_UNORM, // unimplemented
  303. DX10_BC1_UNORM,
  304. DX10_BC1_UNORM_SRGB,
  305. DX10_BC2_UNORM,
  306. DX10_BC2_UNORM_SRGB,
  307. DX10_BC3_UNORM,
  308. DX10_BC3_UNORM_SRGB,
  309. DX10_BC4_UNORM, // unimplemented
  310. DX10_BC4_SNORM, // unimplemented
  311. DX10_BC5_UNORM, // unimplemented
  312. DX10_BC5_SNORM, // unimplemented
  313. // OpenVG
  314. /* RGB{A,X} channel ordering */
  315. ePT_VG_sRGBX_8888 = 0x90,
  316. ePT_VG_sRGBA_8888,
  317. ePT_VG_sRGBA_8888_PRE,
  318. ePT_VG_sRGB_565,
  319. ePT_VG_sRGBA_5551,
  320. ePT_VG_sRGBA_4444,
  321. ePT_VG_sL_8,
  322. ePT_VG_lRGBX_8888,
  323. ePT_VG_lRGBA_8888,
  324. ePT_VG_lRGBA_8888_PRE,
  325. ePT_VG_lL_8,
  326. ePT_VG_A_8,
  327. ePT_VG_BW_1,
  328. /* {A,X}RGB channel ordering */
  329. ePT_VG_sXRGB_8888,
  330. ePT_VG_sARGB_8888,
  331. ePT_VG_sARGB_8888_PRE,
  332. ePT_VG_sARGB_1555,
  333. ePT_VG_sARGB_4444,
  334. ePT_VG_lXRGB_8888,
  335. ePT_VG_lARGB_8888,
  336. ePT_VG_lARGB_8888_PRE,
  337. /* BGR{A,X} channel ordering */
  338. ePT_VG_sBGRX_8888,
  339. ePT_VG_sBGRA_8888,
  340. ePT_VG_sBGRA_8888_PRE,
  341. ePT_VG_sBGR_565,
  342. ePT_VG_sBGRA_5551,
  343. ePT_VG_sBGRA_4444,
  344. ePT_VG_lBGRX_8888,
  345. ePT_VG_lBGRA_8888,
  346. ePT_VG_lBGRA_8888_PRE,
  347. /* {A,X}BGR channel ordering */
  348. ePT_VG_sXBGR_8888,
  349. ePT_VG_sABGR_8888 ,
  350. ePT_VG_sABGR_8888_PRE,
  351. ePT_VG_sABGR_1555,
  352. ePT_VG_sABGR_4444,
  353. ePT_VG_lXBGR_8888,
  354. ePT_VG_lABGR_8888,
  355. ePT_VG_lABGR_8888_PRE,
  356. // max cap for iterating
  357. END_OF_PIXEL_TYPES,
  358. MGLPT_NOTYPE = 0xffffffff
  359. };
  360. // Standard pixel types for each precision of library
  361. // These are the formats that the lib actually works on
  362. const PixelType eInt8StandardPixelType = DX10_R8G8B8A8_UNORM,
  363. eInt16StandardPixelType = D3D_ABGR_16161616,
  364. eInt32StandardPixelType = DX10_R32G32B32A32_UINT,
  365. eFloatStandardPixelType = D3D_ABGR_32323232F;
  366. // The number of APIs supported by the library
  367. // enums for each of these APIs
  368. enum E_API
  369. {
  370. eALL_API=0,
  371. eOGLES,
  372. eOGLES2,
  373. eD3DM,
  374. eOGL2,
  375. eDX9,
  376. eDX10,
  377. eOVG,
  378. eMGL,
  379. NUM_APIS,
  380. };
  381. // human readable names for APIs
  382. const char ppszAPINames[NUM_APIS][16] =
  383. {
  384. "All APIs","OpenGL ES 1.x","OpenGL ES 2.0","Direct3D Mobile","OpenGL","DirectX 9","DirectX 10","OpenVG","MGL"
  385. };
  386. // names for cube map faces
  387. const char g_pszCubeFaceNames[6][6] =
  388. {
  389. "FRONT","BACK","RIGHT","LEFT","TOP","BASE"
  390. };
  391. enum E_PRECMODE
  392. { // precision modes - correspond to standard pixel types
  393. ePREC_INT8=0,
  394. ePREC_INT16,
  395. ePREC_INT32,
  396. ePREC_FLOAT,
  397. ePREC_NONE
  398. };
  399. enum E_RESIZE_MODE
  400. { // scaling modes
  401. eRESIZE_NEAREST=0,
  402. eRESIZE_BILINEAR,
  403. eRESIZE_BICUBIC,
  404. eNumResizeModes
  405. };
  406. const E_RESIZE_MODE keResizeModeDefault = eRESIZE_BICUBIC;
  407. enum E_PVRTC_ENCODING_MODE
  408. {
  409. ePVRTC_NORMAL=0,
  410. ePVRTC_FAST,
  411. eNumPVRTCModes
  412. };
  413. const E_PVRTC_ENCODING_MODE kePVRTCEncodingModeDefault = ePVRTC_NORMAL;
  414. enum E_DITHER_MODE
  415. {
  416. eDITHER_NONE=0,
  417. eDITHER_MONO,
  418. eNumDitherModes
  419. };
  420. const E_DITHER_MODE keDitherModeDefault = eDITHER_NONE;
  421. const int kiPVRTCIterationsDefault = 8;
  422. enum E_ETC_ENCODING_MODE
  423. {
  424. eFast=0,
  425. eMedium,
  426. eSlow,
  427. eFastPerceptual,
  428. eMediumPerceptual,
  429. eSlowPerceptual,
  430. eNumETCModes
  431. };
  432. const E_ETC_ENCODING_MODE keETCEncodingModeDefault = eFastPerceptual;
  433. const char kstrETCEncodingMode[][18] =
  434. {
  435. "Fast",
  436. "Medium",
  437. "Slow",
  438. "Fast Perceptual",
  439. "Medium Perceptual",
  440. "Slow Perceptual",
  441. };
  442. enum E_BORDER_TYPE
  443. {
  444. eBORDER_PVRTC4=0,
  445. eBORDER_PVRTC2
  446. };
  447. const E_BORDER_TYPE keBorderTypeDefault = eBORDER_PVRTC4;
  448. #ifdef __APPLE__
  449. #pragma GCC visibility pop
  450. #endif
  451. }
  452. #endif
  453. /*****************************************************************************
  454. End of file (PVRTexLibGlobals.h)
  455. *****************************************************************************/