forked from BabylonJS/Babylon.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
liteTranscoder_UASTC_RG8_UNORM.ts
50 lines (42 loc) · 1.84 KB
/
liteTranscoder_UASTC_RG8_UNORM.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import * as KTX2 from "core/Materials/Textures/ktx2decoderTypes";
import { LiteTranscoder } from "./liteTranscoder";
import type { KTX2FileReader, IKTX2_ImageDesc } from "../ktx2FileReader";
/**
* @internal
*/
// eslint-disable-next-line @typescript-eslint/naming-convention
export class LiteTranscoder_UASTC_RG8_UNORM extends LiteTranscoder {
/**
* URL to use when loading the wasm module for the transcoder (unorm)
*/
public static WasmModuleURL = "https://preview.babylonjs.com/ktx2Transcoders/1/uastc_rg8_unorm.wasm";
public static CanTranscode(src: KTX2.SourceTextureFormat, dst: KTX2.TranscodeTarget, isInGammaSpace: boolean): boolean {
return src === KTX2.SourceTextureFormat.UASTC4x4 && dst === KTX2.TranscodeTarget.RG8;
}
public static Name = "UniversalTranscoder_UASTC_RG8_UNORM";
public getName(): string {
return LiteTranscoder_UASTC_RG8_UNORM.Name;
}
public initialize(): void {
super.initialize();
this._transcodeInPlace = false;
this.setModulePath(LiteTranscoder_UASTC_RG8_UNORM.WasmModuleURL);
}
public transcode(
src: KTX2.SourceTextureFormat,
dst: KTX2.TranscodeTarget,
level: number,
width: number,
height: number,
uncompressedByteLength: number,
ktx2Reader: KTX2FileReader,
imageDesc: IKTX2_ImageDesc | null,
encodedData: Uint8Array
): Promise<Uint8Array | null> {
return this._loadModule().then((moduleWrapper: any) => {
const transcoder: any = moduleWrapper.module;
const [, uncompressedTextureView] = this._prepareTranscoding(width, height, uncompressedByteLength, encodedData, 2);
return transcoder.decode(width, height) === 0 ? uncompressedTextureView!.slice() : null;
});
}
}