- 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 { parseDDS } from "./parseDDS.js";
import { parseKTX } from "./parseKTX.js";
import { parseKTX2 } from "./parseKTX2.js";
import { parsePVR } from "./parsePVR.js";
import { parsePKM } from "./parsePKM.js";
import * as event from "../../../system/event.js";
let _renderer;
// gracefully capture a reference to the active renderer without adding more cyclic redundancy
event.once(event.VIDEO_INIT, (renderer) => {
_renderer = renderer;
});
export function parseCompressedImage(arrayBuffer, imgExt) {
let texture;
// check if the current renderer is WebGL
if (_renderer.type.includes("WebGL")) {
switch (imgExt) {
// Compressed texture
case "dds":
texture = parseDDS(arrayBuffer);
break;
case "pvr":
texture = parsePVR(arrayBuffer);
break;
case "pkm":
texture = parsePKM(arrayBuffer);
break;
case "ktx":
texture = parseKTX(arrayBuffer);
break;
case "ktx2":
texture = parseKTX2(arrayBuffer);
break;
}
}
if (typeof texture !== "undefined") {
if (_renderer.hasSupportedCompressedFormats(texture.format)) {
console.log("Compressed texture format supported: " + texture.format);
return texture;
}
}
throw ("unsupported texture format:" + imgExt + texture ? " (" + texture.format + ")" : "");
}