PVRTTexture.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. /******************************************************************************
  2. @File PVRTTexture.h
  3. @Title PVRTTexture
  4. @Version
  5. @Copyright Copyright (C) Imagination Technologies Limited.
  6. @Platform ANSI compatible
  7. @Description Texture loading.
  8. ******************************************************************************/
  9. #ifndef _PVRTTEXTURE_H_
  10. #define _PVRTTEXTURE_H_
  11. #include "PVRTGlobal.h"
  12. /*!***************************************************************************
  13. Macros
  14. *****************************************************************************/
  15. /*!***************************************************************************
  16. Describes the header of a PVR header-texture
  17. *****************************************************************************/
  18. struct PVR_Texture_Header
  19. {
  20. PVRTuint32 dwHeaderSize; /*!< size of the structure */
  21. PVRTuint32 dwHeight; /*!< height of surface to be created */
  22. PVRTuint32 dwWidth; /*!< width of input surface */
  23. PVRTuint32 dwMipMapCount; /*!< number of mip-map levels requested */
  24. PVRTuint32 dwpfFlags; /*!< pixel format flags */
  25. PVRTuint32 dwTextureDataSize; /*!< Total size in bytes */
  26. PVRTuint32 dwBitCount; /*!< number of bits per pixel */
  27. PVRTuint32 dwRBitMask; /*!< mask for red bit */
  28. PVRTuint32 dwGBitMask; /*!< mask for green bits */
  29. PVRTuint32 dwBBitMask; /*!< mask for blue bits */
  30. PVRTuint32 dwAlphaBitMask; /*!< mask for alpha channel */
  31. PVRTuint32 dwPVR; /*!< magic number identifying pvr file */
  32. PVRTuint32 dwNumSurfs; /*!< the number of surfaces present in the pvr */
  33. } ;
  34. /*****************************************************************************
  35. * ENUMS
  36. *****************************************************************************/
  37. enum PixelType
  38. {
  39. MGLPT_ARGB_4444 = 0x00,
  40. MGLPT_ARGB_1555,
  41. MGLPT_RGB_565,
  42. MGLPT_RGB_555,
  43. MGLPT_RGB_888,
  44. MGLPT_ARGB_8888,
  45. MGLPT_ARGB_8332,
  46. MGLPT_I_8,
  47. MGLPT_AI_88,
  48. MGLPT_1_BPP,
  49. MGLPT_VY1UY0,
  50. MGLPT_Y1VY0U,
  51. MGLPT_PVRTC2,
  52. MGLPT_PVRTC4,
  53. MGLPT_PVRTC2_2,
  54. MGLPT_PVRTC2_4,
  55. OGL_RGBA_4444= 0x10,
  56. OGL_RGBA_5551,
  57. OGL_RGBA_8888,
  58. OGL_RGB_565,
  59. OGL_RGB_555,
  60. OGL_RGB_888,
  61. OGL_I_8,
  62. OGL_AI_88,
  63. OGL_PVRTC2,
  64. OGL_PVRTC4,
  65. // OGL_BGRA_8888 extension
  66. OGL_BGRA_8888,
  67. OGL_A_8,
  68. D3D_DXT1 = 0x20,
  69. D3D_DXT2,
  70. D3D_DXT3,
  71. D3D_DXT4,
  72. D3D_DXT5,
  73. D3D_RGB_332,
  74. D3D_AI_44,
  75. D3D_LVU_655,
  76. D3D_XLVU_8888,
  77. D3D_QWVU_8888,
  78. //10 bits per channel
  79. D3D_ABGR_2101010,
  80. D3D_ARGB_2101010,
  81. D3D_AWVU_2101010,
  82. //16 bits per channel
  83. D3D_GR_1616,
  84. D3D_VU_1616,
  85. D3D_ABGR_16161616,
  86. //HDR formats
  87. D3D_R16F,
  88. D3D_GR_1616F,
  89. D3D_ABGR_16161616F,
  90. //32 bits per channel
  91. D3D_R32F,
  92. D3D_GR_3232F,
  93. D3D_ABGR_32323232F,
  94. // Ericsson
  95. ETC_RGB_4BPP,
  96. ETC_RGBA_EXPLICIT,
  97. ETC_RGBA_INTERPOLATED,
  98. // DX10
  99. ePT_DX10_R32G32B32A32_FLOAT= 0x50,
  100. ePT_DX10_R32G32B32A32_UINT ,
  101. ePT_DX10_R32G32B32A32_SINT,
  102. ePT_DX10_R32G32B32_FLOAT,
  103. ePT_DX10_R32G32B32_UINT,
  104. ePT_DX10_R32G32B32_SINT,
  105. ePT_DX10_R16G16B16A16_FLOAT ,
  106. ePT_DX10_R16G16B16A16_UNORM,
  107. ePT_DX10_R16G16B16A16_UINT ,
  108. ePT_DX10_R16G16B16A16_SNORM ,
  109. ePT_DX10_R16G16B16A16_SINT ,
  110. ePT_DX10_R32G32_FLOAT ,
  111. ePT_DX10_R32G32_UINT ,
  112. ePT_DX10_R32G32_SINT ,
  113. ePT_DX10_R10G10B10A2_UNORM ,
  114. ePT_DX10_R10G10B10A2_UINT ,
  115. ePT_DX10_R11G11B10_FLOAT ,
  116. ePT_DX10_R8G8B8A8_UNORM ,
  117. ePT_DX10_R8G8B8A8_UNORM_SRGB ,
  118. ePT_DX10_R8G8B8A8_UINT ,
  119. ePT_DX10_R8G8B8A8_SNORM ,
  120. ePT_DX10_R8G8B8A8_SINT ,
  121. ePT_DX10_R16G16_FLOAT ,
  122. ePT_DX10_R16G16_UNORM ,
  123. ePT_DX10_R16G16_UINT ,
  124. ePT_DX10_R16G16_SNORM ,
  125. ePT_DX10_R16G16_SINT ,
  126. ePT_DX10_R32_FLOAT ,
  127. ePT_DX10_R32_UINT ,
  128. ePT_DX10_R32_SINT ,
  129. ePT_DX10_R8G8_UNORM ,
  130. ePT_DX10_R8G8_UINT ,
  131. ePT_DX10_R8G8_SNORM ,
  132. ePT_DX10_R8G8_SINT ,
  133. ePT_DX10_R16_FLOAT ,
  134. ePT_DX10_R16_UNORM ,
  135. ePT_DX10_R16_UINT ,
  136. ePT_DX10_R16_SNORM ,
  137. ePT_DX10_R16_SINT ,
  138. ePT_DX10_R8_UNORM,
  139. ePT_DX10_R8_UINT,
  140. ePT_DX10_R8_SNORM,
  141. ePT_DX10_R8_SINT,
  142. ePT_DX10_A8_UNORM,
  143. ePT_DX10_R1_UNORM,
  144. ePT_DX10_R9G9B9E5_SHAREDEXP,
  145. ePT_DX10_R8G8_B8G8_UNORM,
  146. ePT_DX10_G8R8_G8B8_UNORM,
  147. ePT_DX10_BC1_UNORM,
  148. ePT_DX10_BC1_UNORM_SRGB,
  149. ePT_DX10_BC2_UNORM,
  150. ePT_DX10_BC2_UNORM_SRGB,
  151. ePT_DX10_BC3_UNORM,
  152. ePT_DX10_BC3_UNORM_SRGB,
  153. ePT_DX10_BC4_UNORM,
  154. ePT_DX10_BC4_SNORM,
  155. ePT_DX10_BC5_UNORM,
  156. ePT_DX10_BC5_SNORM,
  157. //ePT_DX10_B5G6R5_UNORM, // defined but obsolete - won't actually load in DX10
  158. //ePT_DX10_B5G5R5A1_UNORM,
  159. //ePT_DX10_B8G8R8A8_UNORM,
  160. //ePT_DX10_B8G8R8X8_UNORM,
  161. // OpenVG
  162. /* RGB{A,X} channel ordering */
  163. ePT_VG_sRGBX_8888 = 0x90,
  164. ePT_VG_sRGBA_8888,
  165. ePT_VG_sRGBA_8888_PRE,
  166. ePT_VG_sRGB_565,
  167. ePT_VG_sRGBA_5551,
  168. ePT_VG_sRGBA_4444,
  169. ePT_VG_sL_8,
  170. ePT_VG_lRGBX_8888,
  171. ePT_VG_lRGBA_8888,
  172. ePT_VG_lRGBA_8888_PRE,
  173. ePT_VG_lL_8,
  174. ePT_VG_A_8,
  175. ePT_VG_BW_1,
  176. /* {A,X}RGB channel ordering */
  177. ePT_VG_sXRGB_8888,
  178. ePT_VG_sARGB_8888,
  179. ePT_VG_sARGB_8888_PRE,
  180. ePT_VG_sARGB_1555,
  181. ePT_VG_sARGB_4444,
  182. ePT_VG_lXRGB_8888,
  183. ePT_VG_lARGB_8888,
  184. ePT_VG_lARGB_8888_PRE,
  185. /* BGR{A,X} channel ordering */
  186. ePT_VG_sBGRX_8888,
  187. ePT_VG_sBGRA_8888,
  188. ePT_VG_sBGRA_8888_PRE,
  189. ePT_VG_sBGR_565,
  190. ePT_VG_sBGRA_5551,
  191. ePT_VG_sBGRA_4444,
  192. ePT_VG_lBGRX_8888,
  193. ePT_VG_lBGRA_8888,
  194. ePT_VG_lBGRA_8888_PRE,
  195. /* {A,X}BGR channel ordering */
  196. ePT_VG_sXBGR_8888,
  197. ePT_VG_sABGR_8888 ,
  198. ePT_VG_sABGR_8888_PRE,
  199. ePT_VG_sABGR_1555,
  200. ePT_VG_sABGR_4444,
  201. ePT_VG_lXBGR_8888,
  202. ePT_VG_lABGR_8888,
  203. ePT_VG_lABGR_8888_PRE,
  204. // max cap for iterating
  205. END_OF_PIXEL_TYPES,
  206. MGLPT_NOTYPE = 0xff
  207. };
  208. /*****************************************************************************
  209. * constants
  210. *****************************************************************************/
  211. const PVRTuint32 PVRTEX_MIPMAP = (1<<8); // has mip map levels
  212. const PVRTuint32 PVRTEX_TWIDDLE = (1<<9); // is twiddled
  213. const PVRTuint32 PVRTEX_BUMPMAP = (1<<10); // has normals encoded for a bump map
  214. const PVRTuint32 PVRTEX_TILING = (1<<11); // is bordered for tiled pvr
  215. const PVRTuint32 PVRTEX_CUBEMAP = (1<<12); // is a cubemap/skybox
  216. const PVRTuint32 PVRTEX_FALSEMIPCOL = (1<<13); // are there false coloured MIP levels
  217. const PVRTuint32 PVRTEX_VOLUME = (1<<14); // is this a volume texture
  218. const PVRTuint32 PVRTEX_ALPHA = (1<<15); // v2.1 is there transparency info in the texture
  219. const PVRTuint32 PVRTEX_VERTICAL_FLIP = (1<<16); // v2.1 is the texture vertically flipped
  220. const PVRTuint32 PVRTEX_PIXELTYPE = 0xff; // pixel type is always in the last 16bits of the flags
  221. const PVRTuint32 PVRTEX_IDENTIFIER = 0x21525650; // the pvr identifier is the characters 'P','V','R'
  222. const PVRTuint32 PVRTEX_V1_HEADER_SIZE = 44; // old header size was 44 for identification purposes
  223. const PVRTuint32 PVRTC2_MIN_TEXWIDTH = 16;
  224. const PVRTuint32 PVRTC2_MIN_TEXHEIGHT = 8;
  225. const PVRTuint32 PVRTC4_MIN_TEXWIDTH = 8;
  226. const PVRTuint32 PVRTC4_MIN_TEXHEIGHT = 8;
  227. const PVRTuint32 ETC_MIN_TEXWIDTH = 4;
  228. const PVRTuint32 ETC_MIN_TEXHEIGHT = 4;
  229. const PVRTuint32 DXT_MIN_TEXWIDTH = 4;
  230. const PVRTuint32 DXT_MIN_TEXHEIGHT = 4;
  231. /****************************************************************************
  232. ** Functions
  233. ****************************************************************************/
  234. /*!***************************************************************************
  235. @Function PVRTTextureCreate
  236. @Input w Size of the texture
  237. @Input h Size of the texture
  238. @Input wMin Minimum size of a texture level
  239. @Input hMin Minimum size of a texture level
  240. @Input nBPP Bits per pixel of the format
  241. @Input bMIPMap Create memory for MIP-map levels also?
  242. @Return Allocated texture memory (must be free()d)
  243. @Description Creates a PVR_Texture_Header structure, including room for
  244. the specified texture, in memory.
  245. *****************************************************************************/
  246. PVR_Texture_Header *PVRTTextureCreate(
  247. unsigned int w,
  248. unsigned int h,
  249. const unsigned int wMin,
  250. const unsigned int hMin,
  251. const unsigned int nBPP,
  252. const bool bMIPMap);
  253. /*!***************************************************************************
  254. @Function PVRTTextureTile
  255. @Modified pOut The tiled texture in system memory
  256. @Input pIn The source texture
  257. @Input nRepeatCnt Number of times to repeat the source texture
  258. @Description Allocates and fills, in system memory, a texture large enough
  259. to repeat the source texture specified number of times.
  260. *****************************************************************************/
  261. void PVRTTextureTile(
  262. PVR_Texture_Header **pOut,
  263. const PVR_Texture_Header * const pIn,
  264. const int nRepeatCnt);
  265. /****************************************************************************
  266. ** Internal Functions
  267. ****************************************************************************/
  268. /*!***************************************************************************
  269. @Function PVRTTextureLoadTiled
  270. @Modified pDst Texture to place the tiled data
  271. @Input nWidthDst Width of destination texture
  272. @Input nHeightDst Height of destination texture
  273. @Input pSrc Texture to tile
  274. @Input nWidthSrc Width of source texture
  275. @Input nHeightSrc Height of source texture
  276. @Input nElementSize Bytes per pixel
  277. @Input bTwiddled True if the data is twiddled
  278. @Description Needed by PVRTTextureTile() in the various PVRTTextureAPIs
  279. *****************************************************************************/
  280. void PVRTTextureLoadTiled(
  281. PVRTuint8 * const pDst,
  282. const unsigned int nWidthDst,
  283. const unsigned int nHeightDst,
  284. const PVRTuint8 * const pSrc,
  285. const unsigned int nWidthSrc,
  286. const unsigned int nHeightSrc,
  287. const unsigned int nElementSize,
  288. const bool bTwiddled);
  289. /*!***************************************************************************
  290. @Function PVRTTextureTwiddle
  291. @Output a Twiddled value
  292. @Input u Coordinate axis 0
  293. @Input v Coordinate axis 1
  294. @Description Combine a 2D coordinate into a twiddled value
  295. *****************************************************************************/
  296. void PVRTTextureTwiddle(unsigned int &a, const unsigned int u, const unsigned int v);
  297. /*!***************************************************************************
  298. @Function PVRTTextureDeTwiddle
  299. @Output u Coordinate axis 0
  300. @Output v Coordinate axis 1
  301. @Input a Twiddled value
  302. @Description Extract 2D coordinates from a twiddled value.
  303. *****************************************************************************/
  304. void PVRTTextureDeTwiddle(unsigned int &u, unsigned int &v, const unsigned int a);
  305. #endif /* _PVRTTEXTURE_H_ */
  306. /*****************************************************************************
  307. End of file (PVRTTexture.h)
  308. *****************************************************************************/