index.d.ts 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  1. /// <reference path="./global.d.ts" />
  2. import type { BaseTexture } from '@pixi/core';
  3. import { BufferResource } from '@pixi/core';
  4. import type { ExtensionMetadata } from '@pixi/core';
  5. import { FORMATS } from '@pixi/constants';
  6. import type { GLTexture } from '@pixi/core';
  7. import { LoaderResource } from '@pixi/loaders';
  8. import type { Renderer } from '@pixi/core';
  9. import type { Resource } from '@pixi/core';
  10. import { TYPES } from '@pixi/constants';
  11. import { ViewableBuffer } from '@pixi/core';
  12. /**
  13. * Resource that fetches texture data over the network and stores it in a buffer.
  14. * @class
  15. * @extends PIXI.Resource
  16. * @memberof PIXI
  17. */
  18. export declare abstract class BlobResource extends BufferResource {
  19. protected origin: string;
  20. protected buffer: ViewableBuffer;
  21. protected loaded: boolean;
  22. /**
  23. * @param {string} source - the URL of the texture file
  24. * @param {PIXI.IBlobOptions} options
  25. * @param {boolean}[options.autoLoad] - whether to fetch the data immediately;
  26. * you can fetch it later via {@link BlobResource#load}
  27. * @param {boolean}[options.width] - the width in pixels.
  28. * @param {boolean}[options.height] - the height in pixels.
  29. */
  30. constructor(source: string | Uint8Array | Uint32Array | Float32Array, options?: IBlobOptions);
  31. protected onBlobLoaded(_data: ArrayBuffer): void;
  32. /** Loads the blob */
  33. load(): Promise<Resource>;
  34. }
  35. /**
  36. * @ignore
  37. */
  38. export declare type CompressedLevelBuffer = {
  39. levelID: number;
  40. levelWidth: number;
  41. levelHeight: number;
  42. levelBuffer: Uint8Array;
  43. };
  44. export declare type CompressedTextureExtensionRef = keyof CompressedTextureExtensions;
  45. /** Compressed texture extensions */
  46. export declare type CompressedTextureExtensions = {
  47. s3tc?: WEBGL_compressed_texture_s3tc;
  48. s3tc_sRGB: WEBGL_compressed_texture_s3tc_srgb;
  49. etc: any;
  50. etc1: any;
  51. pvrtc: any;
  52. atc: any;
  53. astc: WEBGL_compressed_texture_astc;
  54. };
  55. /**
  56. * Loader plugin for handling compressed textures for all platforms.
  57. * @class
  58. * @memberof PIXI
  59. * @implements {PIXI.ILoaderPlugin}
  60. */
  61. export declare class CompressedTextureLoader {
  62. /** @ignore */
  63. static extension: ExtensionMetadata;
  64. /** Map of available texture extensions. */
  65. private static _textureExtensions;
  66. /** Map of available texture formats. */
  67. private static _textureFormats;
  68. /**
  69. * Called after a compressed-textures manifest is loaded.
  70. *
  71. * This will then load the correct compression format for the device. Your manifest should adhere
  72. * to the following schema:
  73. *
  74. * ```js
  75. * import { INTERNAL_FORMATS } from '@pixi/constants';
  76. *
  77. * type CompressedTextureManifest = {
  78. * textures: Array<{ src: string, format?: keyof INTERNAL_FORMATS}>,
  79. * cacheID: string;
  80. * };
  81. * ```
  82. *
  83. * This is an example of a .json manifest file
  84. *
  85. * ```json
  86. * {
  87. * "cacheID":"asset",
  88. * "textures":[
  89. * { "src":"asset.fallback.png" },
  90. * { "format":"COMPRESSED_RGBA_S3TC_DXT5_EXT", "src":"asset.s3tc.ktx" },
  91. * { "format":"COMPRESSED_RGBA8_ETC2_EAC", "src":"asset.etc.ktx" },
  92. * { "format":"RGBA_PVRTC_4BPPV1_IMG", "src":"asset.pvrtc.ktx" }
  93. * ]
  94. * }
  95. * ```
  96. */
  97. static use(resource: LoaderResource, next: (...args: any[]) => void): void;
  98. /** Map of available texture extensions. */
  99. static get textureExtensions(): Partial<CompressedTextureExtensions>;
  100. /** Map of available texture formats. */
  101. static get textureFormats(): {
  102. [P in keyof INTERNAL_FORMATS]?: number;
  103. };
  104. }
  105. /**
  106. * Schema for compressed-texture manifests
  107. * @ignore
  108. * @see PIXI.CompressedTextureLoader
  109. */
  110. export declare type CompressedTextureManifest = {
  111. textures: Array<{
  112. src: string;
  113. format?: keyof INTERNAL_FORMATS;
  114. }>;
  115. cacheID: string;
  116. };
  117. /**
  118. * Resource for compressed texture formats, as follows: S3TC/DXTn (& their sRGB formats), ATC, ASTC, ETC 1/2, PVRTC.
  119. *
  120. * Compressed textures improve performance when rendering is texture-bound. The texture data stays compressed in
  121. * graphics memory, increasing memory locality and speeding up texture fetches. These formats can also be used to store
  122. * more detail in the same amount of memory.
  123. *
  124. * For most developers, container file formats are a better abstraction instead of directly handling raw texture
  125. * data. PixiJS provides native support for the following texture file formats (via {@link PIXI.Loader}):
  126. *
  127. * **.dds** - the DirectDraw Surface file format stores DXTn (DXT-1,3,5) data. See {@link PIXI.DDSLoader}
  128. * **.ktx** - the Khronos Texture Container file format supports storing all the supported WebGL compression formats.
  129. * See {@link PIXI.KTXLoader}.
  130. * **.basis** - the BASIS supercompressed file format stores texture data in an internal format that is transcoded
  131. * to the compression format supported on the device at _runtime_. It also supports transcoding into a uncompressed
  132. * format as a fallback; you must install the `@pixi/basis-loader`, `@pixi/basis-transcoder` packages separately to
  133. * use these files. See {@link PIXI.BasisLoader}.
  134. *
  135. * The loaders for the aforementioned formats use `CompressedTextureResource` internally. It is strongly suggested that
  136. * they be used instead.
  137. *
  138. * ## Working directly with CompressedTextureResource
  139. *
  140. * Since `CompressedTextureResource` inherits `BlobResource`, you can provide it a URL pointing to a file containing
  141. * the raw texture data (with no file headers!):
  142. *
  143. * ```js
  144. * // The resource backing the texture data for your textures.
  145. * // NOTE: You can also provide a ArrayBufferView instead of a URL. This is used when loading data from a container file
  146. * // format such as KTX, DDS, or BASIS.
  147. * const compressedResource = new PIXI.CompressedTextureResource("bunny.dxt5", {
  148. * format: PIXI.INTERNAL_FORMATS.COMPRESSED_RGBA_S3TC_DXT5_EXT,
  149. * width: 256,
  150. * height: 256
  151. * });
  152. *
  153. * // You can create a base-texture to the cache, so that future `Texture`s can be created using the `Texture.from` API.
  154. * const baseTexture = new PIXI.BaseTexture(compressedResource, { pmaMode: PIXI.ALPHA_MODES.NPM });
  155. *
  156. * // Create a Texture to add to the TextureCache
  157. * const texture = new PIXI.Texture(baseTexture);
  158. *
  159. * // Add baseTexture & texture to the global texture cache
  160. * PIXI.BaseTexture.addToCache(baseTexture, "bunny.dxt5");
  161. * PIXI.Texture.addToCache(texture, "bunny.dxt5");
  162. * ```
  163. * @memberof PIXI
  164. */
  165. export declare class CompressedTextureResource extends BlobResource {
  166. /** The compression format */
  167. format: INTERNAL_FORMATS;
  168. /**
  169. * The number of mipmap levels stored in the resource buffer.
  170. * @default 1
  171. */
  172. levels: number;
  173. private _extension;
  174. private _levelBuffers;
  175. /**
  176. * @param source - the buffer/URL holding the compressed texture data
  177. * @param options
  178. * @param {PIXI.INTERNAL_FORMATS} options.format - the compression format
  179. * @param {number} options.width - the image width in pixels.
  180. * @param {number} options.height - the image height in pixels.
  181. * @param {number} [options.level=1] - the mipmap levels stored in the compressed texture, including level 0.
  182. * @param {number} [options.levelBuffers] - the buffers for each mipmap level. `CompressedTextureResource` can allows you
  183. * to pass `null` for `source`, for cases where each level is stored in non-contiguous memory.
  184. */
  185. constructor(source: string | Uint8Array | Uint32Array, options: ICompressedTextureResourceOptions);
  186. /**
  187. * @override
  188. * @param renderer - A reference to the current renderer
  189. * @param _texture - the texture
  190. * @param _glTexture - texture instance for this webgl context
  191. */
  192. upload(renderer: Renderer, _texture: BaseTexture, _glTexture: GLTexture): boolean;
  193. /** @protected */
  194. protected onBlobLoaded(): void;
  195. /**
  196. * Returns the key (to ContextSystem#extensions) for the WebGL extension supporting the compression format
  197. * @private
  198. * @param format - the compression format to get the extension for.
  199. */
  200. private static _formatToExtension;
  201. /**
  202. * Pre-creates buffer views for each mipmap level
  203. * @private
  204. * @param buffer -
  205. * @param format - compression formats
  206. * @param levels - mipmap levels
  207. * @param blockWidth -
  208. * @param blockHeight -
  209. * @param imageWidth - width of the image in pixels
  210. * @param imageHeight - height of the image in pixels
  211. */
  212. private static _createLevelBuffers;
  213. }
  214. /**
  215. * @class
  216. * @memberof PIXI
  217. * @implements {PIXI.ILoaderPlugin}
  218. * @see https://docs.microsoft.com/en-us/windows/win32/direct3ddds/dx-graphics-dds-pguide
  219. */
  220. export declare class DDSLoader {
  221. /** @ignore */
  222. static extension: ExtensionMetadata;
  223. /**
  224. * Registers a DDS compressed texture
  225. * @see PIXI.Loader.loaderMiddleware
  226. * @param resource - loader resource that is checked to see if it is a DDS file
  227. * @param next - callback Function to call when done
  228. */
  229. static use(resource: LoaderResource, next: (...args: any[]) => void): void;
  230. }
  231. /**
  232. * Number of components in each {@link PIXI.FORMATS}
  233. * @ignore
  234. */
  235. export declare const FORMATS_TO_COMPONENTS: {
  236. [id: number]: number;
  237. };
  238. declare interface IBlobOptions {
  239. autoLoad?: boolean;
  240. width: number;
  241. height: number;
  242. }
  243. /**
  244. * @ignore
  245. */
  246. export declare interface ICompressedTextureResourceOptions {
  247. format: INTERNAL_FORMATS;
  248. width: number;
  249. height: number;
  250. levels?: number;
  251. levelBuffers?: CompressedLevelBuffer[];
  252. }
  253. /**
  254. * Maps the compressed texture formats in {@link PIXI.INTERNAL_FORMATS} to the number of bytes taken by
  255. * each texel.
  256. * @memberof PIXI
  257. * @static
  258. * @ignore
  259. */
  260. export declare const INTERNAL_FORMAT_TO_BYTES_PER_PIXEL: {
  261. [id: number]: number;
  262. };
  263. /**
  264. * WebGL internal formats, including compressed texture formats provided by extensions
  265. * @memberof PIXI
  266. * @static
  267. * @name INTERNAL_FORMATS
  268. * @enum {number}
  269. * @property {number} [COMPRESSED_RGB_S3TC_DXT1_EXT=0x83F0] -
  270. * @property {number} [COMPRESSED_RGBA_S3TC_DXT1_EXT=0x83F1] -
  271. * @property {number} [COMPRESSED_RGBA_S3TC_DXT3_EXT=0x83F2] -
  272. * @property {number} [COMPRESSED_RGBA_S3TC_DXT5_EXT=0x83F3] -
  273. * @property {number} [COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT=35917] -
  274. * @property {number} [COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT=35918] -
  275. * @property {number} [COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT=35919] -
  276. * @property {number} [COMPRESSED_SRGB_S3TC_DXT1_EXT=35916] -
  277. * @property {number} [COMPRESSED_R11_EAC=0x9270] -
  278. * @property {number} [COMPRESSED_SIGNED_R11_EAC=0x9271] -
  279. * @property {number} [COMPRESSED_RG11_EAC=0x9272] -
  280. * @property {number} [COMPRESSED_SIGNED_RG11_EAC=0x9273] -
  281. * @property {number} [COMPRESSED_RGB8_ETC2=0x9274] -
  282. * @property {number} [COMPRESSED_RGBA8_ETC2_EAC=0x9278] -
  283. * @property {number} [COMPRESSED_SRGB8_ETC2=0x9275] -
  284. * @property {number} [COMPRESSED_SRGB8_ALPHA8_ETC2_EAC=0x9279] -
  285. * @property {number} [COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2=0x9276] -
  286. * @property {number} [COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2=0x9277] -
  287. * @property {number} [COMPRESSED_RGB_PVRTC_4BPPV1_IMG=0x8C00] -
  288. * @property {number} [COMPRESSED_RGBA_PVRTC_4BPPV1_IMG=0x8C02] -
  289. * @property {number} [COMPRESSED_RGB_PVRTC_2BPPV1_IMG=0x8C01] -
  290. * @property {number} [COMPRESSED_RGBA_PVRTC_2BPPV1_IMG=0x8C03] -
  291. * @property {number} [COMPRESSED_RGB_ETC1_WEBGL=0x8D64] -
  292. * @property {number} [COMPRESSED_RGB_ATC_WEBGL=0x8C92] -
  293. * @property {number} [COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL=0x8C92] -
  294. * @property {number} [COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL=0x87EE] -
  295. * @property {number} [COMPRESSED_RGBA_ASTC_4x4_KHR=0x93B0] -
  296. */
  297. export declare enum INTERNAL_FORMATS {
  298. COMPRESSED_RGB_S3TC_DXT1_EXT = 33776,
  299. COMPRESSED_RGBA_S3TC_DXT1_EXT = 33777,
  300. COMPRESSED_RGBA_S3TC_DXT3_EXT = 33778,
  301. COMPRESSED_RGBA_S3TC_DXT5_EXT = 33779,
  302. COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT = 35917,
  303. COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT = 35918,
  304. COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT = 35919,
  305. COMPRESSED_SRGB_S3TC_DXT1_EXT = 35916,
  306. COMPRESSED_R11_EAC = 37488,
  307. COMPRESSED_SIGNED_R11_EAC = 37489,
  308. COMPRESSED_RG11_EAC = 37490,
  309. COMPRESSED_SIGNED_RG11_EAC = 37491,
  310. COMPRESSED_RGB8_ETC2 = 37492,
  311. COMPRESSED_RGBA8_ETC2_EAC = 37496,
  312. COMPRESSED_SRGB8_ETC2 = 37493,
  313. COMPRESSED_SRGB8_ALPHA8_ETC2_EAC = 37497,
  314. COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2 = 37494,
  315. COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2 = 37495,
  316. COMPRESSED_RGB_PVRTC_4BPPV1_IMG = 35840,
  317. COMPRESSED_RGBA_PVRTC_4BPPV1_IMG = 35842,
  318. COMPRESSED_RGB_PVRTC_2BPPV1_IMG = 35841,
  319. COMPRESSED_RGBA_PVRTC_2BPPV1_IMG = 35843,
  320. COMPRESSED_RGB_ETC1_WEBGL = 36196,
  321. COMPRESSED_RGB_ATC_WEBGL = 35986,
  322. COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL = 35986,
  323. COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL = 34798,
  324. COMPRESSED_RGBA_ASTC_4x4_KHR = 37808
  325. }
  326. /**
  327. * Loader plugin for handling KTX texture container files.
  328. *
  329. * This KTX loader does not currently support the following features:
  330. * * cube textures
  331. * * 3D textures
  332. * * endianness conversion for big-endian machines
  333. * * embedded *.basis files
  334. *
  335. * It does supports the following features:
  336. * * multiple textures per file
  337. * * mipmapping (only for compressed formats)
  338. * * vendor-specific key/value data parsing (enable {@link PIXI.KTXLoader.loadKeyValueData})
  339. * @class
  340. * @memberof PIXI
  341. * @implements {PIXI.ILoaderPlugin}
  342. */
  343. export declare class KTXLoader {
  344. /** @ignore */
  345. static extension: ExtensionMetadata;
  346. /**
  347. * If set to `true`, {@link PIXI.KTXLoader} will parse key-value data in KTX textures. This feature relies
  348. * on the [Encoding Standard]{@link https://encoding.spec.whatwg.org}.
  349. *
  350. * The key-value data will be available on the base-textures as {@code PIXI.BaseTexture.ktxKeyValueData}. They
  351. * will hold a reference to the texture data buffer, so make sure to delete key-value data once you are done
  352. * using it.
  353. */
  354. static loadKeyValueData: boolean;
  355. /**
  356. * Called after a KTX file is loaded.
  357. *
  358. * This will parse the KTX file header and add a {@code BaseTexture} to the texture
  359. * cache.
  360. * @see PIXI.Loader.loaderMiddleware
  361. * @param resource - loader resource that is checked to see if it is a KTX file
  362. * @param next - callback Function to call when done
  363. */
  364. static use(resource: LoaderResource, next: (...args: any[]) => void): void;
  365. }
  366. /**
  367. * @class
  368. * @memberof PIXI
  369. * @implements {PIXI.ILoaderPlugin}
  370. * @see https://docs.microsoft.com/en-us/windows/win32/direct3ddds/dx-graphics-dds-pguide
  371. */
  372. /**
  373. * Parses the DDS file header, generates base-textures, and puts them into the texture cache.
  374. * @param arrayBuffer
  375. */
  376. export declare function parseDDS(arrayBuffer: ArrayBuffer): CompressedTextureResource[];
  377. export declare function parseKTX(url: string, arrayBuffer: ArrayBuffer, loadKeyValueData?: boolean): {
  378. compressed?: CompressedTextureResource[];
  379. uncompressed?: {
  380. resource: BufferResource;
  381. type: TYPES;
  382. format: FORMATS;
  383. }[];
  384. kvData: Map<string, DataView> | null;
  385. };
  386. /**
  387. * Maps {@link PIXI.TYPES} to the bytes taken per component, excluding those ones that are bit-fields.
  388. * @ignore
  389. */
  390. export declare const TYPES_TO_BYTES_PER_COMPONENT: {
  391. [id: number]: number;
  392. };
  393. /**
  394. * Number of bytes per pixel in bit-field types in {@link PIXI.TYPES}
  395. * @ignore
  396. */
  397. export declare const TYPES_TO_BYTES_PER_PIXEL: {
  398. [id: number]: number;
  399. };
  400. export { }