PVRTTexture.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736
  1. /*!****************************************************************************
  2. @file PVRTTexture.h
  3. @copyright Copyright (c) Imagination Technologies Limited.
  4. @brief Texture loading.
  5. ******************************************************************************/
  6. #ifndef _PVRTTEXTURE_H_
  7. #define _PVRTTEXTURE_H_
  8. #include "PVRTGlobal.h"
  9. /*****************************************************************************
  10. * Texture related constants and enumerations.
  11. *****************************************************************************/
  12. // V3 Header Identifiers.
  13. const PVRTuint32 PVRTEX3_IDENT = 0x03525650; // 'P''V''R'3
  14. const PVRTuint32 PVRTEX3_IDENT_REV = 0x50565203;
  15. // If endianness is backwards then PVR3 will read as 3RVP, hence why it is written as an int.
  16. //Current version texture identifiers
  17. const PVRTuint32 PVRTEX_CURR_IDENT = PVRTEX3_IDENT;
  18. const PVRTuint32 PVRTEX_CURR_IDENT_REV = PVRTEX3_IDENT_REV;
  19. // PVR Header file flags. Condition if true. If false, opposite is true unless specified.
  20. const PVRTuint32 PVRTEX3_FILE_COMPRESSED = (1<<0); // Texture has been file compressed using PVRTexLib (currently unused)
  21. const PVRTuint32 PVRTEX3_PREMULTIPLIED = (1<<1); // Texture has been premultiplied by alpha value.
  22. // Mip Map level specifier constants. Other levels are specified by 1,2...n
  23. const PVRTint32 PVRTEX_TOPMIPLEVEL = 0;
  24. const PVRTint32 PVRTEX_ALLMIPLEVELS = -1; //This is a special number used simply to return a total of all MIP levels when dealing with data sizes.
  25. //values for each meta data type that we know about. Texture arrays hinge on each surface being identical in all but content, including meta data.
  26. //If the meta data varies even slightly then a new texture should be used. It is possible to write your own extension to get around this however.
  27. enum EPVRTMetaData
  28. {
  29. ePVRTMetaDataTextureAtlasCoords=0,
  30. ePVRTMetaDataBumpData,
  31. ePVRTMetaDataCubeMapOrder,
  32. ePVRTMetaDataTextureOrientation,
  33. ePVRTMetaDataBorderData,
  34. ePVRTMetaDataPadding,
  35. ePVRTMetaDataNumMetaDataTypes
  36. };
  37. enum EPVRTAxis
  38. {
  39. ePVRTAxisX = 0,
  40. ePVRTAxisY = 1,
  41. ePVRTAxisZ = 2
  42. };
  43. enum EPVRTOrientation
  44. {
  45. ePVRTOrientLeft = 1<<ePVRTAxisX,
  46. ePVRTOrientRight= 0,
  47. ePVRTOrientUp = 1<<ePVRTAxisY,
  48. ePVRTOrientDown = 0,
  49. ePVRTOrientOut = 1<<ePVRTAxisZ,
  50. ePVRTOrientIn = 0
  51. };
  52. enum EPVRTColourSpace
  53. {
  54. ePVRTCSpacelRGB,
  55. ePVRTCSpacesRGB,
  56. ePVRTCSpaceNumSpaces
  57. };
  58. //Compressed pixel formats
  59. enum EPVRTPixelFormat
  60. {
  61. ePVRTPF_PVRTCI_2bpp_RGB,
  62. ePVRTPF_PVRTCI_2bpp_RGBA,
  63. ePVRTPF_PVRTCI_4bpp_RGB,
  64. ePVRTPF_PVRTCI_4bpp_RGBA,
  65. ePVRTPF_PVRTCII_2bpp,
  66. ePVRTPF_PVRTCII_4bpp,
  67. ePVRTPF_ETC1,
  68. ePVRTPF_DXT1,
  69. ePVRTPF_DXT2,
  70. ePVRTPF_DXT3,
  71. ePVRTPF_DXT4,
  72. ePVRTPF_DXT5,
  73. //These formats are identical to some DXT formats.
  74. ePVRTPF_BC1 = ePVRTPF_DXT1,
  75. ePVRTPF_BC2 = ePVRTPF_DXT3,
  76. ePVRTPF_BC3 = ePVRTPF_DXT5,
  77. //These are currently unsupported:
  78. ePVRTPF_BC4,
  79. ePVRTPF_BC5,
  80. ePVRTPF_BC6,
  81. ePVRTPF_BC7,
  82. //These are supported
  83. ePVRTPF_UYVY,
  84. ePVRTPF_YUY2,
  85. ePVRTPF_BW1bpp,
  86. ePVRTPF_SharedExponentR9G9B9E5,
  87. ePVRTPF_RGBG8888,
  88. ePVRTPF_GRGB8888,
  89. ePVRTPF_ETC2_RGB,
  90. ePVRTPF_ETC2_RGBA,
  91. ePVRTPF_ETC2_RGB_A1,
  92. ePVRTPF_EAC_R11,
  93. ePVRTPF_EAC_RG11,
  94. ePVRTPF_ASTC_4x4,
  95. ePVRTPF_ASTC_5x4,
  96. ePVRTPF_ASTC_5x5,
  97. ePVRTPF_ASTC_6x5,
  98. ePVRTPF_ASTC_6x6,
  99. ePVRTPF_ASTC_8x5,
  100. ePVRTPF_ASTC_8x6,
  101. ePVRTPF_ASTC_8x8,
  102. ePVRTPF_ASTC_10x5,
  103. ePVRTPF_ASTC_10x6,
  104. ePVRTPF_ASTC_10x8,
  105. ePVRTPF_ASTC_10x10,
  106. ePVRTPF_ASTC_12x10,
  107. ePVRTPF_ASTC_12x12,
  108. ePVRTPF_ASTC_3x3x3,
  109. ePVRTPF_ASTC_4x3x3,
  110. ePVRTPF_ASTC_4x4x3,
  111. ePVRTPF_ASTC_4x4x4,
  112. ePVRTPF_ASTC_5x4x4,
  113. ePVRTPF_ASTC_5x5x4,
  114. ePVRTPF_ASTC_5x5x5,
  115. ePVRTPF_ASTC_6x5x5,
  116. ePVRTPF_ASTC_6x6x5,
  117. ePVRTPF_ASTC_6x6x6,
  118. //Invalid value
  119. ePVRTPF_NumCompressedPFs
  120. };
  121. //Variable Type Names
  122. enum EPVRTVariableType
  123. {
  124. ePVRTVarTypeUnsignedByteNorm,
  125. ePVRTVarTypeSignedByteNorm,
  126. ePVRTVarTypeUnsignedByte,
  127. ePVRTVarTypeSignedByte,
  128. ePVRTVarTypeUnsignedShortNorm,
  129. ePVRTVarTypeSignedShortNorm,
  130. ePVRTVarTypeUnsignedShort,
  131. ePVRTVarTypeSignedShort,
  132. ePVRTVarTypeUnsignedIntegerNorm,
  133. ePVRTVarTypeSignedIntegerNorm,
  134. ePVRTVarTypeUnsignedInteger,
  135. ePVRTVarTypeSignedInteger,
  136. ePVRTVarTypeSignedFloat, ePVRTVarTypeFloat=ePVRTVarTypeSignedFloat, //the name ePVRTVarTypeFloat is now deprecated.
  137. ePVRTVarTypeUnsignedFloat,
  138. ePVRTVarTypeNumVarTypes
  139. };
  140. //A 64 bit pixel format ID & this will give you the high bits of a pixel format to check for a compressed format.
  141. static const PVRTuint64 PVRTEX_PFHIGHMASK=0xffffffff00000000ull;
  142. /*****************************************************************************
  143. * Texture header structures.
  144. *****************************************************************************/
  145. /*!***********************************************************************
  146. @struct MetaDataBlock
  147. @brief A struct containing a block of extraneous meta data for a texture.
  148. *************************************************************************/
  149. struct MetaDataBlock
  150. {
  151. PVRTuint32 DevFOURCC; ///< A 4cc descriptor of the data type's creator. Values equating to values between 'P' 'V' 'R' 0 and 'P' 'V' 'R' 255 will be used by our headers.
  152. PVRTuint32 u32Key; ///< A DWORD (enum value) identifying the data type, and thus how to read it.
  153. PVRTuint32 u32DataSize; ///< Size of the Data member.
  154. PVRTuint8* Data; ///< Data array, can be absolutely anything, the loader needs to know how to handle it based on DevFOURCC and Key. Use new operator to assign to it.
  155. /*!***********************************************************************
  156. @fn MetaDataBlock
  157. @brief Meta Data Block Constructor
  158. *************************************************************************/
  159. MetaDataBlock() : DevFOURCC(0), u32Key(0), u32DataSize(0), Data(NULL)
  160. {}
  161. /*!***********************************************************************
  162. @fn MetaDataBlock
  163. @brief Meta Data Block Copy Constructor
  164. *************************************************************************/
  165. MetaDataBlock(const MetaDataBlock& rhs) : DevFOURCC(rhs.DevFOURCC), u32Key(rhs.u32Key), u32DataSize(rhs.u32DataSize)
  166. {
  167. //Copy the data across.
  168. Data = new PVRTuint8[u32DataSize];
  169. for (PVRTuint32 uiDataAmt=0; uiDataAmt<u32DataSize; ++uiDataAmt)
  170. {
  171. Data[uiDataAmt]=rhs.Data[uiDataAmt];
  172. }
  173. }
  174. /*!***********************************************************************
  175. @fn ~MetaDataBlock
  176. @brief Meta Data Block Destructor
  177. *************************************************************************/
  178. ~MetaDataBlock()
  179. {
  180. if (Data)
  181. delete [] Data;
  182. Data = NULL;
  183. }
  184. /*!***********************************************************************
  185. @fn SizeOfBlock
  186. @return size_t Size (in a file) of the block.
  187. @brief Returns the number of extra bytes this will add to any output files.
  188. *************************************************************************/
  189. size_t SizeOfBlock() const
  190. {
  191. return sizeof(DevFOURCC)+sizeof(u32Key)+sizeof(u32DataSize)+u32DataSize;
  192. }
  193. /*!***********************************************************************
  194. @brief Assigns one MetaDataBlock to the other.
  195. @return MetaDataBlock This MetaDataBlock after the operation.
  196. *************************************************************************/
  197. MetaDataBlock& operator=(const MetaDataBlock& rhs)
  198. {
  199. if (&rhs==this)
  200. return *this;
  201. //Remove pre-existing data.
  202. if (Data)
  203. delete [] Data;
  204. Data=NULL;
  205. //Copy the basic parameters
  206. DevFOURCC=rhs.DevFOURCC;
  207. u32Key=rhs.u32Key;
  208. u32DataSize=rhs.u32DataSize;
  209. //Copy the data across.
  210. if (rhs.Data)
  211. {
  212. Data = new PVRTuint8[u32DataSize];
  213. for (PVRTuint32 uiDataAmt=0; uiDataAmt<u32DataSize; ++uiDataAmt)
  214. {
  215. Data[uiDataAmt]=rhs.Data[uiDataAmt];
  216. }
  217. }
  218. return *this;
  219. }
  220. /*!***************************************************************************
  221. @fn ReadFromPtr
  222. @param[in] pDataCursor The data to read
  223. @brief Reads from a pointer of memory in to the meta data block.
  224. *****************************************************************************/
  225. bool ReadFromPtr(const unsigned char** pDataCursor);
  226. };
  227. #pragma pack(push,4)
  228. /*!***************************************************************************
  229. @struct PVRTextureHeaderV3
  230. @brief A header for a PVR texture.
  231. @details Contains everything required to read a texture accurately, and nothing more. Extraneous data is stored in a MetaDataBlock.
  232. Correct use of the texture may rely on MetaDataBlock, but accurate data loading can be done through the standard header alone.
  233. *****************************************************************************/
  234. struct PVRTextureHeaderV3{
  235. PVRTuint32 u32Version; ///< Version of the file header, used to identify it.
  236. PVRTuint32 u32Flags; ///< Various format flags.
  237. PVRTuint64 u64PixelFormat; ///< The pixel format, 8cc value storing the 4 channel identifiers and their respective sizes.
  238. PVRTuint32 u32ColourSpace; ///< The Colour Space of the texture, currently either linear RGB or sRGB.
  239. PVRTuint32 u32ChannelType; ///< Variable type that the channel is stored in. Supports signed/unsigned int/short/byte or float for now.
  240. PVRTuint32 u32Height; ///< Height of the texture.
  241. PVRTuint32 u32Width; ///< Width of the texture.
  242. PVRTuint32 u32Depth; ///< Depth of the texture. (Z-slices)
  243. PVRTuint32 u32NumSurfaces; ///< Number of members in a Texture Array.
  244. PVRTuint32 u32NumFaces; ///< Number of faces in a Cube Map. Maybe be a value other than 6.
  245. PVRTuint32 u32MIPMapCount; ///< Number of MIP Maps in the texture - NB: Includes top level.
  246. PVRTuint32 u32MetaDataSize; ///< Size of the accompanying meta data.
  247. /*!***************************************************************************
  248. @brief Constructor for the header - used to make sure that the header is initialised usefully.
  249. The initial pixel format is an invalid one and must be set.
  250. *****************************************************************************/
  251. PVRTextureHeaderV3() :
  252. u32Version(PVRTEX3_IDENT), ///< Version of the file header.
  253. u32Flags(0), ///< Format flags.
  254. u64PixelFormat(ePVRTPF_NumCompressedPFs), ///< The pixel format.
  255. u32ColourSpace(0), ///< The Colour Space of the texture.
  256. u32ChannelType(0), ///< Variable type that the channel is stored in.
  257. u32Height(1), ///< Height of the texture.
  258. u32Width(1), ///< Width of the texture.
  259. u32Depth(1), ///< Depth of the texture. (Z-slices)
  260. u32NumSurfaces(1), ///< Number of members in a Texture Array.
  261. u32NumFaces(1), ///< Number of faces in a Cube Map. Maybe be a value other than 6.
  262. u32MIPMapCount(1), ///< Number of MIP Maps in the texture - NB: Includes top level.
  263. u32MetaDataSize(0) ///< Size of the accompanying meta data.
  264. {}
  265. };
  266. #pragma pack(pop)
  267. #define PVRTEX3_HEADERSIZE 52
  268. /*!***************************************************************************
  269. @brief Describes the Version 2 header of a PVR texture header.
  270. *****************************************************************************/
  271. struct PVR_Texture_Header
  272. {
  273. PVRTuint32 dwHeaderSize; /*!< size of the structure */
  274. PVRTuint32 dwHeight; /*!< height of surface to be created */
  275. PVRTuint32 dwWidth; /*!< width of input surface */
  276. PVRTuint32 dwMipMapCount; /*!< number of mip-map levels requested */
  277. PVRTuint32 dwpfFlags; /*!< pixel format flags */
  278. PVRTuint32 dwTextureDataSize; /*!< Total size in bytes */
  279. PVRTuint32 dwBitCount; /*!< number of bits per pixel */
  280. PVRTuint32 dwRBitMask; /*!< mask for red bit */
  281. PVRTuint32 dwGBitMask; /*!< mask for green bits */
  282. PVRTuint32 dwBBitMask; /*!< mask for blue bits */
  283. PVRTuint32 dwAlphaBitMask; /*!< mask for alpha channel */
  284. PVRTuint32 dwPVR; /*!< magic number identifying pvr file */
  285. PVRTuint32 dwNumSurfs; /*!< the number of surfaces present in the pvr */
  286. } ;
  287. /*****************************************************************************
  288. * Legacy (V2 and V1) ENUMS
  289. *****************************************************************************/
  290. /*!***************************************************************************
  291. @brief Legacy pixel type. DEPRECATED.
  292. *****************************************************************************/
  293. enum PVRTPixelType
  294. {
  295. MGLPT_ARGB_4444 = 0x00,
  296. MGLPT_ARGB_1555,
  297. MGLPT_RGB_565,
  298. MGLPT_RGB_555,
  299. MGLPT_RGB_888,
  300. MGLPT_ARGB_8888,
  301. MGLPT_ARGB_8332,
  302. MGLPT_I_8,
  303. MGLPT_AI_88,
  304. MGLPT_1_BPP,
  305. MGLPT_VY1UY0,
  306. MGLPT_Y1VY0U,
  307. MGLPT_PVRTC2,
  308. MGLPT_PVRTC4,
  309. // OpenGL version of pixel types
  310. OGL_RGBA_4444= 0x10,
  311. OGL_RGBA_5551,
  312. OGL_RGBA_8888,
  313. OGL_RGB_565,
  314. OGL_RGB_555,
  315. OGL_RGB_888,
  316. OGL_I_8,
  317. OGL_AI_88,
  318. OGL_PVRTC2,
  319. OGL_PVRTC4,
  320. OGL_BGRA_8888,
  321. OGL_A_8,
  322. OGL_PVRTCII4, ///< Not in use
  323. OGL_PVRTCII2, ///< Not in use
  324. // S3TC Encoding
  325. D3D_DXT1 = 0x20,
  326. D3D_DXT2,
  327. D3D_DXT3,
  328. D3D_DXT4,
  329. D3D_DXT5,
  330. //RGB Formats
  331. D3D_RGB_332,
  332. D3D_AL_44,
  333. D3D_LVU_655,
  334. D3D_XLVU_8888,
  335. D3D_QWVU_8888,
  336. //10 bit integer - 2 bit alpha
  337. D3D_ABGR_2101010,
  338. D3D_ARGB_2101010,
  339. D3D_AWVU_2101010,
  340. //16 bit integers
  341. D3D_GR_1616,
  342. D3D_VU_1616,
  343. D3D_ABGR_16161616,
  344. //Float Formats
  345. D3D_R16F,
  346. D3D_GR_1616F,
  347. D3D_ABGR_16161616F,
  348. //32 bits per channel
  349. D3D_R32F,
  350. D3D_GR_3232F,
  351. D3D_ABGR_32323232F,
  352. // Ericsson
  353. ETC_RGB_4BPP,
  354. ETC_RGBA_EXPLICIT, ///< Unimplemented
  355. ETC_RGBA_INTERPOLATED, ///< Unimplemented
  356. D3D_A8 = 0x40,
  357. D3D_V8U8,
  358. D3D_L16,
  359. D3D_L8,
  360. D3D_AL_88,
  361. //Y'UV Colourspace
  362. D3D_UYVY,
  363. D3D_YUY2,
  364. // DX10
  365. DX10_R32G32B32A32_FLOAT= 0x50,
  366. DX10_R32G32B32A32_UINT ,
  367. DX10_R32G32B32A32_SINT,
  368. DX10_R32G32B32_FLOAT,
  369. DX10_R32G32B32_UINT,
  370. DX10_R32G32B32_SINT,
  371. DX10_R16G16B16A16_FLOAT ,
  372. DX10_R16G16B16A16_UNORM,
  373. DX10_R16G16B16A16_UINT ,
  374. DX10_R16G16B16A16_SNORM ,
  375. DX10_R16G16B16A16_SINT ,
  376. DX10_R32G32_FLOAT ,
  377. DX10_R32G32_UINT ,
  378. DX10_R32G32_SINT ,
  379. DX10_R10G10B10A2_UNORM ,
  380. DX10_R10G10B10A2_UINT ,
  381. DX10_R11G11B10_FLOAT , ///< Unimplemented
  382. DX10_R8G8B8A8_UNORM ,
  383. DX10_R8G8B8A8_UNORM_SRGB ,
  384. DX10_R8G8B8A8_UINT ,
  385. DX10_R8G8B8A8_SNORM ,
  386. DX10_R8G8B8A8_SINT ,
  387. DX10_R16G16_FLOAT ,
  388. DX10_R16G16_UNORM ,
  389. DX10_R16G16_UINT ,
  390. DX10_R16G16_SNORM ,
  391. DX10_R16G16_SINT ,
  392. DX10_R32_FLOAT ,
  393. DX10_R32_UINT ,
  394. DX10_R32_SINT ,
  395. DX10_R8G8_UNORM ,
  396. DX10_R8G8_UINT ,
  397. DX10_R8G8_SNORM ,
  398. DX10_R8G8_SINT ,
  399. DX10_R16_FLOAT ,
  400. DX10_R16_UNORM ,
  401. DX10_R16_UINT ,
  402. DX10_R16_SNORM ,
  403. DX10_R16_SINT ,
  404. DX10_R8_UNORM,
  405. DX10_R8_UINT,
  406. DX10_R8_SNORM,
  407. DX10_R8_SINT,
  408. DX10_A8_UNORM,
  409. DX10_R1_UNORM,
  410. DX10_R9G9B9E5_SHAREDEXP, ///< Unimplemented
  411. DX10_R8G8_B8G8_UNORM, ///< Unimplemented
  412. DX10_G8R8_G8B8_UNORM, ///< Unimplemented
  413. DX10_BC1_UNORM,
  414. DX10_BC1_UNORM_SRGB,
  415. DX10_BC2_UNORM,
  416. DX10_BC2_UNORM_SRGB,
  417. DX10_BC3_UNORM,
  418. DX10_BC3_UNORM_SRGB,
  419. DX10_BC4_UNORM, ///< Unimplemented
  420. DX10_BC4_SNORM, ///< Unimplemented
  421. DX10_BC5_UNORM, ///< Unimplemented
  422. DX10_BC5_SNORM, ///< Unimplemented
  423. // OpenVG
  424. /* RGB{A,X} channel ordering */
  425. ePT_VG_sRGBX_8888 = 0x90,
  426. ePT_VG_sRGBA_8888,
  427. ePT_VG_sRGBA_8888_PRE,
  428. ePT_VG_sRGB_565,
  429. ePT_VG_sRGBA_5551,
  430. ePT_VG_sRGBA_4444,
  431. ePT_VG_sL_8,
  432. ePT_VG_lRGBX_8888,
  433. ePT_VG_lRGBA_8888,
  434. ePT_VG_lRGBA_8888_PRE,
  435. ePT_VG_lL_8,
  436. ePT_VG_A_8,
  437. ePT_VG_BW_1,
  438. /* {A,X}RGB channel ordering */
  439. ePT_VG_sXRGB_8888,
  440. ePT_VG_sARGB_8888,
  441. ePT_VG_sARGB_8888_PRE,
  442. ePT_VG_sARGB_1555,
  443. ePT_VG_sARGB_4444,
  444. ePT_VG_lXRGB_8888,
  445. ePT_VG_lARGB_8888,
  446. ePT_VG_lARGB_8888_PRE,
  447. /* BGR{A,X} channel ordering */
  448. ePT_VG_sBGRX_8888,
  449. ePT_VG_sBGRA_8888,
  450. ePT_VG_sBGRA_8888_PRE,
  451. ePT_VG_sBGR_565,
  452. ePT_VG_sBGRA_5551,
  453. ePT_VG_sBGRA_4444,
  454. ePT_VG_lBGRX_8888,
  455. ePT_VG_lBGRA_8888,
  456. ePT_VG_lBGRA_8888_PRE,
  457. /* {A,X}BGR channel ordering */
  458. ePT_VG_sXBGR_8888,
  459. ePT_VG_sABGR_8888 ,
  460. ePT_VG_sABGR_8888_PRE,
  461. ePT_VG_sABGR_1555,
  462. ePT_VG_sABGR_4444,
  463. ePT_VG_lXBGR_8888,
  464. ePT_VG_lABGR_8888,
  465. ePT_VG_lABGR_8888_PRE,
  466. // max cap for iterating
  467. END_OF_PIXEL_TYPES,
  468. MGLPT_NOTYPE = 0xffffffff
  469. };
  470. /*****************************************************************************
  471. * Legacy constants (V1/V2)
  472. *****************************************************************************/
  473. const PVRTuint32 PVRTEX_MIPMAP = (1<<8); ///< Has mip map levels. DEPRECATED.
  474. const PVRTuint32 PVRTEX_TWIDDLE = (1<<9); ///< Is twiddled. DEPRECATED.
  475. const PVRTuint32 PVRTEX_BUMPMAP = (1<<10); ///< Has normals encoded for a bump map. DEPRECATED.
  476. const PVRTuint32 PVRTEX_TILING = (1<<11); ///< Is bordered for tiled pvr. DEPRECATED.
  477. const PVRTuint32 PVRTEX_CUBEMAP = (1<<12); ///< Is a cubemap/skybox. DEPRECATED.
  478. const PVRTuint32 PVRTEX_FALSEMIPCOL = (1<<13); ///< Are there false coloured MIP levels. DEPRECATED.
  479. const PVRTuint32 PVRTEX_VOLUME = (1<<14); ///< Is this a volume texture. DEPRECATED.
  480. const PVRTuint32 PVRTEX_ALPHA = (1<<15); ///< v2.1. Is there transparency info in the texture. DEPRECATED.
  481. const PVRTuint32 PVRTEX_VERTICAL_FLIP = (1<<16); ///< v2.1. Is the texture vertically flipped. DEPRECATED.
  482. const PVRTuint32 PVRTEX_PIXELTYPE = 0xff; ///< Pixel type is always in the last 16bits of the flags. DEPRECATED.
  483. const PVRTuint32 PVRTEX_IDENTIFIER = 0x21525650; ///< The pvr identifier is the characters 'P','V','R'. DEPRECATED.
  484. const PVRTuint32 PVRTEX_V1_HEADER_SIZE = 44; ///< Old header size was 44 for identification purposes. DEPRECATED.
  485. const PVRTuint32 PVRTC2_MIN_TEXWIDTH = 16; ///< DEPRECATED.
  486. const PVRTuint32 PVRTC2_MIN_TEXHEIGHT = 8; ///< DEPRECATED.
  487. const PVRTuint32 PVRTC4_MIN_TEXWIDTH = 8; ///< DEPRECATED.
  488. const PVRTuint32 PVRTC4_MIN_TEXHEIGHT = 8; ///< DEPRECATED.
  489. const PVRTuint32 ETC_MIN_TEXWIDTH = 4; ///< DEPRECATED.
  490. const PVRTuint32 ETC_MIN_TEXHEIGHT = 4; ///< DEPRECATED.
  491. const PVRTuint32 DXT_MIN_TEXWIDTH = 4; ///< DEPRECATED.
  492. const PVRTuint32 DXT_MIN_TEXHEIGHT = 4; ///< DEPRECATED.
  493. /****************************************************************************
  494. ** Functions
  495. ****************************************************************************/
  496. /*!***************************************************************************
  497. @fn PVRTTextureCreate
  498. @param[in] w Size of the texture
  499. @param[in] h Size of the texture
  500. @param[in] wMin Minimum size of a texture level
  501. @param[in] hMin Minimum size of a texture level
  502. @param[in] nBPP Bits per pixel of the format
  503. @param[in] bMIPMap Create memory for MIP-map levels also?
  504. @return Allocated texture memory (must be free()d)
  505. @brief Creates a PVRTextureHeaderV3 structure, including room for
  506. the specified texture, in memory.
  507. *****************************************************************************/
  508. PVRTextureHeaderV3 *PVRTTextureCreate(
  509. unsigned int w,
  510. unsigned int h,
  511. const unsigned int wMin,
  512. const unsigned int hMin,
  513. const unsigned int nBPP,
  514. const bool bMIPMap);
  515. /*!***************************************************************************
  516. @fn PVRTTextureTile
  517. @param[in,out] pOut The tiled texture in system memory
  518. @param[in] pIn The source texture
  519. @param[in] nRepeatCnt Number of times to repeat the source texture
  520. @brief Allocates and fills, in system memory, a texture large enough
  521. to repeat the source texture specified number of times.
  522. *****************************************************************************/
  523. void PVRTTextureTile(
  524. PVRTextureHeaderV3 **pOut,
  525. const PVRTextureHeaderV3 * const pIn,
  526. const int nRepeatCnt);
  527. /****************************************************************************
  528. ** Internal Functions
  529. ****************************************************************************/
  530. //Preprocessor definitions to generate a pixelID for use when consts are needed. For example - switch statements. These should be evaluated by the compiler rather than at run time - assuming that arguments are all constant.
  531. //Generate a 4 channel PixelID.
  532. #define PVRTGENPIXELID4(C1Name, C2Name, C3Name, C4Name, C1Bits, C2Bits, C3Bits, C4Bits) ( ( (PVRTuint64)C1Name) + ( (PVRTuint64)C2Name<<8) + ( (PVRTuint64)C3Name<<16) + ( (PVRTuint64)C4Name<<24) + ( (PVRTuint64)C1Bits<<32) + ( (PVRTuint64)C2Bits<<40) + ( (PVRTuint64)C3Bits<<48) + ( (PVRTuint64)C4Bits<<56) )
  533. //Generate a 1 channel PixelID.
  534. #define PVRTGENPIXELID3(C1Name, C2Name, C3Name, C1Bits, C2Bits, C3Bits)( PVRTGENPIXELID4(C1Name, C2Name, C3Name, 0, C1Bits, C2Bits, C3Bits, 0) )
  535. //Generate a 2 channel PixelID.
  536. #define PVRTGENPIXELID2(C1Name, C2Name, C1Bits, C2Bits) ( PVRTGENPIXELID4(C1Name, C2Name, 0, 0, C1Bits, C2Bits, 0, 0) )
  537. //Generate a 3 channel PixelID.
  538. #define PVRTGENPIXELID1(C1Name, C1Bits) ( PVRTGENPIXELID4(C1Name, 0, 0, 0, C1Bits, 0, 0, 0))
  539. //Forward declaration of CPVRTMap.
  540. template <typename KeyType, typename DataType>
  541. class CPVRTMap;
  542. /*!***********************************************************************
  543. @fn PVRTGetBitsPerPixel
  544. @param[in] u64PixelFormat A PVR Pixel Format ID.
  545. @return const PVRTuint32 Number of bits per pixel.
  546. @brief Returns the number of bits per pixel in a PVR Pixel Format
  547. identifier.
  548. *************************************************************************/
  549. PVRTuint32 PVRTGetBitsPerPixel(PVRTuint64 u64PixelFormat);
  550. /*!***********************************************************************
  551. @fn PVRTGetFormatMinDims
  552. @param[in] u64PixelFormat A PVR Pixel Format ID.
  553. @param[in,out] minX Returns the minimum width.
  554. @param[in,out] minY Returns the minimum height.
  555. @param[in,out] minZ Returns the minimum depth.
  556. @brief Gets the minimum dimensions (x,y,z) for a given pixel format.
  557. *************************************************************************/
  558. void PVRTGetFormatMinDims(PVRTuint64 u64PixelFormat, PVRTuint32 &minX, PVRTuint32 &minY, PVRTuint32 &minZ);
  559. /*!***********************************************************************
  560. @fn PVRTConvertOldTextureHeaderToV3
  561. @param[in] LegacyHeader Legacy header for conversion.
  562. @param[in,out] NewHeader New header to output into.
  563. @param[in,out] pMetaData MetaData Map to output into.
  564. @brief Converts a legacy texture header (V1 or V2) to a current
  565. generation header (V3)
  566. *************************************************************************/
  567. void PVRTConvertOldTextureHeaderToV3(const PVR_Texture_Header* LegacyHeader, PVRTextureHeaderV3& NewHeader, CPVRTMap<PVRTuint32, CPVRTMap<PVRTuint32,MetaDataBlock> >* pMetaData);
  568. /*!***********************************************************************
  569. @fn PVRTMapLegacyTextureEnumToNewFormat
  570. @param[in] OldFormat Legacy Enumeration Value
  571. @param[in,out] newType New PixelType identifier.
  572. @param[in,out] newCSpace New ColourSpace
  573. @param[in,out] newChanType New Channel Type
  574. @param[in,out] isPreMult Whether format is pre-multiplied
  575. @brief Maps a legacy enumeration value to the new PVR3 style format.
  576. *************************************************************************/
  577. void PVRTMapLegacyTextureEnumToNewFormat(PVRTPixelType OldFormat, PVRTuint64& newType, EPVRTColourSpace& newCSpace, EPVRTVariableType& newChanType, bool& isPreMult);
  578. /*!***************************************************************************
  579. @fn PVRTTextureLoadTiled
  580. @param[in,out] pDst Texture to place the tiled data
  581. @param[in] nWidthDst Width of destination texture
  582. @param[in] nHeightDst Height of destination texture
  583. @param[in] pSrc Texture to tile
  584. @param[in] nWidthSrc Width of source texture
  585. @param[in] nHeightSrc Height of source texture
  586. @param[in] nElementSize Bytes per pixel
  587. @param[in] bTwiddled True if the data is twiddled
  588. @brief Needed by PVRTTextureTile() in the various PVRTTextureAPIs
  589. *****************************************************************************/
  590. void PVRTTextureLoadTiled(
  591. PVRTuint8 * const pDst,
  592. const unsigned int nWidthDst,
  593. const unsigned int nHeightDst,
  594. const PVRTuint8 * const pSrc,
  595. const unsigned int nWidthSrc,
  596. const unsigned int nHeightSrc,
  597. const unsigned int nElementSize,
  598. const bool bTwiddled);
  599. /*!***************************************************************************
  600. @fn PVRTTextureTwiddle
  601. @param[out] a Twiddled value
  602. @param[in] u Coordinate axis 0
  603. @param[in] v Coordinate axis 1
  604. @brief Combine a 2D coordinate into a twiddled value
  605. *****************************************************************************/
  606. void PVRTTextureTwiddle(unsigned int &a, const unsigned int u, const unsigned int v);
  607. /*!***************************************************************************
  608. @fn PVRTTextureDeTwiddle
  609. @param[out] u Coordinate axis 0
  610. @param[out] v Coordinate axis 1
  611. @param[in] a Twiddled value
  612. @brief Extract 2D coordinates from a twiddled value.
  613. *****************************************************************************/
  614. void PVRTTextureDeTwiddle(unsigned int &u, unsigned int &v, const unsigned int a);
  615. /*!***********************************************************************
  616. @fn PVRTGetTextureDataSize
  617. @param[in] sTextureHeader Specifies the texture header.
  618. @param[in] iMipLevel Specifies a mip level to check, 'PVRTEX_ALLMIPLEVELS'
  619. can be passed to get the size of all MIP levels.
  620. @param[in] bAllSurfaces Size of all surfaces is calculated if true,
  621. only a single surface if false.
  622. @param[in] bAllFaces Size of all faces is calculated if true,
  623. only a single face if false.
  624. @return PVRTuint32 Size in BYTES of the specified texture area.
  625. @brief Gets the size in BYTES of the texture, given various input
  626. parameters. User can retrieve the size of either all
  627. surfaces or a single surface, all faces or a single face and
  628. all MIP-Maps or a single specified MIP level.
  629. *************************************************************************/
  630. PVRTuint32 PVRTGetTextureDataSize(PVRTextureHeaderV3 sTextureHeader, PVRTint32 iMipLevel=PVRTEX_ALLMIPLEVELS, bool bAllSurfaces = true, bool bAllFaces = true);
  631. #endif /* _PVRTTEXTURE_H_ */
  632. /*****************************************************************************
  633. End of file (PVRTTexture.h)
  634. *****************************************************************************/