CPVRTexture.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. /******************************************************************************
  2. @File CPVRTexture.h
  3. @Title Console Log
  4. @Version @Version
  5. @Copyright Copyright (C) Imagination Technologies Limited.
  6. @Platform ANSI
  7. @Description Class that holds data and descriptive information for PVR textures.
  8. ******************************************************************************/
  9. #ifndef CPVRTEXTURE_H
  10. #define CPVRTEXTURE_H
  11. #include "CPVRTextureHeader.h"
  12. #include "CPVRTextureData.h"
  13. namespace pvrtexlib
  14. {
  15. #ifdef __APPLE__
  16. /* The classes below are exported */
  17. #pragma GCC visibility push(default)
  18. #endif
  19. class PVR_DLL CPVRTexture
  20. {
  21. public:
  22. /*******************************************************************************
  23. * Function Name : CPVRTexture Constructors
  24. * Description : default
  25. * from CPVRTextureHeader but no data
  26. * from CPVRTextureHeader/CPVRTextureData pair
  27. * from Header with blank data
  28. * create Header for raw data
  29. * from file
  30. * from PVR data with embedded header (contents of PVR file)
  31. *******************************************************************************/
  32. CPVRTexture(); // default constructor
  33. CPVRTexture(CPVRTextureHeader& sHeader); // from CPVRTextureHeader but no data
  34. CPVRTexture(CPVRTextureHeader& sHeader, CPVRTextureData& sData);// from CPVRTextureHeader/CPVRTextureData pair
  35. CPVRTexture(
  36. const unsigned int u32Width, // create header info with no data
  37. const unsigned int u32Height,
  38. const unsigned int u32MipMapCount,
  39. const unsigned int u32NumSurfaces,
  40. const bool bBorder,
  41. const bool bTwiddled,
  42. const bool bCubeMap,
  43. const bool bVolume,
  44. const bool bFalseMips,
  45. const bool bAlpha,
  46. const bool bFlipped,
  47. const PixelType ePixelType,
  48. const float fNormalMap);
  49. CPVRTexture(
  50. const unsigned int u32Width, // create header info for raw data
  51. const unsigned int u32Height,
  52. const unsigned int u32MipMapCount,
  53. const unsigned int u32NumSurfaces,
  54. const bool bBorder,
  55. const bool bTwiddled,
  56. const bool bCubeMap,
  57. const bool bVolume,
  58. const bool bFalseMips,
  59. const bool bAlpha,
  60. const bool bFlipped,
  61. const PixelType ePixelType,
  62. const float fNormalMap,
  63. uint8 *pPixelData);
  64. // Easy constructor
  65. CPVRTexture(
  66. const unsigned int u32Width,
  67. const unsigned int u32Height,
  68. const unsigned int u32MipMapCount=0,
  69. const unsigned int u32NumSurfaces=1,
  70. const PixelType ePixelType=DX10_R8G8B8A8_UNORM,
  71. const float fNormalMap=1.0f,
  72. const bool bBorder=false,
  73. const bool bTwiddled=false,
  74. const bool bCubeMap=false,
  75. const bool bVolume=false,
  76. const bool bFalseMips=false,
  77. const bool bAlpha=false,
  78. const bool bFlipped=false,
  79. uint8 *pPixelData=NULL);
  80. CPVRTexture(const char* const pszFilename); // from file depending on extension passed
  81. CPVRTexture(const uint8* const pPVRData); // from PVR data with embedded header (contents of PVR file)
  82. /*******************************************************************************
  83. * Function Name : getHeader
  84. * Description : returns the CPVRTextureHeader instance from this instance
  85. * note this returns a reference
  86. *******************************************************************************/
  87. CPVRTextureHeader& getHeader();
  88. /*******************************************************************************
  89. * Function Name : getData
  90. * Description : returns the CPVRTextureData instance from this instance
  91. * note this returns a reference
  92. *******************************************************************************/
  93. CPVRTextureData& getData();
  94. /*******************************************************************************
  95. * : Accessor functions for header values
  96. * Description : Correspond to the values held in a pvr texture file.
  97. * : PixelType is the actual texture format
  98. * : Width is the width of the top image of the texture
  99. * : Height is the height of the top image of the texture
  100. * : MipMapCount is the number of MIP-maps present: 0 = top level
  101. *******************************************************************************/
  102. void setData(uint8* pData);
  103. PixelType getPixelType();
  104. void setPixelType(PixelType ePixelType);
  105. unsigned int getPrecMode() const;
  106. unsigned int getWidth() const;
  107. unsigned int getMipWidth(unsigned int iMipMapNum) const;
  108. void setWidth(unsigned int u32Width);
  109. unsigned int getHeight() const;
  110. unsigned int getMipHeight(unsigned int iMipMapNum) const;
  111. void setHeight(unsigned int u32Height);
  112. unsigned int getMipMapCount() const;
  113. void setMipMapCount(unsigned int u32MipMapCount);
  114. bool hasMips() const;
  115. unsigned int getNumSurfaces() const;
  116. void setNumSurfaces(unsigned int u32NumSurfaces);
  117. unsigned int getSurfaceSize() const;
  118. unsigned int getSurfaceSizeInPixels() const;
  119. unsigned int getMIPSize(int mipNumber) const;
  120. unsigned int getMIPSizeInPixels(int mipNumber) const;
  121. /*******************************************************************************
  122. * : Accessor functions for flag values
  123. * Description : Border: a border around the texture
  124. * in order to avoid artifacts. See the PVRTC document for more info
  125. * Twiddled: Morton order for the texture
  126. * CubeMap: does the texture constitute 6 surfaces facing a cube
  127. * Volume: is this a volume texture
  128. * NormalMap: a value of 0.0f indicates not a Normal map texture
  129. * a non-zero value is taken as the height factor
  130. * when calculating the normal vectors
  131. * FalseMips: artificially coloured MIP-map levels
  132. *******************************************************************************/
  133. bool isBordered() const;
  134. void setBorder(bool bBorder);
  135. bool isTwiddled() const;
  136. void setTwiddled(bool bTwiddled);
  137. bool isCubeMap() const;
  138. void setCubeMap(bool bCubeMap);
  139. bool isVolume() const;
  140. void setVolume(const bool bVolume);
  141. float getNormalMap() const;
  142. void setNormalMap(const float fNormalMap);
  143. bool isNormalMap() const;
  144. bool hasFalseMips() const;
  145. void setFalseMips(const bool bFalseMips);
  146. bool hasAlpha() const;
  147. void setAlpha(const bool bAlpha);
  148. bool isFlipped() const;
  149. void setFlipped(const bool bFlipped);
  150. /*******************************************************************************
  151. * Function Name : convertToPrecMode
  152. * Description : Converts the data to float/uint16/uint8 from uint8/uint16/float
  153. * expanding/contracting the buffer.
  154. * If the data is not uint8/uint16/float PVRTHROWs
  155. *******************************************************************************/
  156. void convertToPrecMode(const E_PRECMODE ePrecMode);
  157. /*******************************************************************************
  158. * Function Name : SwapChannels
  159. * Description : Swaps the two specified channels.
  160. * If the data is not uint8/uint16/uint32/float PVRTHROWs
  161. *******************************************************************************/
  162. void SwapChannels(const E_COLOUR_CHANNEL e32ChannelA, const E_COLOUR_CHANNEL e32ChannelB);
  163. /*******************************************************************************
  164. * Function Name : SetChannels
  165. * Description : Sets channelTo in this texture to the channelFrom in the new texture.
  166. * If the data is not uint8/uint16/uint32/float PVRTHROWs
  167. *******************************************************************************/
  168. void setChannel(
  169. const unsigned int eChannelTo,
  170. const unsigned int eChannelFrom,
  171. CPVRTexture& sSourceTexture,
  172. const unsigned int u32SourceSurfaceNum=0,
  173. const unsigned int u32DestSurfaceNum=0,
  174. const int i32MipNum=-1);
  175. /*******************************************************************************
  176. * Function Name : SetChannels
  177. * Description : Sets channelTo in this texture to the specified value
  178. * If the data is not uint8/uint16/uint32/float PVRTHROWs
  179. *******************************************************************************/
  180. void setChannel(
  181. const unsigned int eChannelTo,
  182. const unsigned int newValue=255,
  183. const unsigned int u32DestSurfaceNum=0,
  184. const int i32MipNum=-1);
  185. /*******************************************************************************
  186. * Function Name : getSurfaceData
  187. * Description : Returns a pointer to the surface specified, NULL if it doesn't exist
  188. *******************************************************************************/
  189. uint8* getSurfaceData(unsigned int u32SurfaceNum);
  190. /*******************************************************************************
  191. * Function Name : Append
  192. * Description : Appends a texture to the current one if possible. If the current
  193. * texture has no surfaces then acts like a copy assignment
  194. *******************************************************************************/
  195. void append(CPVRTexture& sTexture);
  196. /*******************************************************************************
  197. * Function Name : RGBToAlpha
  198. * Description : Adds alpha to a texture from the RGB data of the other texture
  199. *******************************************************************************/
  200. void RGBToAlpha( CPVRTexture& sAlphaTexture,
  201. const unsigned int u32DestSurfaceNum = 0,
  202. const unsigned int u32SourceSurfaceNum = 0 );
  203. /*******************************************************************************
  204. * Function Name : writeToFile
  205. * Description : writes to a file depending on the extension of the file path passed.
  206. *******************************************************************************/
  207. size_t writeToFile(const char* const strFilename)const ;
  208. /*******************************************************************************
  209. * Function Name : writeIncludeFile32Bits
  210. * Description : writes to a C++ compatible header file (u32TextureVersion is currently unimplemented)
  211. *******************************************************************************/
  212. size_t writeIncludeFile32Bits(const char* const pszFilename,
  213. const char* const pszVarName)const ;
  214. private:
  215. CPVRTextureHeader m_sHeader;
  216. CPVRTextureData m_sData;
  217. };
  218. #ifdef __APPLE__
  219. #pragma GCC visibility pop
  220. #endif
  221. }
  222. #endif // CPVRTEXTURE_H
  223. /*****************************************************************************
  224. End of file (PVRTexture.h)
  225. *****************************************************************************/