khronosTextureContainer2.d.ts 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. import type { InternalTexture } from "../Materials/Textures/internalTexture";
  2. import type { AbstractEngine } from "../Engines/abstractEngine";
  3. import { AutoReleaseWorkerPool } from "./workerPool";
  4. import type { Nullable } from "../types";
  5. import type { IDecodedData, IKTX2DecoderOptions } from "../Materials/Textures/ktx2decoderTypes.js";
  6. import type { AllowedKeys } from "./khronosTextureContainer2Worker";
  7. /**
  8. * Class that defines the default KTX2 decoder options.
  9. *
  10. * This class is useful for providing options to the KTX2 decoder to control how the source data is transcoded.
  11. */
  12. export declare class DefaultKTX2DecoderOptions {
  13. private _isDirty;
  14. /**
  15. * Gets the dirty flag
  16. */
  17. get isDirty(): boolean;
  18. private _useRGBAIfASTCBC7NotAvailableWhenUASTC?;
  19. /**
  20. * force a (uncompressed) RGBA transcoded format if transcoding a UASTC source format and ASTC + BC7 are not available as a compressed transcoded format
  21. */
  22. get useRGBAIfASTCBC7NotAvailableWhenUASTC(): boolean | undefined;
  23. set useRGBAIfASTCBC7NotAvailableWhenUASTC(value: boolean | undefined);
  24. private _useRGBAIfOnlyBC1BC3AvailableWhenUASTC?;
  25. /**
  26. * force a (uncompressed) RGBA transcoded format if transcoding a UASTC source format and only BC1 or BC3 are available as a compressed transcoded format.
  27. * This property is true by default to favor speed over memory, because currently transcoding from UASTC to BC1/3 is slow because the transcoder transcodes
  28. * to uncompressed and then recompresses the texture
  29. */
  30. get useRGBAIfOnlyBC1BC3AvailableWhenUASTC(): boolean | undefined;
  31. set useRGBAIfOnlyBC1BC3AvailableWhenUASTC(value: boolean | undefined);
  32. private _forceRGBA?;
  33. /**
  34. * force to always use (uncompressed) RGBA for transcoded format
  35. */
  36. get forceRGBA(): boolean | undefined;
  37. set forceRGBA(value: boolean | undefined);
  38. private _forceR8?;
  39. /**
  40. * force to always use (uncompressed) R8 for transcoded format
  41. */
  42. get forceR8(): boolean | undefined;
  43. set forceR8(value: boolean | undefined);
  44. private _forceRG8?;
  45. /**
  46. * force to always use (uncompressed) RG8 for transcoded format
  47. */
  48. get forceRG8(): boolean | undefined;
  49. set forceRG8(value: boolean | undefined);
  50. private _bypassTranscoders?;
  51. /**
  52. * list of transcoders to bypass when looking for a suitable transcoder. The available transcoders are:
  53. * UniversalTranscoder_UASTC_ASTC
  54. * UniversalTranscoder_UASTC_BC7
  55. * UniversalTranscoder_UASTC_RGBA_UNORM
  56. * UniversalTranscoder_UASTC_RGBA_SRGB
  57. * UniversalTranscoder_UASTC_R8_UNORM
  58. * UniversalTranscoder_UASTC_RG8_UNORM
  59. * MSCTranscoder
  60. */
  61. get bypassTranscoders(): string[] | undefined;
  62. set bypassTranscoders(value: string[] | undefined);
  63. private _ktx2DecoderOptions;
  64. /** @internal */
  65. _getKTX2DecoderOptions(): IKTX2DecoderOptions;
  66. }
  67. /**
  68. * Options for the KTX2 decoder
  69. */
  70. export interface IKhronosTextureContainer2Options {
  71. /**
  72. * Number of workers to use for async operations. Specify `0` to disable web workers and run synchronously in the current context.
  73. */
  74. numWorkers?: number;
  75. /**
  76. * Worker pool to use for async operations. If set, `numWorkers` will be ignored.
  77. */
  78. workerPool?: AutoReleaseWorkerPool;
  79. /**
  80. * Optional container for the KTX2 decoder module and its dependencies. If set, the module will be used from this container and the URLs will be ignored.
  81. */
  82. binariesAndModulesContainer?: {
  83. [key in AllowedKeys]?: ArrayBuffer | any;
  84. };
  85. }
  86. /**
  87. * Class for loading KTX2 files
  88. */
  89. export declare class KhronosTextureContainer2 {
  90. private static _WorkerPoolPromise?;
  91. private static _DecoderModulePromise?;
  92. private static _KTX2DecoderModule?;
  93. /**
  94. * URLs to use when loading the KTX2 decoder module as well as its dependencies
  95. * If a url is null, the default url is used (pointing to https://preview.babylonjs.com)
  96. * Note that jsDecoderModule can't be null and that the other dependencies will only be loaded if necessary
  97. * Urls you can change:
  98. * URLConfig.jsDecoderModule
  99. * URLConfig.wasmUASTCToASTC
  100. * URLConfig.wasmUASTCToBC7
  101. * URLConfig.wasmUASTCToRGBA_UNORM
  102. * URLConfig.wasmUASTCToRGBA_SRGB
  103. * URLConfig.wasmUASTCToR8_UNORM
  104. * URLConfig.wasmUASTCToRG8_UNORM
  105. * URLConfig.jsMSCTranscoder
  106. * URLConfig.wasmMSCTranscoder
  107. * URLConfig.wasmZSTDDecoder
  108. * You can see their default values in this PG: https://playground.babylonjs.com/#EIJH8L#29
  109. */
  110. static URLConfig: {
  111. jsDecoderModule: string;
  112. wasmUASTCToASTC: Nullable<string>;
  113. wasmUASTCToBC7: Nullable<string>;
  114. wasmUASTCToRGBA_UNORM: Nullable<string>;
  115. wasmUASTCToRGBA_SRGB: Nullable<string>;
  116. wasmUASTCToR8_UNORM: Nullable<string>;
  117. wasmUASTCToRG8_UNORM: Nullable<string>;
  118. jsMSCTranscoder: Nullable<string>;
  119. wasmMSCTranscoder: Nullable<string>;
  120. wasmZSTDDecoder: Nullable<string>;
  121. };
  122. /**
  123. * If provided, this worker pool will be used instead of creating a new one.
  124. * This is useful when loading the WASM and the js modules on your own and
  125. * you want to use the ktxTextureLoader and not construct this class directly.
  126. */
  127. static WorkerPool?: AutoReleaseWorkerPool;
  128. /**
  129. * Default number of workers used to handle data decoding
  130. */
  131. static DefaultNumWorkers: number;
  132. /**
  133. * Default configuration for the KTX2 decoder.
  134. * The options defined in this way have priority over those passed when creating a KTX2 texture with new Texture(...).
  135. */
  136. static DefaultDecoderOptions: DefaultKTX2DecoderOptions;
  137. private static GetDefaultNumWorkers;
  138. private _engine;
  139. private static _Initialize;
  140. /**
  141. * Constructor
  142. * @param engine The engine to use
  143. * @param numWorkersOrOptions The number of workers for async operations. Specify `0` to disable web workers and run synchronously in the current context.
  144. */
  145. constructor(engine: AbstractEngine, numWorkersOrOptions?: number | IKhronosTextureContainer2Options);
  146. /**
  147. * @internal
  148. */
  149. _uploadAsync(data: ArrayBufferView, internalTexture: InternalTexture, options?: IKTX2DecoderOptions & IDecodedData): Promise<void>;
  150. protected _createTexture(data: IDecodedData, internalTexture: InternalTexture, options?: IKTX2DecoderOptions & IDecodedData): void;
  151. /**
  152. * Checks if the given data starts with a KTX2 file identifier.
  153. * @param data the data to check
  154. * @returns true if the data is a KTX2 file or false otherwise
  155. */
  156. static IsValid(data: ArrayBufferView): boolean;
  157. }