PVRTextureHeader.h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539
  1. /*!***********************************************************************
  2. @file PVRTextureHeader.h
  3. @copyright Copyright (c) Imagination Technologies Limited.
  4. @brief Texture header methods.
  5. @details Includes pixel and channel type methods, size retrieval and
  6. dimension manipulation. As well as set and get methods for
  7. BumpMaps, Meta Data and cube map order.
  8. *************************************************************************/
  9. #ifndef _PVRTEXTURE_HEADER_H
  10. #define _PVRTEXTURE_HEADER_H
  11. #include "PVRTextureDefines.h"
  12. #include "PVRTextureFormat.h"
  13. #include "PVRTString.h"
  14. #include "PVRTMap.h"
  15. namespace pvrtexture
  16. {
  17. /*!***********************************************************************
  18. @class CPVRTextureHeader
  19. @brief Wrapper class for PVRTextureHeaderV3, adds 'smart' accessor functions.
  20. *************************************************************************/
  21. class PVR_DLL CPVRTextureHeader
  22. {
  23. protected:
  24. PVRTextureHeaderV3 m_sHeader; //!< Texture header as laid out in a file.
  25. CPVRTMap<uint32, CPVRTMap<uint32,MetaDataBlock> > m_MetaData; //!< Map of all the meta data stored for a texture.
  26. public:
  27. // Construction methods for a texture header.
  28. /*!***********************************************************************
  29. @brief Default constructor for a CPVRTextureHeader. Returns an empty header.
  30. @return A new texture header.
  31. *************************************************************************/
  32. CPVRTextureHeader();
  33. /*!***********************************************************************
  34. @brief Creates a new texture header from a PVRTextureHeaderV3,
  35. and appends Meta data if any is supplied.
  36. @param[in] fileHeader PVRTextureHeaderV3
  37. @param[in] metaDataCount Number of Meta data blocks to add
  38. @param[in] metaData Pointer to meta data block
  39. @return A new texture header.
  40. *************************************************************************/
  41. CPVRTextureHeader( PVRTextureHeaderV3 fileHeader,
  42. uint32 metaDataCount=0,
  43. MetaDataBlock* metaData=NULL);
  44. /*!***********************************************************************
  45. @brief Creates a new texture header based on individual header
  46. variables.
  47. @param[in] u64PixelFormat PixelFormat
  48. @param[in] u32Height Texture height
  49. @param[in] u32Width Texture width
  50. @param[in] u32Depth Texture depth
  51. @param[in] u32NumMipMaps Number of MIP Maps
  52. @param[in] u32NumArrayMembers Number of array members
  53. @param[in] u32NumFaces Number of faces
  54. @param[in] eColourSpace Colour space
  55. @param[in] eChannelType Channel type
  56. @param[in] bPreMultiplied Whether or not the texture's colour has been
  57. pre-multiplied by the alpha values
  58. @return A new texture header.
  59. *************************************************************************/
  60. CPVRTextureHeader( uint64 u64PixelFormat,
  61. uint32 u32Height=1,
  62. uint32 u32Width=1,
  63. uint32 u32Depth=1,
  64. uint32 u32NumMipMaps=1,
  65. uint32 u32NumArrayMembers=1,
  66. uint32 u32NumFaces=1,
  67. EPVRTColourSpace eColourSpace=ePVRTCSpacelRGB,
  68. EPVRTVariableType eChannelType=ePVRTVarTypeUnsignedByteNorm,
  69. bool bPreMultiplied=false);
  70. /*!***********************************************************************
  71. @brief Will copy the contents and information of another header into this one.
  72. @param[in] rhs Header to copy.
  73. @return This header.
  74. *************************************************************************/
  75. CPVRTextureHeader& operator=(const CPVRTextureHeader& rhs);
  76. // Accessor Methods for a texture's properties - getters.
  77. /*!***********************************************************************
  78. @brief Gets the file header structure.
  79. @return The file header.
  80. *************************************************************************/
  81. PVRTextureHeaderV3 getFileHeader() const;
  82. /*!***********************************************************************
  83. @brief Gets the 64-bit pixel type ID of the texture.
  84. @return 64-bit pixel type ID.
  85. *************************************************************************/
  86. PixelType getPixelType() const;
  87. /*!***********************************************************************
  88. @brief Gets the bits per pixel of the texture format.
  89. @return Number of bits per pixel.
  90. *************************************************************************/
  91. uint32 getBitsPerPixel() const;
  92. /*!***********************************************************************
  93. @brief Returns the colour space of the texture.
  94. @return enum representing colour space.
  95. *************************************************************************/
  96. EPVRTColourSpace getColourSpace() const;
  97. /*!***********************************************************************
  98. @brief Returns the variable type that the texture's data is stored in.
  99. @return enum representing the type of the texture.
  100. *************************************************************************/
  101. EPVRTVariableType getChannelType() const;
  102. /*!***********************************************************************
  103. @brief Gets the width of the user specified MIP-Map
  104. level for the texture
  105. @param[in] uiMipLevel MIP level that user is interested in.
  106. @return Width of the specified MIP-Map level.
  107. *************************************************************************/
  108. uint32 getWidth(uint32 uiMipLevel=PVRTEX_TOPMIPLEVEL) const;
  109. /*!***********************************************************************
  110. @brief Gets the height of the user specified MIP-Map
  111. level for the texture
  112. @param[in] uiMipLevel MIP level that user is interested in.
  113. @return Height of the specified MIP-Map level.
  114. *************************************************************************/
  115. uint32 getHeight(uint32 uiMipLevel=PVRTEX_TOPMIPLEVEL) const;
  116. /*!***********************************************************************
  117. @brief Gets the depth of the user specified MIP-Map
  118. level for the texture
  119. @param[in] uiMipLevel MIP level that user is interested in.
  120. @return Depth of the specified MIP-Map level.
  121. *************************************************************************/
  122. uint32 getDepth(uint32 uiMipLevel=PVRTEX_TOPMIPLEVEL) const;
  123. /*!***********************************************************************
  124. @brief Gets the size in PIXELS of the texture, given various input
  125. parameters. User can retrieve the total size of either all
  126. surfaces or a single surface, all faces or a single face and
  127. all MIP-Maps or a single specified MIP level. All of these
  128. @param[in] iMipLevel Specifies a MIP level to check,
  129. 'PVRTEX_ALLMIPLEVELS' can be passed to get
  130. the size of all MIP levels.
  131. @param[in] bAllSurfaces Size of all surfaces is calculated if true,
  132. only a single surface if false.
  133. @param[in] bAllFaces Size of all faces is calculated if true,
  134. only a single face if false.
  135. @return Size in PIXELS of the specified texture area.
  136. *************************************************************************/
  137. uint32 getTextureSize(int32 iMipLevel=PVRTEX_ALLMIPLEVELS, bool bAllSurfaces = true, bool bAllFaces = true) const;
  138. /*!***********************************************************************
  139. @brief Gets the size in BYTES of the texture, given various input
  140. parameters. User can retrieve the size of either all
  141. surfaces or a single surface, all faces or a single face
  142. and all MIP-Maps or a single specified MIP level.
  143. @param[in] iMipLevel Specifies a mip level to check,
  144. 'PVRTEX_ALLMIPLEVELS' can be passed to get
  145. the size of all MIP levels.
  146. @param[in] bAllSurfaces Size of all surfaces is calculated if true,
  147. only a single surface if false.
  148. @param[in] bAllFaces Size of all faces is calculated if true,
  149. only a single face if false.
  150. @return Size in BYTES of the specified texture area.
  151. *************************************************************************/
  152. uint32 getDataSize(int32 iMipLevel=PVRTEX_ALLMIPLEVELS, bool bAllSurfaces = true, bool bAllFaces = true) const;
  153. /*!***********************************************************************
  154. @brief Gets the number of array members stored in this texture.
  155. @return Number of array members in this texture.
  156. *************************************************************************/
  157. uint32 getNumArrayMembers() const;
  158. /*!***********************************************************************
  159. @brief Gets the number of MIP-Map levels stored in this texture.
  160. @return Number of MIP-Map levels in this texture.
  161. *************************************************************************/
  162. uint32 getNumMIPLevels() const;
  163. /*!***********************************************************************
  164. @brief Gets the number of faces stored in this texture.
  165. @return Number of faces in this texture.
  166. *************************************************************************/
  167. uint32 getNumFaces() const;
  168. /*!***********************************************************************
  169. @brief Gets the data orientation for this texture.
  170. @param[in] axis EPVRTAxis type specifying the axis to examine.
  171. @return Enum orientation of the axis.
  172. *************************************************************************/
  173. EPVRTOrientation getOrientation(EPVRTAxis axis) const;
  174. /*!***********************************************************************
  175. @brief Returns whether or not the texture is compressed using
  176. PVRTexLib's FILE compression - this is independent of
  177. any texture compression.
  178. @return True if it is file compressed.
  179. *************************************************************************/
  180. bool isFileCompressed() const;
  181. /*!***********************************************************************
  182. @brief Returns whether or not the texture's colour has been
  183. pre-multiplied by the alpha values.
  184. @return True if texture is premultiplied.
  185. *************************************************************************/
  186. bool isPreMultiplied() const;
  187. /*!***********************************************************************
  188. @brief Returns the total size of the meta data stored in the header.
  189. This includes the size of all information stored in all MetaDataBlocks.
  190. @return Size, in bytes, of the meta data stored in the header.
  191. *************************************************************************/
  192. uint32 getMetaDataSize() const;
  193. /*!***********************************************************************
  194. @brief Gets the OpenGL equivalent values of internal format, format
  195. and type for this texture. This will return any supported
  196. OpenGL texture values, it is up to the user to decide if
  197. these are valid for their current platform.
  198. @param[in,out] internalformat Internal format
  199. @param[in,out] format Format
  200. @param[in,out] type Type
  201. *************************************************************************/
  202. void getOGLFormat(uint32& internalformat, uint32& format, uint32& type) const;
  203. /*!***********************************************************************
  204. @brief Gets the OpenGLES equivalent values of internal format,
  205. format and type for this texture. This will return any
  206. supported OpenGLES texture values, it is up to the user
  207. to decide if these are valid for their current platform.
  208. @param[in,out] internalformat Internal format
  209. @param[in,out] format Format
  210. @param[in,out] type Type
  211. *************************************************************************/
  212. void getOGLESFormat(uint32& internalformat, uint32& format, uint32& type) const;
  213. /*!***********************************************************************
  214. @brief Gets the D3DFormat (up to DirectX 9 and Direct 3D Mobile)
  215. equivalent values for this texture. This will return any
  216. supported D3D texture formats, it is up to the user to
  217. decide if this is valid for their current platform.
  218. @return D3D format, represented by an uint32.
  219. *************************************************************************/
  220. uint32 getD3DFormat() const;
  221. /*!***********************************************************************
  222. @brief Gets the DXGIFormat (DirectX 10 onward) equivalent values
  223. for this texture. This will return any supported DX texture
  224. formats, it is up to the user to decide if this is valid
  225. for their current platform.
  226. @return GXGIFormat, represented by a uint32.
  227. *************************************************************************/
  228. uint32 getDXGIFormat() const;
  229. // Accessor Methods for a texture's properties - setters.
  230. /*!***********************************************************************
  231. @brief Sets the pixel format for this texture.
  232. @param[in] uPixelFormat The format of the pixel.
  233. *************************************************************************/
  234. void setPixelFormat(PixelType uPixelFormat);
  235. /*!***********************************************************************
  236. @brief Sets the colour space for this texture. Default is lRGB.
  237. @param[in] eColourSpace A colour space enum.
  238. *************************************************************************/
  239. void setColourSpace(EPVRTColourSpace eColourSpace);
  240. /*!***********************************************************************
  241. @brief Sets the variable type for the channels in this texture.
  242. @param[in] eVarType A variable type enum.
  243. *************************************************************************/
  244. void setChannelType(EPVRTVariableType eVarType);
  245. /*!***********************************************************************
  246. @brief Sets the format of the texture to PVRTexLib's internal
  247. representation of the OGL format.
  248. @param[in,out] internalformat Internal format
  249. @param[in,out] format Format
  250. @param[in,out] type Type
  251. @return True if successful.
  252. *************************************************************************/
  253. bool setOGLFormat(const uint32& internalformat, const uint32& format, const uint32& type);
  254. /*!***********************************************************************
  255. @brief Sets the format of the texture to PVRTexLib's internal
  256. representation of the OGLES format.
  257. @param[in,out] internalformat Internal format
  258. @param[in,out] format Format
  259. @param[in,out] type Type
  260. @return True if successful.
  261. *************************************************************************/
  262. bool setOGLESFormat(const uint32& internalformat, const uint32& format, const uint32& type);
  263. /*!***********************************************************************
  264. @brief Sets the format of the texture to PVRTexLib's internal
  265. representation of the D3D format.
  266. @return True if successful.
  267. *************************************************************************/
  268. bool setD3DFormat(const uint32& DWORD_D3D_FORMAT);
  269. /*!***********************************************************************
  270. @brief Sets the format of the texture to PVRTexLib's internal
  271. representation of the DXGI format.
  272. @return True if successful.
  273. *************************************************************************/
  274. bool setDXGIFormat(const uint32& DWORD_DXGI_FORMAT);
  275. /*!***********************************************************************
  276. @brief Sets the width.
  277. @param[in] newWidth The new width.
  278. *************************************************************************/
  279. void setWidth(uint32 newWidth);
  280. /*!***********************************************************************
  281. @brief Sets the height.
  282. @param[in] newHeight The new height.
  283. *************************************************************************/
  284. void setHeight(uint32 newHeight);
  285. /*!***********************************************************************
  286. @brief Sets the depth.
  287. @param[in] newDepth The new depth.
  288. *************************************************************************/
  289. void setDepth(uint32 newDepth);
  290. /*!***********************************************************************
  291. @brief Sets the depth.
  292. @param[in] newNumMembers The new number of members in this array.
  293. *************************************************************************/
  294. void setNumArrayMembers(uint32 newNumMembers);
  295. /*!***********************************************************************
  296. @brief Sets the number of MIP-Map levels in this texture.
  297. @param[in] newNumMIPLevels New number of MIP-Map levels.
  298. *************************************************************************/
  299. void setNumMIPLevels(uint32 newNumMIPLevels);
  300. /*!***********************************************************************
  301. @brief Sets the number of faces stored in this texture.
  302. @param[in] newNumFaces New number of faces for this texture.
  303. *************************************************************************/
  304. void setNumFaces(uint32 newNumFaces);
  305. /*!***********************************************************************
  306. @brief Sets the data orientation for a given axis in this texture.
  307. @param[in] eAxisOrientation Enum specifying axis and orientation.
  308. *************************************************************************/
  309. void setOrientation(EPVRTOrientation eAxisOrientation);
  310. /*!***********************************************************************
  311. @brief Sets whether or not the texture is compressed using
  312. PVRTexLib's FILE compression - this is independent of
  313. any texture compression. Currently unsupported.
  314. @param[in] isFileCompressed Sets file compression to true/false.
  315. *************************************************************************/
  316. void setIsFileCompressed(bool isFileCompressed);
  317. /*!***********************************************************************
  318. @brief Sets whether or not the texture's colour has been
  319. pre-multiplied by the alpha values.
  320. @return isPreMultiplied Sets if texture is premultiplied.
  321. *************************************************************************/
  322. void setIsPreMultiplied(bool isPreMultiplied);
  323. // Meta Data functions - Getters.
  324. /*!***********************************************************************
  325. @brief Returns whether the texture is a bump map or not.
  326. @return True if the texture is a bump map.
  327. *************************************************************************/
  328. bool isBumpMap() const;
  329. /*!***********************************************************************
  330. @brief Gets the bump map scaling value for this texture.
  331. @details If the texture is not a bump map, 0.0f is returned. If the
  332. texture is a bump map but no meta data is stored to
  333. specify its scale, then 1.0f is returned.
  334. @return Returns the bump map scale value as a float.
  335. *************************************************************************/
  336. float getBumpMapScale() const;
  337. /*!***********************************************************************
  338. @brief Gets the bump map channel order relative to rgba.
  339. @details For example, an RGB texture with bumps mapped to XYZ returns
  340. 'xyz'. A BGR texture with bumps in the order ZYX will also
  341. return 'xyz' as the mapping is the same: R=X, G=Y, B=Z.
  342. If the letter 'h' is present in the string, it means that
  343. the height map has been stored here.
  344. Other characters are possible if the bump map was created
  345. manually, but PVRTexLib will ignore these characters. They
  346. are returned simply for completeness.
  347. @return Bump map order relative to rgba.
  348. *************************************************************************/
  349. CPVRTString getBumpMapOrder() const;
  350. /*!***********************************************************************
  351. @brief Works out the number of possible texture atlas members in
  352. the texture based on the w/h/d and the data size.
  353. @return The number of sub textures defined by meta data.
  354. *************************************************************************/
  355. int getNumTextureAtlasMembers() const;
  356. /*!***********************************************************************
  357. @brief Returns a pointer to the texture atlas data.
  358. @return A pointer directly to the texture atlas data.
  359. *************************************************************************/
  360. const float* getTextureAtlasData() const;
  361. /*!***********************************************************************
  362. @brief Gets the cube map face order.
  363. @details Returned string will be in the form "ZzXxYy" with capitals
  364. representing positive and small letters representing
  365. negative. I.e. Z=Z-Positive, z=Z-Negative.
  366. @return Cube map order string.
  367. *************************************************************************/
  368. CPVRTString getCubeMapOrder() const;
  369. /*!***********************************************************************
  370. @brief Obtains the border size in each dimension for this texture.
  371. @param[in] uiBorderWidth Border width
  372. @param[in] uiBorderHeight Border height
  373. @param[in] uiBorderDepth Border depth
  374. *************************************************************************/
  375. void getBorder(uint32& uiBorderWidth, uint32& uiBorderHeight, uint32& uiBorderDepth) const;
  376. /*!***********************************************************************
  377. @brief Returns a block of meta data from the texture. If the meta
  378. data doesn't exist, a block with data size 0 will be returned.
  379. @param[in] DevFOURCC Four character descriptor representing the
  380. creator of the meta data
  381. @param[in] u32Key Key value representing the type of meta
  382. data stored
  383. @return A copy of the meta data from the texture.
  384. *************************************************************************/
  385. MetaDataBlock getMetaData(uint32 DevFOURCC, uint32 u32Key) const;
  386. /*!***********************************************************************
  387. @brief Returns whether or not the specified meta data exists as
  388. part of this texture header.
  389. @param[in] DevFOURCC Four character descriptor representing the
  390. creator of the meta data
  391. @param[in] u32Key Key value representing the type of meta
  392. data stored
  393. @return True if the specified meta data bock exists
  394. *************************************************************************/
  395. bool hasMetaData(uint32 DevFOURCC, uint32 u32Key) const;
  396. /*!***********************************************************************
  397. @brief A pointer directly to the Meta Data Map, to allow users to read out data.
  398. @return A direct pointer to the MetaData map.
  399. *************************************************************************/
  400. const MetaDataMap* getMetaDataMap() const;
  401. // Meta Data functions - Setters.
  402. /*!***********************************************************************
  403. @brief Sets a texture's bump map data.
  404. @param[in] bumpScale Floating point "height" value to scale the bump map.
  405. @param[in] bumpOrder Up to 4 character string, with values x,y,z,h in
  406. some combination. Not all values need to be present.
  407. Denotes channel order; x,y,z refer to the
  408. corresponding axes, h indicates presence of the
  409. original height map. It is possible to have only some
  410. of these values rather than all. For example if 'h'
  411. is present alone it will be considered a height map.
  412. The values should be presented in RGBA order, regardless
  413. of the texture format, so a zyxh order in a bgra texture
  414. should still be passed as 'xyzh'. Capitals are allowed.
  415. Any character stored here that is not one of x,y,z,h
  416. or a NULL character will be ignored when PVRTexLib
  417. reads the data, but will be preserved. This is useful
  418. if you wish to define a custom data channel for instance.
  419. In these instances PVRTexLib will assume it is simply
  420. colour data.
  421. *************************************************************************/
  422. void setBumpMap(float bumpScale, CPVRTString bumpOrder="xyz");
  423. /*!***********************************************************************
  424. @brief Sets the texture atlas coordinate meta data for later display.
  425. It is up to the user to make sure that this texture atlas
  426. data actually makes sense in the context of the header. It is
  427. suggested that the "generateTextureAtlas" method in the tools
  428. is used to create a texture atlas, manually setting one up is
  429. possible but should be done with care.
  430. @param[in] pAtlasData Pointer to an array of atlas data.
  431. @param[in] dataSize Number of floats that the data pointer contains.
  432. *************************************************************************/
  433. void setTextureAtlas(float* pAtlasData, uint32 dataSize);
  434. /*!***********************************************************************
  435. @brief Sets a texture's bump map data.
  436. @param[in] cubeMapOrder Up to 6 character string, with values
  437. x,X,y,Y,z,Z in some combination. Not all
  438. values need to be present. Denotes face
  439. order; Capitals refer to positive axis
  440. positions and small letters refer to
  441. negative axis positions. E.g. x=X-Negative,
  442. X=X-Positive. It is possible to have only
  443. some of these values rather than all, as
  444. long as they are NULL terminated.
  445. NB: Values past the 6th character are not read.
  446. *************************************************************************/
  447. void setCubeMapOrder(CPVRTString cubeMapOrder="XxYyZz");
  448. /*!***********************************************************************
  449. @brief Sets a texture's border size data. This value is subtracted
  450. from the current texture height/width/depth to get the valid
  451. texture data.
  452. @param[in] uiBorderWidth Border width
  453. @param[in] uiBorderHeight Border height
  454. @param[in] uiBorderDepth Border depth
  455. *************************************************************************/
  456. void setBorder(uint32 uiBorderWidth, uint32 uiBorderHeight, uint32 uiBorderDepth);
  457. /*!***********************************************************************
  458. @brief Adds an arbitrary piece of meta data.
  459. @param[in] MetaBlock Meta data block to be added.
  460. *************************************************************************/
  461. void addMetaData(const MetaDataBlock& MetaBlock);
  462. /*!***********************************************************************
  463. @brief Removes a specified piece of meta data, if it exists.
  464. @param[in] DevFOURCC Four character descriptor representing the
  465. creator of the meta data
  466. @param[in] u32Key Key value representing the type of meta
  467. data stored
  468. *************************************************************************/
  469. void removeMetaData(const uint32& DevFOURCC, const uint32& u32Key);
  470. };
  471. };
  472. #endif