PVRTexture.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. /*!***********************************************************************
  2. @file PVRTexture.h
  3. @copyright Copyright (c) Imagination Technologies Limited.
  4. @brief Contains methods concerning basic CPVRTexture creation, saving
  5. and data duplication. This is the main class for PVRTexLib.
  6. *************************************************************************/
  7. /*****************************************************************************/
  8. /*! @mainpage PVRTexLib
  9. ******************************************************************************
  10. @section overview Overview
  11. *****************************
  12. PVRTexLib is a library for the management of textures. It occupies the @ref pvrtexture
  13. namespace and allows users to access the PVRTexTool functionality in a library,
  14. for easy integration with existing tool chains.
  15. PVRTexLib contains the facility to:
  16. \li Load and save PVR files.
  17. \li Transcode to and from many different texture formats.
  18. \li Perform a variety of pre-process techniques on decompressed pixel data.
  19. \li Provide information about a texture file loaded by the library.
  20. @section pvrtools PVRTools
  21. *****************************
  22. A number of header files from the PowerVR SDK Tools libraries are present in PVRTexLib:
  23. \li PVRTGlobal.h
  24. \li PVRTError.h
  25. \li PVRTArray.h
  26. \li PVRTMap.h
  27. \li PVRTString.h
  28. \li PVRTTexture.h
  29. These header files are included in the PVRTexLib package so that separate installation
  30. of the tools libraries is not required. If PowerVR Graphics SDK Tools are installed,
  31. documentation for the these files can be found in the ‘Tools’ folder
  32. in the PowerVR Insider SDK directory.
  33. */
  34. #ifndef _PVRTEXTURE_H
  35. #define _PVRTEXTURE_H
  36. #include "PVRTextureDefines.h"
  37. #include "PVRTextureHeader.h"
  38. #include "PVRTString.h"
  39. namespace pvrtexture
  40. {
  41. /*!***********************************************************************
  42. @class CPVRTexture
  43. @brief A full public texture container format, with support for custom
  44. meta-data, and complete, optimised, resource loading code into PVRTools.
  45. *************************************************************************/
  46. class PVR_DLL CPVRTexture : public CPVRTextureHeader
  47. {
  48. public:
  49. // Construction methods for a texture.
  50. /*!***********************************************************************
  51. @brief Creates a new empty texture
  52. @return A new CPVRTexture.
  53. *************************************************************************/
  54. CPVRTexture();
  55. /*!***********************************************************************
  56. @brief Creates a new texture based on a texture header,
  57. pre-allocating the correct amount of memory. If data is
  58. supplied, it will be copied into memory.
  59. @param[in] sHeader Texture header
  60. @param[in] pData Texture data
  61. @return A new CPVRTexture.
  62. *************************************************************************/
  63. CPVRTexture(const CPVRTextureHeader& sHeader, const void* pData=NULL);
  64. /*!***********************************************************************
  65. @brief Creates a new texture from a filepath.
  66. @param[in] szFilePath File path to existing texture
  67. @return A new CPVRTexture.
  68. *************************************************************************/
  69. CPVRTexture(const char* szFilePath);
  70. /*!***********************************************************************
  71. @brief Creates a new texture from a pointer that includes a header
  72. structure, meta data and texture data as laid out in a file.
  73. This functionality is primarily for user-defined file loading.
  74. Header may be any version of pvr.
  75. @param[in] pTexture Pointer to texture data
  76. @return A new CPVRTexture.
  77. *************************************************************************/
  78. CPVRTexture( const void* pTexture );
  79. /*!***********************************************************************
  80. @brief Creates a new texture as a copy of another.
  81. @param[in] texture Texture to copy
  82. @return A new CPVRTexture
  83. *************************************************************************/
  84. CPVRTexture(const CPVRTexture& texture);
  85. /*!***********************************************************************
  86. @brief Deconstructor for CPVRTextures.
  87. *************************************************************************/
  88. ~CPVRTexture();
  89. /*!***********************************************************************
  90. @brief Will copy the contents and information of another texture into this one.
  91. @param[in] rhs Texture to copy
  92. @return This texture.
  93. *************************************************************************/
  94. CPVRTexture& operator=(const CPVRTexture& rhs);
  95. // Texture accessor functions - others are inherited from CPVRTextureHeader.
  96. /*!***********************************************************************
  97. @brief Returns a pointer into the texture's data.
  98. @details It is possible to specify an offset to specific array members,
  99. faces and MIP Map levels.
  100. @param[in] uiMIPLevel Offset to MIP Map levels
  101. @param[in] uiArrayMember Offset to array members
  102. @param[in] uiFaceNumber Offset to face numbers
  103. @return Pointer to a location in the texture.
  104. *************************************************************************/
  105. void* getDataPtr(uint32 uiMIPLevel = 0, uint32 uiArrayMember = 0, uint32 uiFaceNumber = 0) const;
  106. /*!***********************************************************************
  107. @brief Gets the header for this texture, allowing you to create a new
  108. texture based on this one with some changes. Useful for passing
  109. information about a texture without passing all of its data.
  110. @return Returns the header only for this texture.
  111. *************************************************************************/
  112. const CPVRTextureHeader& getHeader() const;
  113. // File io.
  114. /*!***********************************************************************
  115. @brief When writing the texture out to a PVR file, it is often
  116. desirable to pad the meta data so that the start of the
  117. texture data aligns to a given boundary.
  118. @details This function pads to a boundary value equal to "uiPadding".
  119. For example setting uiPadding=8 will align the start of the
  120. texture data to an 8 byte boundary.
  121. Note - this should be called immediately before saving as
  122. the value is worked out based on the current meta data size.
  123. @param[in] uiPadding Padding boundary value
  124. *************************************************************************/
  125. void addPaddingMetaData( uint32 uiPadding );
  126. /*!***********************************************************************
  127. @brief Writes out to a file, given a filename and path.
  128. @details File type will be determined by the extension present in the string.
  129. If no extension is present, PVR format will be selected.
  130. Unsupported formats will result in failure.
  131. @param[in] filepath File path to write to
  132. @return True if the method succeeds.
  133. *************************************************************************/
  134. bool saveFile(const CPVRTString& filepath) const;
  135. /*!***********************************************************************
  136. @brief Writes out to a file, stripping any extensions specified
  137. and appending .pvr. This function is for legacy support only
  138. and saves out to PVR Version 2 file. The target api must be
  139. specified in order to save to this format.
  140. @param[in] filepath File path to write to
  141. @param[in] eApi Target API
  142. @return True if the method succeeds.
  143. *************************************************************************/
  144. bool saveFileLegacyPVR(const CPVRTString& filepath, ELegacyApi eApi) const;
  145. /*!***********************************************************************
  146. @brief Saves an ASTC File.
  147. @param[in] filepath File path to write to
  148. @return True if the method succeeds.
  149. *************************************************************************/
  150. bool saveASTCFile(const CPVRTString& filepath) const;
  151. private:
  152. size_t m_stDataSize; //!< Size of the texture data.
  153. uint8* m_pTextureData; //!< Pointer to texture data.
  154. // Private IO functions
  155. /*!***********************************************************************
  156. @brief Loads a PVR file.
  157. @param[in] pTextureFile PVR texture file
  158. @return True if the method succeeds.
  159. *************************************************************************/
  160. bool privateLoadPVRFile(FILE* pTextureFile);
  161. /*!***********************************************************************
  162. @brief Saves a PVR File.
  163. @param[in] pTextureFile PVR texture file
  164. @return True if the method succeeds.
  165. *************************************************************************/
  166. bool privateSavePVRFile(FILE* pTextureFile) const;
  167. /*!***********************************************************************
  168. @brief Loads a KTX file.
  169. @param[in] pTextureFile KTX texture file
  170. @return True if the method succeeds.
  171. *************************************************************************/
  172. bool privateLoadKTXFile(FILE* pTextureFile);
  173. /*!***********************************************************************
  174. @brief Saves a KTX File.
  175. @param[in] pTextureFile KTX texture file
  176. @return True if the method succeeds.
  177. *************************************************************************/
  178. bool privateSaveKTXFile(FILE* pTextureFile) const;
  179. /*!***********************************************************************
  180. @brief Loads a DDS file.
  181. @param[in] pTextureFile DDS texture file
  182. @return True if the method succeeds.
  183. *************************************************************************/
  184. bool privateLoadDDSFile(FILE* pTextureFile);
  185. /*!***********************************************************************
  186. @brief Saves a DDS File.
  187. @param[in] pTextureFile DDS texture file
  188. @return True if the method succeeds.
  189. *************************************************************************/
  190. bool privateSaveDDSFile(FILE* pTextureFile) const;
  191. /*!***********************************************************************
  192. @brief Loads an ASTC file.
  193. @param[in] pTextureFile ASTC texture file
  194. @return True if the method succeeds.
  195. *************************************************************************/
  196. bool privateLoadASTCFile(FILE* pTextureFile);
  197. /*!***********************************************************************
  198. @brief Saves an ASTC file.
  199. @param[in] pTextureFile ASTC texture file
  200. @return True if the method succeeds.
  201. *************************************************************************/
  202. bool privateSaveASTCFile(FILE* pTextureFile) const;
  203. //Legacy IO
  204. /*!***********************************************************************
  205. @brief Saves a .h File. Legacy operator
  206. @param[in] pTextureFile PVR texture file
  207. @param[in] filename File path to write to
  208. @return True if the method succeeds.
  209. *************************************************************************/
  210. bool privateSaveCHeaderFile(FILE* pTextureFile, CPVRTString filename) const;
  211. /*!***********************************************************************
  212. @brief Saves a legacy PVR File - Uses version 2 file format.
  213. @param[in] pTextureFile PVR texture file
  214. @param[in] eApi Target API
  215. @return True if the method succeeds.
  216. *************************************************************************/
  217. bool privateSaveLegacyPVRFile(FILE* pTextureFile, ELegacyApi eApi) const;
  218. };
  219. };
  220. #endif //_PVRTEXTURE_H