babylonjs-ktx2decoder 5.0.0-rc.7 → 5.0.0-rc.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{dist/babylon.ktx2Decoder.js → babylon.ktx2Decoder.js} +0 -0
- package/{dist/babylon.ktx2Decoder.js.map → babylon.ktx2Decoder.js.map} +0 -0
- package/{dist/babylon.ktx2Decoder.max.js → babylon.ktx2Decoder.max.js} +1233 -1233
- package/{dist/babylon.ktx2Decoder.max.js.map → babylon.ktx2Decoder.max.js.map} +0 -0
- package/babylon.ktx2Decoder.module.d.ts +12 -0
- package/package.json +6 -7
- package/dist/babylon.ktx2Decoder.module.d.ts +0 -578
|
@@ -22,121 +22,121 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
22
22
|
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
23
23
|
/* harmony export */ "DataReader": () => (/* binding */ DataReader)
|
|
24
24
|
/* harmony export */ });
|
|
25
|
-
/**
|
|
26
|
-
* Utility class for reading from a data buffer
|
|
27
|
-
*/
|
|
28
|
-
class DataReader {
|
|
29
|
-
/**
|
|
30
|
-
* Constructor
|
|
31
|
-
* @param buffer The buffer to set
|
|
32
|
-
* @param byteOffset The starting offset in the buffer
|
|
33
|
-
* @param byteLength The byte length of the buffer
|
|
34
|
-
*/
|
|
35
|
-
constructor(buffer, byteOffset, byteLength) {
|
|
36
|
-
if (buffer.buffer) {
|
|
37
|
-
this._dataView = new DataView(buffer.buffer, buffer.byteOffset + (byteOffset !== null && byteOffset !== void 0 ? byteOffset : 0), byteLength !== null && byteLength !== void 0 ? byteLength : buffer.byteLength);
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
this._dataView = new DataView(buffer, byteOffset !== null && byteOffset !== void 0 ? byteOffset : 0, byteLength !== null && byteLength !== void 0 ? byteLength : buffer.byteLength);
|
|
41
|
-
}
|
|
42
|
-
this._dataByteOffset = 0;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* The current byte offset from the beginning of the data buffer.
|
|
46
|
-
*/
|
|
47
|
-
get byteOffset() {
|
|
48
|
-
return this._dataByteOffset;
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Read a unsigned 8-bit integer from the currently loaded data range.
|
|
52
|
-
* @returns The 8-bit integer read
|
|
53
|
-
*/
|
|
54
|
-
readUint8() {
|
|
55
|
-
const value = this._dataView.getUint8(this._dataByteOffset);
|
|
56
|
-
this._dataByteOffset += 1;
|
|
57
|
-
return value;
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Read a signed 8-bit integer from the currently loaded data range.
|
|
61
|
-
* @returns The 8-bit integer read
|
|
62
|
-
*/
|
|
63
|
-
readInt8() {
|
|
64
|
-
const value = this._dataView.getInt8(this._dataByteOffset);
|
|
65
|
-
this._dataByteOffset += 1;
|
|
66
|
-
return value;
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Read a unsigned 16-bit integer from the currently loaded data range.
|
|
70
|
-
* @returns The 16-bit integer read
|
|
71
|
-
*/
|
|
72
|
-
readUint16() {
|
|
73
|
-
const value = this._dataView.getUint16(this._dataByteOffset, true);
|
|
74
|
-
this._dataByteOffset += 2;
|
|
75
|
-
return value;
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Read a signed 16-bit integer from the currently loaded data range.
|
|
79
|
-
* @returns The 16-bit integer read
|
|
80
|
-
*/
|
|
81
|
-
readInt16() {
|
|
82
|
-
const value = this._dataView.getInt16(this._dataByteOffset, true);
|
|
83
|
-
this._dataByteOffset += 2;
|
|
84
|
-
return value;
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Read a unsigned 32-bit integer from the currently loaded data range.
|
|
88
|
-
* @returns The 32-bit integer read
|
|
89
|
-
*/
|
|
90
|
-
readUint32() {
|
|
91
|
-
const value = this._dataView.getUint32(this._dataByteOffset, true);
|
|
92
|
-
this._dataByteOffset += 4;
|
|
93
|
-
return value;
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Read a signed 32-bit integer from the currently loaded data range.
|
|
97
|
-
* @returns The 32-bit integer read
|
|
98
|
-
*/
|
|
99
|
-
readInt32() {
|
|
100
|
-
const value = this._dataView.getInt32(this._dataByteOffset, true);
|
|
101
|
-
this._dataByteOffset += 4;
|
|
102
|
-
return value;
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Read a unsigned 32-bit integer from the currently loaded data range.
|
|
106
|
-
* @returns The 32-bit integer read
|
|
107
|
-
*/
|
|
108
|
-
readUint64() {
|
|
109
|
-
// split 64-bit number into two 32-bit (4-byte) parts
|
|
110
|
-
const left = this._dataView.getUint32(this._dataByteOffset, true);
|
|
111
|
-
const right = this._dataView.getUint32(this._dataByteOffset + 4, true);
|
|
112
|
-
// combine the two 32-bit values
|
|
113
|
-
const combined = left + 2 ** 32 * right; // That was weird..Keeping it for posterity: true ? left + 2 ** 32 * right : 2 ** 32 * left + right;
|
|
114
|
-
/*if (!Number.isSafeInteger(combined)) {
|
|
115
|
-
console.warn('DataReader: ' + combined + ' exceeds MAX_SAFE_INTEGER. Precision may be lost.');
|
|
116
|
-
}*/
|
|
117
|
-
this._dataByteOffset += 8;
|
|
118
|
-
return combined;
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* Read a byte array from the currently loaded data range.
|
|
122
|
-
* @param byteLength The byte length to read
|
|
123
|
-
* @returns The byte array read
|
|
124
|
-
*/
|
|
125
|
-
readUint8Array(byteLength) {
|
|
126
|
-
const value = new Uint8Array(this._dataView.buffer, this._dataView.byteOffset + this._dataByteOffset, byteLength);
|
|
127
|
-
this._dataByteOffset += byteLength;
|
|
128
|
-
return value;
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* Skips the given byte length the currently loaded data range.
|
|
132
|
-
* @param byteLength The byte length to skip
|
|
133
|
-
* @returns This instance
|
|
134
|
-
*/
|
|
135
|
-
skipBytes(byteLength) {
|
|
136
|
-
this._dataByteOffset += byteLength;
|
|
137
|
-
return this;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
25
|
+
/**
|
|
26
|
+
* Utility class for reading from a data buffer
|
|
27
|
+
*/
|
|
28
|
+
class DataReader {
|
|
29
|
+
/**
|
|
30
|
+
* Constructor
|
|
31
|
+
* @param buffer The buffer to set
|
|
32
|
+
* @param byteOffset The starting offset in the buffer
|
|
33
|
+
* @param byteLength The byte length of the buffer
|
|
34
|
+
*/
|
|
35
|
+
constructor(buffer, byteOffset, byteLength) {
|
|
36
|
+
if (buffer.buffer) {
|
|
37
|
+
this._dataView = new DataView(buffer.buffer, buffer.byteOffset + (byteOffset !== null && byteOffset !== void 0 ? byteOffset : 0), byteLength !== null && byteLength !== void 0 ? byteLength : buffer.byteLength);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
this._dataView = new DataView(buffer, byteOffset !== null && byteOffset !== void 0 ? byteOffset : 0, byteLength !== null && byteLength !== void 0 ? byteLength : buffer.byteLength);
|
|
41
|
+
}
|
|
42
|
+
this._dataByteOffset = 0;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* The current byte offset from the beginning of the data buffer.
|
|
46
|
+
*/
|
|
47
|
+
get byteOffset() {
|
|
48
|
+
return this._dataByteOffset;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Read a unsigned 8-bit integer from the currently loaded data range.
|
|
52
|
+
* @returns The 8-bit integer read
|
|
53
|
+
*/
|
|
54
|
+
readUint8() {
|
|
55
|
+
const value = this._dataView.getUint8(this._dataByteOffset);
|
|
56
|
+
this._dataByteOffset += 1;
|
|
57
|
+
return value;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Read a signed 8-bit integer from the currently loaded data range.
|
|
61
|
+
* @returns The 8-bit integer read
|
|
62
|
+
*/
|
|
63
|
+
readInt8() {
|
|
64
|
+
const value = this._dataView.getInt8(this._dataByteOffset);
|
|
65
|
+
this._dataByteOffset += 1;
|
|
66
|
+
return value;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Read a unsigned 16-bit integer from the currently loaded data range.
|
|
70
|
+
* @returns The 16-bit integer read
|
|
71
|
+
*/
|
|
72
|
+
readUint16() {
|
|
73
|
+
const value = this._dataView.getUint16(this._dataByteOffset, true);
|
|
74
|
+
this._dataByteOffset += 2;
|
|
75
|
+
return value;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Read a signed 16-bit integer from the currently loaded data range.
|
|
79
|
+
* @returns The 16-bit integer read
|
|
80
|
+
*/
|
|
81
|
+
readInt16() {
|
|
82
|
+
const value = this._dataView.getInt16(this._dataByteOffset, true);
|
|
83
|
+
this._dataByteOffset += 2;
|
|
84
|
+
return value;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Read a unsigned 32-bit integer from the currently loaded data range.
|
|
88
|
+
* @returns The 32-bit integer read
|
|
89
|
+
*/
|
|
90
|
+
readUint32() {
|
|
91
|
+
const value = this._dataView.getUint32(this._dataByteOffset, true);
|
|
92
|
+
this._dataByteOffset += 4;
|
|
93
|
+
return value;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Read a signed 32-bit integer from the currently loaded data range.
|
|
97
|
+
* @returns The 32-bit integer read
|
|
98
|
+
*/
|
|
99
|
+
readInt32() {
|
|
100
|
+
const value = this._dataView.getInt32(this._dataByteOffset, true);
|
|
101
|
+
this._dataByteOffset += 4;
|
|
102
|
+
return value;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Read a unsigned 32-bit integer from the currently loaded data range.
|
|
106
|
+
* @returns The 32-bit integer read
|
|
107
|
+
*/
|
|
108
|
+
readUint64() {
|
|
109
|
+
// split 64-bit number into two 32-bit (4-byte) parts
|
|
110
|
+
const left = this._dataView.getUint32(this._dataByteOffset, true);
|
|
111
|
+
const right = this._dataView.getUint32(this._dataByteOffset + 4, true);
|
|
112
|
+
// combine the two 32-bit values
|
|
113
|
+
const combined = left + 2 ** 32 * right; // That was weird..Keeping it for posterity: true ? left + 2 ** 32 * right : 2 ** 32 * left + right;
|
|
114
|
+
/*if (!Number.isSafeInteger(combined)) {
|
|
115
|
+
console.warn('DataReader: ' + combined + ' exceeds MAX_SAFE_INTEGER. Precision may be lost.');
|
|
116
|
+
}*/
|
|
117
|
+
this._dataByteOffset += 8;
|
|
118
|
+
return combined;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Read a byte array from the currently loaded data range.
|
|
122
|
+
* @param byteLength The byte length to read
|
|
123
|
+
* @returns The byte array read
|
|
124
|
+
*/
|
|
125
|
+
readUint8Array(byteLength) {
|
|
126
|
+
const value = new Uint8Array(this._dataView.buffer, this._dataView.byteOffset + this._dataByteOffset, byteLength);
|
|
127
|
+
this._dataByteOffset += byteLength;
|
|
128
|
+
return value;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Skips the given byte length the currently loaded data range.
|
|
132
|
+
* @param byteLength The byte length to skip
|
|
133
|
+
* @returns This instance
|
|
134
|
+
*/
|
|
135
|
+
skipBytes(byteLength) {
|
|
136
|
+
this._dataByteOffset += byteLength;
|
|
137
|
+
return this;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
140
|
|
|
141
141
|
|
|
142
142
|
/***/ }),
|
|
@@ -152,7 +152,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
152
152
|
/* harmony export */ "DataReader": () => (/* reexport safe */ _dataReader__WEBPACK_IMPORTED_MODULE_0__.DataReader)
|
|
153
153
|
/* harmony export */ });
|
|
154
154
|
/* harmony import */ var _dataReader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./dataReader */ "../../../tools/ktx2Decoder/dist/Misc/dataReader.js");
|
|
155
|
-
|
|
155
|
+
|
|
156
156
|
|
|
157
157
|
|
|
158
158
|
/***/ }),
|
|
@@ -178,12 +178,12 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
178
178
|
/* harmony import */ var _liteTranscoder_UASTC_RGBA_UNORM__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./liteTranscoder_UASTC_RGBA_UNORM */ "../../../tools/ktx2Decoder/dist/Transcoders/liteTranscoder_UASTC_RGBA_UNORM.js");
|
|
179
179
|
/* harmony import */ var _liteTranscoder_UASTC_RGBA_SRGB__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./liteTranscoder_UASTC_RGBA_SRGB */ "../../../tools/ktx2Decoder/dist/Transcoders/liteTranscoder_UASTC_RGBA_SRGB.js");
|
|
180
180
|
/* harmony import */ var _mscTranscoder__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./mscTranscoder */ "../../../tools/ktx2Decoder/dist/Transcoders/mscTranscoder.js");
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
|
|
187
187
|
|
|
188
188
|
|
|
189
189
|
/***/ }),
|
|
@@ -200,63 +200,63 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
200
200
|
/* harmony export */ });
|
|
201
201
|
/* harmony import */ var _transcoder__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../transcoder */ "../../../tools/ktx2Decoder/dist/transcoder.js");
|
|
202
202
|
/* harmony import */ var _wasmMemoryManager__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../wasmMemoryManager */ "../../../tools/ktx2Decoder/dist/wasmMemoryManager.js");
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
/**
|
|
206
|
-
* @hidden
|
|
207
|
-
*/
|
|
208
|
-
class LiteTranscoder extends _transcoder__WEBPACK_IMPORTED_MODULE_0__.Transcoder {
|
|
209
|
-
_loadModule() {
|
|
210
|
-
if (this._modulePromise) {
|
|
211
|
-
return this._modulePromise;
|
|
212
|
-
}
|
|
213
|
-
this._modulePromise = _wasmMemoryManager__WEBPACK_IMPORTED_MODULE_1__.WASMMemoryManager.LoadWASM(this._modulePath).then((wasmBinary) => {
|
|
214
|
-
return new Promise((resolve) => {
|
|
215
|
-
WebAssembly.instantiate(wasmBinary, { env: { memory: this._memoryManager.wasmMemory } }).then((moduleWrapper) => {
|
|
216
|
-
resolve({ module: moduleWrapper.instance.exports });
|
|
217
|
-
});
|
|
218
|
-
});
|
|
219
|
-
});
|
|
220
|
-
return this._modulePromise;
|
|
221
|
-
}
|
|
222
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
223
|
-
get memoryManager() {
|
|
224
|
-
return this._memoryManager;
|
|
225
|
-
}
|
|
226
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
227
|
-
setModulePath(modulePath) {
|
|
228
|
-
this._modulePath = modulePath;
|
|
229
|
-
}
|
|
230
|
-
initialize() {
|
|
231
|
-
this._transcodeInPlace = true;
|
|
232
|
-
}
|
|
233
|
-
needMemoryManager() {
|
|
234
|
-
return true;
|
|
235
|
-
}
|
|
236
|
-
setMemoryManager(memoryMgr) {
|
|
237
|
-
this._memoryManager = memoryMgr;
|
|
238
|
-
}
|
|
239
|
-
transcode(src, dst, level, width, height, uncompressedByteLength, ktx2Reader, imageDesc, encodedData) {
|
|
240
|
-
return this._loadModule().then((moduleWrapper) => {
|
|
241
|
-
const transcoder = moduleWrapper.module;
|
|
242
|
-
const [textureView, uncompressedTextureView, nBlocks] = this._prepareTranscoding(width, height, uncompressedByteLength, encodedData);
|
|
243
|
-
return transcoder.transcode(nBlocks) === 0 ? (this._transcodeInPlace ? textureView.slice() : uncompressedTextureView.slice()) : null;
|
|
244
|
-
});
|
|
245
|
-
}
|
|
246
|
-
_prepareTranscoding(width, height, uncompressedByteLength, encodedData, forceRGBA = false) {
|
|
247
|
-
const nBlocks = ((width + 3) >> 2) * ((height + 3) >> 2);
|
|
248
|
-
if (forceRGBA) {
|
|
249
|
-
uncompressedByteLength = width * ((height + 3) >> 2) * 4 * 4;
|
|
250
|
-
}
|
|
251
|
-
const texMemoryPages = ((nBlocks * 16 + 65535 + (this._transcodeInPlace ? 0 : uncompressedByteLength)) >> 16) + 1;
|
|
252
|
-
const textureView = this.memoryManager.getMemoryView(texMemoryPages, 65536, nBlocks * 16);
|
|
253
|
-
const uncompressedTextureView = this._transcodeInPlace
|
|
254
|
-
? null
|
|
255
|
-
: new Uint8Array(this._memoryManager.wasmMemory.buffer, 65536 + nBlocks * 16, forceRGBA ? width * height * 4 : uncompressedByteLength);
|
|
256
|
-
textureView.set(encodedData);
|
|
257
|
-
return [textureView, uncompressedTextureView, nBlocks];
|
|
258
|
-
}
|
|
259
|
-
}
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* @hidden
|
|
207
|
+
*/
|
|
208
|
+
class LiteTranscoder extends _transcoder__WEBPACK_IMPORTED_MODULE_0__.Transcoder {
|
|
209
|
+
_loadModule() {
|
|
210
|
+
if (this._modulePromise) {
|
|
211
|
+
return this._modulePromise;
|
|
212
|
+
}
|
|
213
|
+
this._modulePromise = _wasmMemoryManager__WEBPACK_IMPORTED_MODULE_1__.WASMMemoryManager.LoadWASM(this._modulePath).then((wasmBinary) => {
|
|
214
|
+
return new Promise((resolve) => {
|
|
215
|
+
WebAssembly.instantiate(wasmBinary, { env: { memory: this._memoryManager.wasmMemory } }).then((moduleWrapper) => {
|
|
216
|
+
resolve({ module: moduleWrapper.instance.exports });
|
|
217
|
+
});
|
|
218
|
+
});
|
|
219
|
+
});
|
|
220
|
+
return this._modulePromise;
|
|
221
|
+
}
|
|
222
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
223
|
+
get memoryManager() {
|
|
224
|
+
return this._memoryManager;
|
|
225
|
+
}
|
|
226
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
227
|
+
setModulePath(modulePath) {
|
|
228
|
+
this._modulePath = modulePath;
|
|
229
|
+
}
|
|
230
|
+
initialize() {
|
|
231
|
+
this._transcodeInPlace = true;
|
|
232
|
+
}
|
|
233
|
+
needMemoryManager() {
|
|
234
|
+
return true;
|
|
235
|
+
}
|
|
236
|
+
setMemoryManager(memoryMgr) {
|
|
237
|
+
this._memoryManager = memoryMgr;
|
|
238
|
+
}
|
|
239
|
+
transcode(src, dst, level, width, height, uncompressedByteLength, ktx2Reader, imageDesc, encodedData) {
|
|
240
|
+
return this._loadModule().then((moduleWrapper) => {
|
|
241
|
+
const transcoder = moduleWrapper.module;
|
|
242
|
+
const [textureView, uncompressedTextureView, nBlocks] = this._prepareTranscoding(width, height, uncompressedByteLength, encodedData);
|
|
243
|
+
return transcoder.transcode(nBlocks) === 0 ? (this._transcodeInPlace ? textureView.slice() : uncompressedTextureView.slice()) : null;
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
_prepareTranscoding(width, height, uncompressedByteLength, encodedData, forceRGBA = false) {
|
|
247
|
+
const nBlocks = ((width + 3) >> 2) * ((height + 3) >> 2);
|
|
248
|
+
if (forceRGBA) {
|
|
249
|
+
uncompressedByteLength = width * ((height + 3) >> 2) * 4 * 4;
|
|
250
|
+
}
|
|
251
|
+
const texMemoryPages = ((nBlocks * 16 + 65535 + (this._transcodeInPlace ? 0 : uncompressedByteLength)) >> 16) + 1;
|
|
252
|
+
const textureView = this.memoryManager.getMemoryView(texMemoryPages, 65536, nBlocks * 16);
|
|
253
|
+
const uncompressedTextureView = this._transcodeInPlace
|
|
254
|
+
? null
|
|
255
|
+
: new Uint8Array(this._memoryManager.wasmMemory.buffer, 65536 + nBlocks * 16, forceRGBA ? width * height * 4 : uncompressedByteLength);
|
|
256
|
+
textureView.set(encodedData);
|
|
257
|
+
return [textureView, uncompressedTextureView, nBlocks];
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
260
|
|
|
261
261
|
|
|
262
262
|
/***/ }),
|
|
@@ -273,30 +273,30 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
273
273
|
/* harmony export */ });
|
|
274
274
|
/* harmony import */ var _transcoder__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../transcoder */ "../../../tools/ktx2Decoder/dist/transcoder.js");
|
|
275
275
|
/* harmony import */ var _liteTranscoder__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./liteTranscoder */ "../../../tools/ktx2Decoder/dist/Transcoders/liteTranscoder.js");
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
/**
|
|
279
|
-
* @hidden
|
|
280
|
-
*/
|
|
281
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
282
|
-
class LiteTranscoder_UASTC_ASTC extends _liteTranscoder__WEBPACK_IMPORTED_MODULE_1__.LiteTranscoder {
|
|
283
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
284
|
-
static CanTranscode(src, dst, isInGammaSpace) {
|
|
285
|
-
return src === _transcoder__WEBPACK_IMPORTED_MODULE_0__.sourceTextureFormat.UASTC4x4 && dst === _transcoder__WEBPACK_IMPORTED_MODULE_0__.transcodeTarget.ASTC_4x4_RGBA;
|
|
286
|
-
}
|
|
287
|
-
getName() {
|
|
288
|
-
return LiteTranscoder_UASTC_ASTC.Name;
|
|
289
|
-
}
|
|
290
|
-
initialize() {
|
|
291
|
-
super.initialize();
|
|
292
|
-
this.setModulePath(LiteTranscoder_UASTC_ASTC.WasmModuleURL);
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
/**
|
|
296
|
-
* URL to use when loading the wasm module for the transcoder
|
|
297
|
-
*/
|
|
298
|
-
LiteTranscoder_UASTC_ASTC.WasmModuleURL = "https://preview.babylonjs.com/ktx2Transcoders/uastc_astc.wasm";
|
|
299
|
-
LiteTranscoder_UASTC_ASTC.Name = "UniversalTranscoder_UASTC_ASTC";
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* @hidden
|
|
280
|
+
*/
|
|
281
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
282
|
+
class LiteTranscoder_UASTC_ASTC extends _liteTranscoder__WEBPACK_IMPORTED_MODULE_1__.LiteTranscoder {
|
|
283
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
284
|
+
static CanTranscode(src, dst, isInGammaSpace) {
|
|
285
|
+
return src === _transcoder__WEBPACK_IMPORTED_MODULE_0__.sourceTextureFormat.UASTC4x4 && dst === _transcoder__WEBPACK_IMPORTED_MODULE_0__.transcodeTarget.ASTC_4x4_RGBA;
|
|
286
|
+
}
|
|
287
|
+
getName() {
|
|
288
|
+
return LiteTranscoder_UASTC_ASTC.Name;
|
|
289
|
+
}
|
|
290
|
+
initialize() {
|
|
291
|
+
super.initialize();
|
|
292
|
+
this.setModulePath(LiteTranscoder_UASTC_ASTC.WasmModuleURL);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* URL to use when loading the wasm module for the transcoder
|
|
297
|
+
*/
|
|
298
|
+
LiteTranscoder_UASTC_ASTC.WasmModuleURL = "https://preview.babylonjs.com/ktx2Transcoders/uastc_astc.wasm";
|
|
299
|
+
LiteTranscoder_UASTC_ASTC.Name = "UniversalTranscoder_UASTC_ASTC";
|
|
300
300
|
|
|
301
301
|
|
|
302
302
|
/***/ }),
|
|
@@ -313,30 +313,30 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
313
313
|
/* harmony export */ });
|
|
314
314
|
/* harmony import */ var _transcoder__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../transcoder */ "../../../tools/ktx2Decoder/dist/transcoder.js");
|
|
315
315
|
/* harmony import */ var _liteTranscoder__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./liteTranscoder */ "../../../tools/ktx2Decoder/dist/Transcoders/liteTranscoder.js");
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
/**
|
|
319
|
-
* @hidden
|
|
320
|
-
*/
|
|
321
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
322
|
-
class LiteTranscoder_UASTC_BC7 extends _liteTranscoder__WEBPACK_IMPORTED_MODULE_1__.LiteTranscoder {
|
|
323
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
324
|
-
static CanTranscode(src, dst, isInGammaSpace) {
|
|
325
|
-
return src === _transcoder__WEBPACK_IMPORTED_MODULE_0__.sourceTextureFormat.UASTC4x4 && dst === _transcoder__WEBPACK_IMPORTED_MODULE_0__.transcodeTarget.BC7_RGBA;
|
|
326
|
-
}
|
|
327
|
-
getName() {
|
|
328
|
-
return LiteTranscoder_UASTC_BC7.Name;
|
|
329
|
-
}
|
|
330
|
-
initialize() {
|
|
331
|
-
super.initialize();
|
|
332
|
-
this.setModulePath(LiteTranscoder_UASTC_BC7.WasmModuleURL);
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
/**
|
|
336
|
-
* URL to use when loading the wasm module for the transcoder
|
|
337
|
-
*/
|
|
338
|
-
LiteTranscoder_UASTC_BC7.WasmModuleURL = "https://preview.babylonjs.com/ktx2Transcoders/uastc_bc7.wasm";
|
|
339
|
-
LiteTranscoder_UASTC_BC7.Name = "UniversalTranscoder_UASTC_BC7";
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* @hidden
|
|
320
|
+
*/
|
|
321
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
322
|
+
class LiteTranscoder_UASTC_BC7 extends _liteTranscoder__WEBPACK_IMPORTED_MODULE_1__.LiteTranscoder {
|
|
323
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
324
|
+
static CanTranscode(src, dst, isInGammaSpace) {
|
|
325
|
+
return src === _transcoder__WEBPACK_IMPORTED_MODULE_0__.sourceTextureFormat.UASTC4x4 && dst === _transcoder__WEBPACK_IMPORTED_MODULE_0__.transcodeTarget.BC7_RGBA;
|
|
326
|
+
}
|
|
327
|
+
getName() {
|
|
328
|
+
return LiteTranscoder_UASTC_BC7.Name;
|
|
329
|
+
}
|
|
330
|
+
initialize() {
|
|
331
|
+
super.initialize();
|
|
332
|
+
this.setModulePath(LiteTranscoder_UASTC_BC7.WasmModuleURL);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* URL to use when loading the wasm module for the transcoder
|
|
337
|
+
*/
|
|
338
|
+
LiteTranscoder_UASTC_BC7.WasmModuleURL = "https://preview.babylonjs.com/ktx2Transcoders/uastc_bc7.wasm";
|
|
339
|
+
LiteTranscoder_UASTC_BC7.Name = "UniversalTranscoder_UASTC_BC7";
|
|
340
340
|
|
|
341
341
|
|
|
342
342
|
/***/ }),
|
|
@@ -353,37 +353,37 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
353
353
|
/* harmony export */ });
|
|
354
354
|
/* harmony import */ var _transcoder__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../transcoder */ "../../../tools/ktx2Decoder/dist/transcoder.js");
|
|
355
355
|
/* harmony import */ var _liteTranscoder__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./liteTranscoder */ "../../../tools/ktx2Decoder/dist/Transcoders/liteTranscoder.js");
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
/**
|
|
359
|
-
* @hidden
|
|
360
|
-
*/
|
|
361
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
362
|
-
class LiteTranscoder_UASTC_RGBA_SRGB extends _liteTranscoder__WEBPACK_IMPORTED_MODULE_1__.LiteTranscoder {
|
|
363
|
-
static CanTranscode(src, dst, isInGammaSpace) {
|
|
364
|
-
return src === _transcoder__WEBPACK_IMPORTED_MODULE_0__.sourceTextureFormat.UASTC4x4 && dst === _transcoder__WEBPACK_IMPORTED_MODULE_0__.transcodeTarget.RGBA32 && isInGammaSpace;
|
|
365
|
-
}
|
|
366
|
-
getName() {
|
|
367
|
-
return LiteTranscoder_UASTC_RGBA_SRGB.Name;
|
|
368
|
-
}
|
|
369
|
-
initialize() {
|
|
370
|
-
super.initialize();
|
|
371
|
-
this._transcodeInPlace = false;
|
|
372
|
-
this.setModulePath(LiteTranscoder_UASTC_RGBA_SRGB.WasmModuleURL);
|
|
373
|
-
}
|
|
374
|
-
transcode(src, dst, level, width, height, uncompressedByteLength, ktx2Reader, imageDesc, encodedData) {
|
|
375
|
-
return this._loadModule().then((moduleWrapper) => {
|
|
376
|
-
const transcoder = moduleWrapper.module;
|
|
377
|
-
const [, uncompressedTextureView] = this._prepareTranscoding(width, height, uncompressedByteLength, encodedData, true);
|
|
378
|
-
return transcoder.decodeRGBA32(width, height) === 0 ? uncompressedTextureView.slice() : null;
|
|
379
|
-
});
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
/**
|
|
383
|
-
* URL to use when loading the wasm module for the transcoder (srgb)
|
|
384
|
-
*/
|
|
385
|
-
LiteTranscoder_UASTC_RGBA_SRGB.WasmModuleURL = "https://preview.babylonjs.com/ktx2Transcoders/uastc_rgba32_srgb.wasm";
|
|
386
|
-
LiteTranscoder_UASTC_RGBA_SRGB.Name = "UniversalTranscoder_UASTC_RGBA_SRGB";
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* @hidden
|
|
360
|
+
*/
|
|
361
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
362
|
+
class LiteTranscoder_UASTC_RGBA_SRGB extends _liteTranscoder__WEBPACK_IMPORTED_MODULE_1__.LiteTranscoder {
|
|
363
|
+
static CanTranscode(src, dst, isInGammaSpace) {
|
|
364
|
+
return src === _transcoder__WEBPACK_IMPORTED_MODULE_0__.sourceTextureFormat.UASTC4x4 && dst === _transcoder__WEBPACK_IMPORTED_MODULE_0__.transcodeTarget.RGBA32 && isInGammaSpace;
|
|
365
|
+
}
|
|
366
|
+
getName() {
|
|
367
|
+
return LiteTranscoder_UASTC_RGBA_SRGB.Name;
|
|
368
|
+
}
|
|
369
|
+
initialize() {
|
|
370
|
+
super.initialize();
|
|
371
|
+
this._transcodeInPlace = false;
|
|
372
|
+
this.setModulePath(LiteTranscoder_UASTC_RGBA_SRGB.WasmModuleURL);
|
|
373
|
+
}
|
|
374
|
+
transcode(src, dst, level, width, height, uncompressedByteLength, ktx2Reader, imageDesc, encodedData) {
|
|
375
|
+
return this._loadModule().then((moduleWrapper) => {
|
|
376
|
+
const transcoder = moduleWrapper.module;
|
|
377
|
+
const [, uncompressedTextureView] = this._prepareTranscoding(width, height, uncompressedByteLength, encodedData, true);
|
|
378
|
+
return transcoder.decodeRGBA32(width, height) === 0 ? uncompressedTextureView.slice() : null;
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* URL to use when loading the wasm module for the transcoder (srgb)
|
|
384
|
+
*/
|
|
385
|
+
LiteTranscoder_UASTC_RGBA_SRGB.WasmModuleURL = "https://preview.babylonjs.com/ktx2Transcoders/uastc_rgba32_srgb.wasm";
|
|
386
|
+
LiteTranscoder_UASTC_RGBA_SRGB.Name = "UniversalTranscoder_UASTC_RGBA_SRGB";
|
|
387
387
|
|
|
388
388
|
|
|
389
389
|
/***/ }),
|
|
@@ -400,37 +400,37 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
400
400
|
/* harmony export */ });
|
|
401
401
|
/* harmony import */ var _transcoder__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../transcoder */ "../../../tools/ktx2Decoder/dist/transcoder.js");
|
|
402
402
|
/* harmony import */ var _liteTranscoder__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./liteTranscoder */ "../../../tools/ktx2Decoder/dist/Transcoders/liteTranscoder.js");
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
/**
|
|
406
|
-
* @hidden
|
|
407
|
-
*/
|
|
408
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
409
|
-
class LiteTranscoder_UASTC_RGBA_UNORM extends _liteTranscoder__WEBPACK_IMPORTED_MODULE_1__.LiteTranscoder {
|
|
410
|
-
static CanTranscode(src, dst, isInGammaSpace) {
|
|
411
|
-
return src === _transcoder__WEBPACK_IMPORTED_MODULE_0__.sourceTextureFormat.UASTC4x4 && dst === _transcoder__WEBPACK_IMPORTED_MODULE_0__.transcodeTarget.RGBA32 && !isInGammaSpace;
|
|
412
|
-
}
|
|
413
|
-
getName() {
|
|
414
|
-
return LiteTranscoder_UASTC_RGBA_UNORM.Name;
|
|
415
|
-
}
|
|
416
|
-
initialize() {
|
|
417
|
-
super.initialize();
|
|
418
|
-
this._transcodeInPlace = false;
|
|
419
|
-
this.setModulePath(LiteTranscoder_UASTC_RGBA_UNORM.WasmModuleURL);
|
|
420
|
-
}
|
|
421
|
-
transcode(src, dst, level, width, height, uncompressedByteLength, ktx2Reader, imageDesc, encodedData) {
|
|
422
|
-
return this._loadModule().then((moduleWrapper) => {
|
|
423
|
-
const transcoder = moduleWrapper.module;
|
|
424
|
-
const [, uncompressedTextureView] = this._prepareTranscoding(width, height, uncompressedByteLength, encodedData, true);
|
|
425
|
-
return transcoder.decodeRGBA32(width, height) === 0 ? uncompressedTextureView.slice() : null;
|
|
426
|
-
});
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
/**
|
|
430
|
-
* URL to use when loading the wasm module for the transcoder (unorm)
|
|
431
|
-
*/
|
|
432
|
-
LiteTranscoder_UASTC_RGBA_UNORM.WasmModuleURL = "https://preview.babylonjs.com/ktx2Transcoders/uastc_rgba32_unorm.wasm";
|
|
433
|
-
LiteTranscoder_UASTC_RGBA_UNORM.Name = "UniversalTranscoder_UASTC_RGBA_UNORM";
|
|
403
|
+
|
|
404
|
+
|
|
405
|
+
/**
|
|
406
|
+
* @hidden
|
|
407
|
+
*/
|
|
408
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
409
|
+
class LiteTranscoder_UASTC_RGBA_UNORM extends _liteTranscoder__WEBPACK_IMPORTED_MODULE_1__.LiteTranscoder {
|
|
410
|
+
static CanTranscode(src, dst, isInGammaSpace) {
|
|
411
|
+
return src === _transcoder__WEBPACK_IMPORTED_MODULE_0__.sourceTextureFormat.UASTC4x4 && dst === _transcoder__WEBPACK_IMPORTED_MODULE_0__.transcodeTarget.RGBA32 && !isInGammaSpace;
|
|
412
|
+
}
|
|
413
|
+
getName() {
|
|
414
|
+
return LiteTranscoder_UASTC_RGBA_UNORM.Name;
|
|
415
|
+
}
|
|
416
|
+
initialize() {
|
|
417
|
+
super.initialize();
|
|
418
|
+
this._transcodeInPlace = false;
|
|
419
|
+
this.setModulePath(LiteTranscoder_UASTC_RGBA_UNORM.WasmModuleURL);
|
|
420
|
+
}
|
|
421
|
+
transcode(src, dst, level, width, height, uncompressedByteLength, ktx2Reader, imageDesc, encodedData) {
|
|
422
|
+
return this._loadModule().then((moduleWrapper) => {
|
|
423
|
+
const transcoder = moduleWrapper.module;
|
|
424
|
+
const [, uncompressedTextureView] = this._prepareTranscoding(width, height, uncompressedByteLength, encodedData, true);
|
|
425
|
+
return transcoder.decodeRGBA32(width, height) === 0 ? uncompressedTextureView.slice() : null;
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
/**
|
|
430
|
+
* URL to use when loading the wasm module for the transcoder (unorm)
|
|
431
|
+
*/
|
|
432
|
+
LiteTranscoder_UASTC_RGBA_UNORM.WasmModuleURL = "https://preview.babylonjs.com/ktx2Transcoders/uastc_rgba32_unorm.wasm";
|
|
433
|
+
LiteTranscoder_UASTC_RGBA_UNORM.Name = "UniversalTranscoder_UASTC_RGBA_UNORM";
|
|
434
434
|
|
|
435
435
|
|
|
436
436
|
/***/ }),
|
|
@@ -447,119 +447,119 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
447
447
|
/* harmony export */ });
|
|
448
448
|
/* harmony import */ var _transcoder__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../transcoder */ "../../../tools/ktx2Decoder/dist/transcoder.js");
|
|
449
449
|
/* harmony import */ var _wasmMemoryManager__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../wasmMemoryManager */ "../../../tools/ktx2Decoder/dist/wasmMemoryManager.js");
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
/**
|
|
453
|
-
* @hidden
|
|
454
|
-
*/
|
|
455
|
-
class MSCTranscoder extends _transcoder__WEBPACK_IMPORTED_MODULE_0__.Transcoder {
|
|
456
|
-
getName() {
|
|
457
|
-
return MSCTranscoder.Name;
|
|
458
|
-
}
|
|
459
|
-
_getMSCBasisTranscoder() {
|
|
460
|
-
if (this._mscBasisTranscoderPromise) {
|
|
461
|
-
return this._mscBasisTranscoderPromise;
|
|
462
|
-
}
|
|
463
|
-
this._mscBasisTranscoderPromise = _wasmMemoryManager__WEBPACK_IMPORTED_MODULE_1__.WASMMemoryManager.LoadWASM(MSCTranscoder.WasmModuleURL).then((wasmBinary) => {
|
|
464
|
-
if (MSCTranscoder.UseFromWorkerThread) {
|
|
465
|
-
importScripts(MSCTranscoder.JSModuleURL);
|
|
466
|
-
}
|
|
467
|
-
// Worker Number = 0 and MSC_TRANSCODER has not been loaded yet.
|
|
468
|
-
else if (typeof MSC_TRANSCODER === "undefined") {
|
|
469
|
-
return new Promise((resolve, reject) => {
|
|
470
|
-
const head = document.getElementsByTagName("head")[0];
|
|
471
|
-
const script = document.createElement("script");
|
|
472
|
-
script.setAttribute("type", "text/javascript");
|
|
473
|
-
script.setAttribute("src", MSCTranscoder.JSModuleURL);
|
|
474
|
-
script.onload = () => {
|
|
475
|
-
MSC_TRANSCODER({ wasmBinary }).then((basisModule) => {
|
|
476
|
-
basisModule.initTranscoders();
|
|
477
|
-
this._mscBasisModule = basisModule;
|
|
478
|
-
resolve();
|
|
479
|
-
});
|
|
480
|
-
};
|
|
481
|
-
script.onerror = () => {
|
|
482
|
-
reject("Can not load MSC_TRANSCODER script.");
|
|
483
|
-
};
|
|
484
|
-
head.appendChild(script);
|
|
485
|
-
});
|
|
486
|
-
}
|
|
487
|
-
return new Promise((resolve) => {
|
|
488
|
-
MSC_TRANSCODER({ wasmBinary }).then((basisModule) => {
|
|
489
|
-
basisModule.initTranscoders();
|
|
490
|
-
this._mscBasisModule = basisModule;
|
|
491
|
-
resolve();
|
|
492
|
-
});
|
|
493
|
-
});
|
|
494
|
-
});
|
|
495
|
-
return this._mscBasisTranscoderPromise;
|
|
496
|
-
}
|
|
497
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
498
|
-
static CanTranscode(src, dst, isInGammaSpace) {
|
|
499
|
-
return true;
|
|
500
|
-
}
|
|
501
|
-
transcode(src, dst, level, width, height, uncompressedByteLength, ktx2Reader, imageDesc, encodedData) {
|
|
502
|
-
const isVideo = false;
|
|
503
|
-
return this._getMSCBasisTranscoder().then(() => {
|
|
504
|
-
const basisModule = this._mscBasisModule;
|
|
505
|
-
let transcoder;
|
|
506
|
-
let imageInfo;
|
|
507
|
-
let result;
|
|
508
|
-
let textureData = null;
|
|
509
|
-
try {
|
|
510
|
-
transcoder = src === _transcoder__WEBPACK_IMPORTED_MODULE_0__.sourceTextureFormat.UASTC4x4 ? new basisModule.UastcImageTranscoder() : new basisModule.BasisLzEtc1sImageTranscoder();
|
|
511
|
-
const texFormat = src === _transcoder__WEBPACK_IMPORTED_MODULE_0__.sourceTextureFormat.UASTC4x4 ? basisModule.TextureFormat.UASTC4x4 : basisModule.TextureFormat.ETC1S;
|
|
512
|
-
imageInfo = new basisModule.ImageInfo(texFormat, width, height, level);
|
|
513
|
-
const targetFormat = basisModule.TranscodeTarget[_transcoder__WEBPACK_IMPORTED_MODULE_0__.transcodeTarget[dst]]; // works because the labels of the sourceTextureFormat enum are the same as the property names used in TranscodeTarget!
|
|
514
|
-
if (!basisModule.isFormatSupported(targetFormat, texFormat)) {
|
|
515
|
-
throw new Error(`MSCTranscoder: Transcoding from "${_transcoder__WEBPACK_IMPORTED_MODULE_0__.sourceTextureFormat[src]}" to "${_transcoder__WEBPACK_IMPORTED_MODULE_0__.transcodeTarget[dst]}" not supported by current transcoder build.`);
|
|
516
|
-
}
|
|
517
|
-
if (src === _transcoder__WEBPACK_IMPORTED_MODULE_0__.sourceTextureFormat.ETC1S) {
|
|
518
|
-
const sgd = ktx2Reader.supercompressionGlobalData;
|
|
519
|
-
transcoder.decodePalettes(sgd.endpointCount, sgd.endpointsData, sgd.selectorCount, sgd.selectorsData);
|
|
520
|
-
transcoder.decodeTables(sgd.tablesData);
|
|
521
|
-
imageInfo.flags = imageDesc.imageFlags;
|
|
522
|
-
imageInfo.rgbByteOffset = 0;
|
|
523
|
-
imageInfo.rgbByteLength = imageDesc.rgbSliceByteLength;
|
|
524
|
-
imageInfo.alphaByteOffset = imageDesc.alphaSliceByteOffset > 0 ? imageDesc.rgbSliceByteLength : 0;
|
|
525
|
-
imageInfo.alphaByteLength = imageDesc.alphaSliceByteLength;
|
|
526
|
-
result = transcoder.transcodeImage(targetFormat, encodedData, imageInfo, 0, isVideo);
|
|
527
|
-
}
|
|
528
|
-
else {
|
|
529
|
-
imageInfo.flags = 0;
|
|
530
|
-
imageInfo.rgbByteOffset = 0;
|
|
531
|
-
imageInfo.rgbByteLength = uncompressedByteLength;
|
|
532
|
-
imageInfo.alphaByteOffset = 0;
|
|
533
|
-
imageInfo.alphaByteLength = 0;
|
|
534
|
-
result = transcoder.transcodeImage(targetFormat, encodedData, imageInfo, 0, ktx2Reader.hasAlpha, isVideo);
|
|
535
|
-
}
|
|
536
|
-
}
|
|
537
|
-
finally {
|
|
538
|
-
if (transcoder) {
|
|
539
|
-
transcoder.delete();
|
|
540
|
-
}
|
|
541
|
-
if (imageInfo) {
|
|
542
|
-
imageInfo.delete();
|
|
543
|
-
}
|
|
544
|
-
if (result && result.transcodedImage) {
|
|
545
|
-
textureData = result.transcodedImage.get_typed_memory_view().slice();
|
|
546
|
-
result.transcodedImage.delete();
|
|
547
|
-
}
|
|
548
|
-
}
|
|
549
|
-
return textureData;
|
|
550
|
-
});
|
|
551
|
-
}
|
|
552
|
-
}
|
|
553
|
-
/**
|
|
554
|
-
* URL to use when loading the MSC transcoder
|
|
555
|
-
*/
|
|
556
|
-
MSCTranscoder.JSModuleURL = "https://preview.babylonjs.com/ktx2Transcoders/msc_basis_transcoder.js";
|
|
557
|
-
/**
|
|
558
|
-
* URL to use when loading the wasm module for the transcoder
|
|
559
|
-
*/
|
|
560
|
-
MSCTranscoder.WasmModuleURL = "https://preview.babylonjs.com/ktx2Transcoders/msc_basis_transcoder.wasm";
|
|
561
|
-
MSCTranscoder.UseFromWorkerThread = true;
|
|
562
|
-
MSCTranscoder.Name = "MSCTranscoder";
|
|
450
|
+
|
|
451
|
+
|
|
452
|
+
/**
|
|
453
|
+
* @hidden
|
|
454
|
+
*/
|
|
455
|
+
class MSCTranscoder extends _transcoder__WEBPACK_IMPORTED_MODULE_0__.Transcoder {
|
|
456
|
+
getName() {
|
|
457
|
+
return MSCTranscoder.Name;
|
|
458
|
+
}
|
|
459
|
+
_getMSCBasisTranscoder() {
|
|
460
|
+
if (this._mscBasisTranscoderPromise) {
|
|
461
|
+
return this._mscBasisTranscoderPromise;
|
|
462
|
+
}
|
|
463
|
+
this._mscBasisTranscoderPromise = _wasmMemoryManager__WEBPACK_IMPORTED_MODULE_1__.WASMMemoryManager.LoadWASM(MSCTranscoder.WasmModuleURL).then((wasmBinary) => {
|
|
464
|
+
if (MSCTranscoder.UseFromWorkerThread) {
|
|
465
|
+
importScripts(MSCTranscoder.JSModuleURL);
|
|
466
|
+
}
|
|
467
|
+
// Worker Number = 0 and MSC_TRANSCODER has not been loaded yet.
|
|
468
|
+
else if (typeof MSC_TRANSCODER === "undefined") {
|
|
469
|
+
return new Promise((resolve, reject) => {
|
|
470
|
+
const head = document.getElementsByTagName("head")[0];
|
|
471
|
+
const script = document.createElement("script");
|
|
472
|
+
script.setAttribute("type", "text/javascript");
|
|
473
|
+
script.setAttribute("src", MSCTranscoder.JSModuleURL);
|
|
474
|
+
script.onload = () => {
|
|
475
|
+
MSC_TRANSCODER({ wasmBinary }).then((basisModule) => {
|
|
476
|
+
basisModule.initTranscoders();
|
|
477
|
+
this._mscBasisModule = basisModule;
|
|
478
|
+
resolve();
|
|
479
|
+
});
|
|
480
|
+
};
|
|
481
|
+
script.onerror = () => {
|
|
482
|
+
reject("Can not load MSC_TRANSCODER script.");
|
|
483
|
+
};
|
|
484
|
+
head.appendChild(script);
|
|
485
|
+
});
|
|
486
|
+
}
|
|
487
|
+
return new Promise((resolve) => {
|
|
488
|
+
MSC_TRANSCODER({ wasmBinary }).then((basisModule) => {
|
|
489
|
+
basisModule.initTranscoders();
|
|
490
|
+
this._mscBasisModule = basisModule;
|
|
491
|
+
resolve();
|
|
492
|
+
});
|
|
493
|
+
});
|
|
494
|
+
});
|
|
495
|
+
return this._mscBasisTranscoderPromise;
|
|
496
|
+
}
|
|
497
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
498
|
+
static CanTranscode(src, dst, isInGammaSpace) {
|
|
499
|
+
return true;
|
|
500
|
+
}
|
|
501
|
+
transcode(src, dst, level, width, height, uncompressedByteLength, ktx2Reader, imageDesc, encodedData) {
|
|
502
|
+
const isVideo = false;
|
|
503
|
+
return this._getMSCBasisTranscoder().then(() => {
|
|
504
|
+
const basisModule = this._mscBasisModule;
|
|
505
|
+
let transcoder;
|
|
506
|
+
let imageInfo;
|
|
507
|
+
let result;
|
|
508
|
+
let textureData = null;
|
|
509
|
+
try {
|
|
510
|
+
transcoder = src === _transcoder__WEBPACK_IMPORTED_MODULE_0__.sourceTextureFormat.UASTC4x4 ? new basisModule.UastcImageTranscoder() : new basisModule.BasisLzEtc1sImageTranscoder();
|
|
511
|
+
const texFormat = src === _transcoder__WEBPACK_IMPORTED_MODULE_0__.sourceTextureFormat.UASTC4x4 ? basisModule.TextureFormat.UASTC4x4 : basisModule.TextureFormat.ETC1S;
|
|
512
|
+
imageInfo = new basisModule.ImageInfo(texFormat, width, height, level);
|
|
513
|
+
const targetFormat = basisModule.TranscodeTarget[_transcoder__WEBPACK_IMPORTED_MODULE_0__.transcodeTarget[dst]]; // works because the labels of the sourceTextureFormat enum are the same as the property names used in TranscodeTarget!
|
|
514
|
+
if (!basisModule.isFormatSupported(targetFormat, texFormat)) {
|
|
515
|
+
throw new Error(`MSCTranscoder: Transcoding from "${_transcoder__WEBPACK_IMPORTED_MODULE_0__.sourceTextureFormat[src]}" to "${_transcoder__WEBPACK_IMPORTED_MODULE_0__.transcodeTarget[dst]}" not supported by current transcoder build.`);
|
|
516
|
+
}
|
|
517
|
+
if (src === _transcoder__WEBPACK_IMPORTED_MODULE_0__.sourceTextureFormat.ETC1S) {
|
|
518
|
+
const sgd = ktx2Reader.supercompressionGlobalData;
|
|
519
|
+
transcoder.decodePalettes(sgd.endpointCount, sgd.endpointsData, sgd.selectorCount, sgd.selectorsData);
|
|
520
|
+
transcoder.decodeTables(sgd.tablesData);
|
|
521
|
+
imageInfo.flags = imageDesc.imageFlags;
|
|
522
|
+
imageInfo.rgbByteOffset = 0;
|
|
523
|
+
imageInfo.rgbByteLength = imageDesc.rgbSliceByteLength;
|
|
524
|
+
imageInfo.alphaByteOffset = imageDesc.alphaSliceByteOffset > 0 ? imageDesc.rgbSliceByteLength : 0;
|
|
525
|
+
imageInfo.alphaByteLength = imageDesc.alphaSliceByteLength;
|
|
526
|
+
result = transcoder.transcodeImage(targetFormat, encodedData, imageInfo, 0, isVideo);
|
|
527
|
+
}
|
|
528
|
+
else {
|
|
529
|
+
imageInfo.flags = 0;
|
|
530
|
+
imageInfo.rgbByteOffset = 0;
|
|
531
|
+
imageInfo.rgbByteLength = uncompressedByteLength;
|
|
532
|
+
imageInfo.alphaByteOffset = 0;
|
|
533
|
+
imageInfo.alphaByteLength = 0;
|
|
534
|
+
result = transcoder.transcodeImage(targetFormat, encodedData, imageInfo, 0, ktx2Reader.hasAlpha, isVideo);
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
finally {
|
|
538
|
+
if (transcoder) {
|
|
539
|
+
transcoder.delete();
|
|
540
|
+
}
|
|
541
|
+
if (imageInfo) {
|
|
542
|
+
imageInfo.delete();
|
|
543
|
+
}
|
|
544
|
+
if (result && result.transcodedImage) {
|
|
545
|
+
textureData = result.transcodedImage.get_typed_memory_view().slice();
|
|
546
|
+
result.transcodedImage.delete();
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
return textureData;
|
|
550
|
+
});
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
/**
|
|
554
|
+
* URL to use when loading the MSC transcoder
|
|
555
|
+
*/
|
|
556
|
+
MSCTranscoder.JSModuleURL = "https://preview.babylonjs.com/ktx2Transcoders/msc_basis_transcoder.js";
|
|
557
|
+
/**
|
|
558
|
+
* URL to use when loading the wasm module for the transcoder
|
|
559
|
+
*/
|
|
560
|
+
MSCTranscoder.WasmModuleURL = "https://preview.babylonjs.com/ktx2Transcoders/msc_basis_transcoder.wasm";
|
|
561
|
+
MSCTranscoder.UseFromWorkerThread = true;
|
|
562
|
+
MSCTranscoder.Name = "MSCTranscoder";
|
|
563
563
|
|
|
564
564
|
|
|
565
565
|
/***/ }),
|
|
@@ -597,14 +597,14 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
597
597
|
/* harmony import */ var _zstddec__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./zstddec */ "../../../tools/ktx2Decoder/dist/zstddec.js");
|
|
598
598
|
/* harmony import */ var _Misc_index__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./Misc/index */ "../../../tools/ktx2Decoder/dist/Misc/index.js");
|
|
599
599
|
/* harmony import */ var _Transcoders_index__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./Transcoders/index */ "../../../tools/ktx2Decoder/dist/Transcoders/index.js");
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
600
|
+
|
|
601
|
+
|
|
602
|
+
|
|
603
|
+
|
|
604
|
+
|
|
605
|
+
|
|
606
|
+
|
|
607
|
+
|
|
608
608
|
|
|
609
609
|
|
|
610
610
|
/***/ }),
|
|
@@ -629,141 +629,141 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
629
629
|
/* harmony import */ var _transcoder__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./transcoder */ "../../../tools/ktx2Decoder/dist/transcoder.js");
|
|
630
630
|
/* harmony import */ var _zstddec__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./zstddec */ "../../../tools/ktx2Decoder/dist/zstddec.js");
|
|
631
631
|
/* harmony import */ var _transcodeDecisionTree__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ./transcodeDecisionTree */ "../../../tools/ktx2Decoder/dist/transcodeDecisionTree.js");
|
|
632
|
-
/**
|
|
633
|
-
* Resources used for the implementation:
|
|
634
|
-
* - 3js KTX2 loader: https://github.com/mrdoob/three.js/blob/dfb5c23ce126ec845e4aa240599915fef5375797/examples/jsm/loaders/KTX2Loader.js
|
|
635
|
-
* - Universal Texture Transcoders: https://github.com/KhronosGroup/Universal-Texture-Transcoders
|
|
636
|
-
* - KTX2 specification: http://github.khronos.org/KTX-Specification/
|
|
637
|
-
* - KTX2 binaries to convert files: https://github.com/KhronosGroup/KTX-Software/releases
|
|
638
|
-
* - KTX specification: https://www.khronos.org/registry/DataFormat/specs/1.3/dataformat.1.3.html
|
|
639
|
-
* - KTX-Software: https://github.com/KhronosGroup/KTX-Software
|
|
640
|
-
*/
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
const isPowerOfTwo = (value) => {
|
|
652
|
-
return (value & (value - 1)) === 0 && value !== 0;
|
|
653
|
-
};
|
|
654
|
-
/**
|
|
655
|
-
* Class for decoding KTX2 files
|
|
656
|
-
*
|
|
657
|
-
*/
|
|
658
|
-
class KTX2Decoder {
|
|
659
|
-
constructor() {
|
|
660
|
-
this._transcoderMgr = new _transcoderManager__WEBPACK_IMPORTED_MODULE_1__.TranscoderManager();
|
|
661
|
-
}
|
|
662
|
-
decode(data, caps, options) {
|
|
663
|
-
return Promise.resolve().then(() => {
|
|
664
|
-
const kfr = new _ktx2FileReader__WEBPACK_IMPORTED_MODULE_0__.KTX2FileReader(data);
|
|
665
|
-
if (!kfr.isValid()) {
|
|
666
|
-
throw new Error("Invalid KT2 file: wrong signature");
|
|
667
|
-
}
|
|
668
|
-
kfr.parse();
|
|
669
|
-
if (kfr.needZSTDDecoder) {
|
|
670
|
-
if (!this._zstdDecoder) {
|
|
671
|
-
this._zstdDecoder = new _zstddec__WEBPACK_IMPORTED_MODULE_8__.ZSTDDecoder();
|
|
672
|
-
}
|
|
673
|
-
return this._zstdDecoder.init().then(() => {
|
|
674
|
-
return this._decodeData(kfr, caps, options);
|
|
675
|
-
});
|
|
676
|
-
}
|
|
677
|
-
return this._decodeData(kfr, caps, options);
|
|
678
|
-
});
|
|
679
|
-
}
|
|
680
|
-
_decodeData(kfr, caps, options) {
|
|
681
|
-
const width = kfr.header.pixelWidth;
|
|
682
|
-
const height = kfr.header.pixelHeight;
|
|
683
|
-
const srcTexFormat = kfr.textureFormat;
|
|
684
|
-
const decisionTree = new _transcodeDecisionTree__WEBPACK_IMPORTED_MODULE_9__.TranscodeDecisionTree(srcTexFormat, kfr.hasAlpha, isPowerOfTwo(width) && isPowerOfTwo(height), caps, options);
|
|
685
|
-
const transcodeFormat = decisionTree.transcodeFormat;
|
|
686
|
-
const engineFormat = decisionTree.engineFormat;
|
|
687
|
-
const roundToMultiple4 = decisionTree.roundToMultiple4;
|
|
688
|
-
const transcoder = this._transcoderMgr.findTranscoder(srcTexFormat, transcodeFormat, kfr.isInGammaSpace, options === null || options === void 0 ? void 0 : options.bypassTranscoders);
|
|
689
|
-
if (transcoder === null) {
|
|
690
|
-
throw new Error(`no transcoder found to transcode source texture format "${_transcoder__WEBPACK_IMPORTED_MODULE_7__.sourceTextureFormat[srcTexFormat]}" to format "${_transcoder__WEBPACK_IMPORTED_MODULE_7__.transcodeTarget[transcodeFormat]}"`);
|
|
691
|
-
}
|
|
692
|
-
const mipmaps = [];
|
|
693
|
-
const dataPromises = [];
|
|
694
|
-
const decodedData = {
|
|
695
|
-
width: 0,
|
|
696
|
-
height: 0,
|
|
697
|
-
transcodedFormat: engineFormat,
|
|
698
|
-
mipmaps,
|
|
699
|
-
isInGammaSpace: kfr.isInGammaSpace,
|
|
700
|
-
hasAlpha: kfr.hasAlpha,
|
|
701
|
-
transcoderName: transcoder.getName(),
|
|
702
|
-
};
|
|
703
|
-
let firstImageDescIndex = 0;
|
|
704
|
-
for (let level = 0; level < kfr.header.levelCount; level++) {
|
|
705
|
-
if (level > 0) {
|
|
706
|
-
firstImageDescIndex += Math.max(kfr.header.layerCount, 1) * kfr.header.faceCount * Math.max(kfr.header.pixelDepth >> (level - 1), 1);
|
|
707
|
-
}
|
|
708
|
-
const levelWidth = Math.floor(width / (1 << level)) || 1;
|
|
709
|
-
const levelHeight = Math.floor(height / (1 << level)) || 1;
|
|
710
|
-
const numImagesInLevel = kfr.header.faceCount; // note that cubemap are not supported yet (see KTX2FileReader), so faceCount == 1
|
|
711
|
-
const levelImageByteLength = ((levelWidth + 3) >> 2) * ((levelHeight + 3) >> 2) * kfr.dfdBlock.bytesPlane[0];
|
|
712
|
-
const levelUncompressedByteLength = kfr.levels[level].uncompressedByteLength;
|
|
713
|
-
let levelDataBuffer = kfr.data.buffer;
|
|
714
|
-
let levelDataOffset = kfr.levels[level].byteOffset + kfr.data.byteOffset;
|
|
715
|
-
let imageOffsetInLevel = 0;
|
|
716
|
-
if (kfr.header.supercompressionScheme === _ktx2FileReader__WEBPACK_IMPORTED_MODULE_0__.SupercompressionScheme.ZStandard) {
|
|
717
|
-
levelDataBuffer = this._zstdDecoder.decode(new Uint8Array(levelDataBuffer, levelDataOffset, kfr.levels[level].byteLength), levelUncompressedByteLength);
|
|
718
|
-
levelDataOffset = 0;
|
|
719
|
-
}
|
|
720
|
-
if (level === 0) {
|
|
721
|
-
decodedData.width = roundToMultiple4 ? (levelWidth + 3) & ~3 : levelWidth;
|
|
722
|
-
decodedData.height = roundToMultiple4 ? (levelHeight + 3) & ~3 : levelHeight;
|
|
723
|
-
}
|
|
724
|
-
for (let imageIndex = 0; imageIndex < numImagesInLevel; imageIndex++) {
|
|
725
|
-
let encodedData;
|
|
726
|
-
let imageDesc = null;
|
|
727
|
-
if (kfr.header.supercompressionScheme === _ktx2FileReader__WEBPACK_IMPORTED_MODULE_0__.SupercompressionScheme.BasisLZ) {
|
|
728
|
-
imageDesc = kfr.supercompressionGlobalData.imageDescs[firstImageDescIndex + imageIndex];
|
|
729
|
-
encodedData = new Uint8Array(levelDataBuffer, levelDataOffset + imageDesc.rgbSliceByteOffset, imageDesc.rgbSliceByteLength + imageDesc.alphaSliceByteLength);
|
|
730
|
-
}
|
|
731
|
-
else {
|
|
732
|
-
encodedData = new Uint8Array(levelDataBuffer, levelDataOffset + imageOffsetInLevel, levelImageByteLength);
|
|
733
|
-
imageOffsetInLevel += levelImageByteLength;
|
|
734
|
-
}
|
|
735
|
-
const mipmap = {
|
|
736
|
-
data: null,
|
|
737
|
-
width: levelWidth,
|
|
738
|
-
height: levelHeight,
|
|
739
|
-
};
|
|
740
|
-
const transcodedData = transcoder
|
|
741
|
-
.transcode(srcTexFormat, transcodeFormat, level, levelWidth, levelHeight, levelUncompressedByteLength, kfr, imageDesc, encodedData)
|
|
742
|
-
.then((data) => {
|
|
743
|
-
mipmap.data = data;
|
|
744
|
-
return data;
|
|
745
|
-
})
|
|
746
|
-
.catch((reason) => {
|
|
747
|
-
var _a;
|
|
748
|
-
decodedData.errors = (_a = decodedData.errors) !== null && _a !== void 0 ? _a : "";
|
|
749
|
-
decodedData.errors += reason + "\n" + reason.stack + "\n";
|
|
750
|
-
return null;
|
|
751
|
-
});
|
|
752
|
-
dataPromises.push(transcodedData);
|
|
753
|
-
mipmaps.push(mipmap);
|
|
754
|
-
}
|
|
755
|
-
}
|
|
756
|
-
return Promise.all(dataPromises).then(() => {
|
|
757
|
-
return decodedData;
|
|
758
|
-
});
|
|
759
|
-
}
|
|
760
|
-
}
|
|
761
|
-
// Put in the order you want the transcoders to be used in priority
|
|
762
|
-
_transcoderManager__WEBPACK_IMPORTED_MODULE_1__.TranscoderManager.RegisterTranscoder(_Transcoders_liteTranscoder_UASTC_ASTC__WEBPACK_IMPORTED_MODULE_2__.LiteTranscoder_UASTC_ASTC);
|
|
763
|
-
_transcoderManager__WEBPACK_IMPORTED_MODULE_1__.TranscoderManager.RegisterTranscoder(_Transcoders_liteTranscoder_UASTC_BC7__WEBPACK_IMPORTED_MODULE_3__.LiteTranscoder_UASTC_BC7);
|
|
764
|
-
_transcoderManager__WEBPACK_IMPORTED_MODULE_1__.TranscoderManager.RegisterTranscoder(_Transcoders_liteTranscoder_UASTC_RGBA_UNORM__WEBPACK_IMPORTED_MODULE_4__.LiteTranscoder_UASTC_RGBA_UNORM);
|
|
765
|
-
_transcoderManager__WEBPACK_IMPORTED_MODULE_1__.TranscoderManager.RegisterTranscoder(_Transcoders_liteTranscoder_UASTC_RGBA_SRGB__WEBPACK_IMPORTED_MODULE_5__.LiteTranscoder_UASTC_RGBA_SRGB);
|
|
766
|
-
_transcoderManager__WEBPACK_IMPORTED_MODULE_1__.TranscoderManager.RegisterTranscoder(_Transcoders_mscTranscoder__WEBPACK_IMPORTED_MODULE_6__.MSCTranscoder); // catch all transcoder - will throw an error if the format can't be transcoded
|
|
632
|
+
/**
|
|
633
|
+
* Resources used for the implementation:
|
|
634
|
+
* - 3js KTX2 loader: https://github.com/mrdoob/three.js/blob/dfb5c23ce126ec845e4aa240599915fef5375797/examples/jsm/loaders/KTX2Loader.js
|
|
635
|
+
* - Universal Texture Transcoders: https://github.com/KhronosGroup/Universal-Texture-Transcoders
|
|
636
|
+
* - KTX2 specification: http://github.khronos.org/KTX-Specification/
|
|
637
|
+
* - KTX2 binaries to convert files: https://github.com/KhronosGroup/KTX-Software/releases
|
|
638
|
+
* - KTX specification: https://www.khronos.org/registry/DataFormat/specs/1.3/dataformat.1.3.html
|
|
639
|
+
* - KTX-Software: https://github.com/KhronosGroup/KTX-Software
|
|
640
|
+
*/
|
|
641
|
+
|
|
642
|
+
|
|
643
|
+
|
|
644
|
+
|
|
645
|
+
|
|
646
|
+
|
|
647
|
+
|
|
648
|
+
|
|
649
|
+
|
|
650
|
+
|
|
651
|
+
const isPowerOfTwo = (value) => {
|
|
652
|
+
return (value & (value - 1)) === 0 && value !== 0;
|
|
653
|
+
};
|
|
654
|
+
/**
|
|
655
|
+
* Class for decoding KTX2 files
|
|
656
|
+
*
|
|
657
|
+
*/
|
|
658
|
+
class KTX2Decoder {
|
|
659
|
+
constructor() {
|
|
660
|
+
this._transcoderMgr = new _transcoderManager__WEBPACK_IMPORTED_MODULE_1__.TranscoderManager();
|
|
661
|
+
}
|
|
662
|
+
decode(data, caps, options) {
|
|
663
|
+
return Promise.resolve().then(() => {
|
|
664
|
+
const kfr = new _ktx2FileReader__WEBPACK_IMPORTED_MODULE_0__.KTX2FileReader(data);
|
|
665
|
+
if (!kfr.isValid()) {
|
|
666
|
+
throw new Error("Invalid KT2 file: wrong signature");
|
|
667
|
+
}
|
|
668
|
+
kfr.parse();
|
|
669
|
+
if (kfr.needZSTDDecoder) {
|
|
670
|
+
if (!this._zstdDecoder) {
|
|
671
|
+
this._zstdDecoder = new _zstddec__WEBPACK_IMPORTED_MODULE_8__.ZSTDDecoder();
|
|
672
|
+
}
|
|
673
|
+
return this._zstdDecoder.init().then(() => {
|
|
674
|
+
return this._decodeData(kfr, caps, options);
|
|
675
|
+
});
|
|
676
|
+
}
|
|
677
|
+
return this._decodeData(kfr, caps, options);
|
|
678
|
+
});
|
|
679
|
+
}
|
|
680
|
+
_decodeData(kfr, caps, options) {
|
|
681
|
+
const width = kfr.header.pixelWidth;
|
|
682
|
+
const height = kfr.header.pixelHeight;
|
|
683
|
+
const srcTexFormat = kfr.textureFormat;
|
|
684
|
+
const decisionTree = new _transcodeDecisionTree__WEBPACK_IMPORTED_MODULE_9__.TranscodeDecisionTree(srcTexFormat, kfr.hasAlpha, isPowerOfTwo(width) && isPowerOfTwo(height), caps, options);
|
|
685
|
+
const transcodeFormat = decisionTree.transcodeFormat;
|
|
686
|
+
const engineFormat = decisionTree.engineFormat;
|
|
687
|
+
const roundToMultiple4 = decisionTree.roundToMultiple4;
|
|
688
|
+
const transcoder = this._transcoderMgr.findTranscoder(srcTexFormat, transcodeFormat, kfr.isInGammaSpace, options === null || options === void 0 ? void 0 : options.bypassTranscoders);
|
|
689
|
+
if (transcoder === null) {
|
|
690
|
+
throw new Error(`no transcoder found to transcode source texture format "${_transcoder__WEBPACK_IMPORTED_MODULE_7__.sourceTextureFormat[srcTexFormat]}" to format "${_transcoder__WEBPACK_IMPORTED_MODULE_7__.transcodeTarget[transcodeFormat]}"`);
|
|
691
|
+
}
|
|
692
|
+
const mipmaps = [];
|
|
693
|
+
const dataPromises = [];
|
|
694
|
+
const decodedData = {
|
|
695
|
+
width: 0,
|
|
696
|
+
height: 0,
|
|
697
|
+
transcodedFormat: engineFormat,
|
|
698
|
+
mipmaps,
|
|
699
|
+
isInGammaSpace: kfr.isInGammaSpace,
|
|
700
|
+
hasAlpha: kfr.hasAlpha,
|
|
701
|
+
transcoderName: transcoder.getName(),
|
|
702
|
+
};
|
|
703
|
+
let firstImageDescIndex = 0;
|
|
704
|
+
for (let level = 0; level < kfr.header.levelCount; level++) {
|
|
705
|
+
if (level > 0) {
|
|
706
|
+
firstImageDescIndex += Math.max(kfr.header.layerCount, 1) * kfr.header.faceCount * Math.max(kfr.header.pixelDepth >> (level - 1), 1);
|
|
707
|
+
}
|
|
708
|
+
const levelWidth = Math.floor(width / (1 << level)) || 1;
|
|
709
|
+
const levelHeight = Math.floor(height / (1 << level)) || 1;
|
|
710
|
+
const numImagesInLevel = kfr.header.faceCount; // note that cubemap are not supported yet (see KTX2FileReader), so faceCount == 1
|
|
711
|
+
const levelImageByteLength = ((levelWidth + 3) >> 2) * ((levelHeight + 3) >> 2) * kfr.dfdBlock.bytesPlane[0];
|
|
712
|
+
const levelUncompressedByteLength = kfr.levels[level].uncompressedByteLength;
|
|
713
|
+
let levelDataBuffer = kfr.data.buffer;
|
|
714
|
+
let levelDataOffset = kfr.levels[level].byteOffset + kfr.data.byteOffset;
|
|
715
|
+
let imageOffsetInLevel = 0;
|
|
716
|
+
if (kfr.header.supercompressionScheme === _ktx2FileReader__WEBPACK_IMPORTED_MODULE_0__.SupercompressionScheme.ZStandard) {
|
|
717
|
+
levelDataBuffer = this._zstdDecoder.decode(new Uint8Array(levelDataBuffer, levelDataOffset, kfr.levels[level].byteLength), levelUncompressedByteLength);
|
|
718
|
+
levelDataOffset = 0;
|
|
719
|
+
}
|
|
720
|
+
if (level === 0) {
|
|
721
|
+
decodedData.width = roundToMultiple4 ? (levelWidth + 3) & ~3 : levelWidth;
|
|
722
|
+
decodedData.height = roundToMultiple4 ? (levelHeight + 3) & ~3 : levelHeight;
|
|
723
|
+
}
|
|
724
|
+
for (let imageIndex = 0; imageIndex < numImagesInLevel; imageIndex++) {
|
|
725
|
+
let encodedData;
|
|
726
|
+
let imageDesc = null;
|
|
727
|
+
if (kfr.header.supercompressionScheme === _ktx2FileReader__WEBPACK_IMPORTED_MODULE_0__.SupercompressionScheme.BasisLZ) {
|
|
728
|
+
imageDesc = kfr.supercompressionGlobalData.imageDescs[firstImageDescIndex + imageIndex];
|
|
729
|
+
encodedData = new Uint8Array(levelDataBuffer, levelDataOffset + imageDesc.rgbSliceByteOffset, imageDesc.rgbSliceByteLength + imageDesc.alphaSliceByteLength);
|
|
730
|
+
}
|
|
731
|
+
else {
|
|
732
|
+
encodedData = new Uint8Array(levelDataBuffer, levelDataOffset + imageOffsetInLevel, levelImageByteLength);
|
|
733
|
+
imageOffsetInLevel += levelImageByteLength;
|
|
734
|
+
}
|
|
735
|
+
const mipmap = {
|
|
736
|
+
data: null,
|
|
737
|
+
width: levelWidth,
|
|
738
|
+
height: levelHeight,
|
|
739
|
+
};
|
|
740
|
+
const transcodedData = transcoder
|
|
741
|
+
.transcode(srcTexFormat, transcodeFormat, level, levelWidth, levelHeight, levelUncompressedByteLength, kfr, imageDesc, encodedData)
|
|
742
|
+
.then((data) => {
|
|
743
|
+
mipmap.data = data;
|
|
744
|
+
return data;
|
|
745
|
+
})
|
|
746
|
+
.catch((reason) => {
|
|
747
|
+
var _a;
|
|
748
|
+
decodedData.errors = (_a = decodedData.errors) !== null && _a !== void 0 ? _a : "";
|
|
749
|
+
decodedData.errors += reason + "\n" + reason.stack + "\n";
|
|
750
|
+
return null;
|
|
751
|
+
});
|
|
752
|
+
dataPromises.push(transcodedData);
|
|
753
|
+
mipmaps.push(mipmap);
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
return Promise.all(dataPromises).then(() => {
|
|
757
|
+
return decodedData;
|
|
758
|
+
});
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
// Put in the order you want the transcoders to be used in priority
|
|
762
|
+
_transcoderManager__WEBPACK_IMPORTED_MODULE_1__.TranscoderManager.RegisterTranscoder(_Transcoders_liteTranscoder_UASTC_ASTC__WEBPACK_IMPORTED_MODULE_2__.LiteTranscoder_UASTC_ASTC);
|
|
763
|
+
_transcoderManager__WEBPACK_IMPORTED_MODULE_1__.TranscoderManager.RegisterTranscoder(_Transcoders_liteTranscoder_UASTC_BC7__WEBPACK_IMPORTED_MODULE_3__.LiteTranscoder_UASTC_BC7);
|
|
764
|
+
_transcoderManager__WEBPACK_IMPORTED_MODULE_1__.TranscoderManager.RegisterTranscoder(_Transcoders_liteTranscoder_UASTC_RGBA_UNORM__WEBPACK_IMPORTED_MODULE_4__.LiteTranscoder_UASTC_RGBA_UNORM);
|
|
765
|
+
_transcoderManager__WEBPACK_IMPORTED_MODULE_1__.TranscoderManager.RegisterTranscoder(_Transcoders_liteTranscoder_UASTC_RGBA_SRGB__WEBPACK_IMPORTED_MODULE_5__.LiteTranscoder_UASTC_RGBA_SRGB);
|
|
766
|
+
_transcoderManager__WEBPACK_IMPORTED_MODULE_1__.TranscoderManager.RegisterTranscoder(_Transcoders_mscTranscoder__WEBPACK_IMPORTED_MODULE_6__.MSCTranscoder); // catch all transcoder - will throw an error if the format can't be transcoded
|
|
767
767
|
|
|
768
768
|
|
|
769
769
|
/***/ }),
|
|
@@ -781,224 +781,224 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
781
781
|
/* harmony export */ });
|
|
782
782
|
/* harmony import */ var _Misc_dataReader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./Misc/dataReader */ "../../../tools/ktx2Decoder/dist/Misc/dataReader.js");
|
|
783
783
|
/* harmony import */ var _transcoder__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./transcoder */ "../../../tools/ktx2Decoder/dist/transcoder.js");
|
|
784
|
-
/* eslint-disable @typescript-eslint/naming-convention */
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
/** @hidden */
|
|
788
|
-
var SupercompressionScheme;
|
|
789
|
-
(function (SupercompressionScheme) {
|
|
790
|
-
SupercompressionScheme[SupercompressionScheme["None"] = 0] = "None";
|
|
791
|
-
SupercompressionScheme[SupercompressionScheme["BasisLZ"] = 1] = "BasisLZ";
|
|
792
|
-
SupercompressionScheme[SupercompressionScheme["ZStandard"] = 2] = "ZStandard";
|
|
793
|
-
SupercompressionScheme[SupercompressionScheme["ZLib"] = 3] = "ZLib";
|
|
794
|
-
})(SupercompressionScheme || (SupercompressionScheme = {}));
|
|
795
|
-
class KTX2FileReader {
|
|
796
|
-
/**
|
|
797
|
-
* Will throw an exception if the file can't be parsed
|
|
798
|
-
* @param data
|
|
799
|
-
*/
|
|
800
|
-
constructor(data) {
|
|
801
|
-
this._data = data;
|
|
802
|
-
}
|
|
803
|
-
get data() {
|
|
804
|
-
return this._data;
|
|
805
|
-
}
|
|
806
|
-
get header() {
|
|
807
|
-
return this._header;
|
|
808
|
-
}
|
|
809
|
-
get levels() {
|
|
810
|
-
return this._levels;
|
|
811
|
-
}
|
|
812
|
-
get dfdBlock() {
|
|
813
|
-
return this._dfdBlock;
|
|
814
|
-
}
|
|
815
|
-
get supercompressionGlobalData() {
|
|
816
|
-
return this._supercompressionGlobalData;
|
|
817
|
-
}
|
|
818
|
-
isValid() {
|
|
819
|
-
return KTX2FileReader.IsValid(this._data);
|
|
820
|
-
}
|
|
821
|
-
parse() {
|
|
822
|
-
let offsetInFile = 12; // skip the header
|
|
823
|
-
/**
|
|
824
|
-
* Get the header
|
|
825
|
-
*/
|
|
826
|
-
const hdrReader = new _Misc_dataReader__WEBPACK_IMPORTED_MODULE_0__.DataReader(this._data, offsetInFile, 17 * 4);
|
|
827
|
-
const header = (this._header = {
|
|
828
|
-
vkFormat: hdrReader.readUint32(),
|
|
829
|
-
typeSize: hdrReader.readUint32(),
|
|
830
|
-
pixelWidth: hdrReader.readUint32(),
|
|
831
|
-
pixelHeight: hdrReader.readUint32(),
|
|
832
|
-
pixelDepth: hdrReader.readUint32(),
|
|
833
|
-
layerCount: hdrReader.readUint32(),
|
|
834
|
-
faceCount: hdrReader.readUint32(),
|
|
835
|
-
levelCount: hdrReader.readUint32(),
|
|
836
|
-
supercompressionScheme: hdrReader.readUint32(),
|
|
837
|
-
dfdByteOffset: hdrReader.readUint32(),
|
|
838
|
-
dfdByteLength: hdrReader.readUint32(),
|
|
839
|
-
kvdByteOffset: hdrReader.readUint32(),
|
|
840
|
-
kvdByteLength: hdrReader.readUint32(),
|
|
841
|
-
sgdByteOffset: hdrReader.readUint64(),
|
|
842
|
-
sgdByteLength: hdrReader.readUint64(),
|
|
843
|
-
});
|
|
844
|
-
if (header.pixelDepth > 0) {
|
|
845
|
-
throw new Error(`Failed to parse KTX2 file - Only 2D textures are currently supported.`);
|
|
846
|
-
}
|
|
847
|
-
if (header.layerCount > 1) {
|
|
848
|
-
throw new Error(`Failed to parse KTX2 file - Array textures are not currently supported.`);
|
|
849
|
-
}
|
|
850
|
-
if (header.faceCount > 1) {
|
|
851
|
-
throw new Error(`Failed to parse KTX2 file - Cube textures are not currently supported.`);
|
|
852
|
-
}
|
|
853
|
-
offsetInFile += hdrReader.byteOffset;
|
|
854
|
-
/**
|
|
855
|
-
* Get the levels
|
|
856
|
-
*/
|
|
857
|
-
let levelCount = Math.max(1, header.levelCount);
|
|
858
|
-
const levelReader = new _Misc_dataReader__WEBPACK_IMPORTED_MODULE_0__.DataReader(this._data, offsetInFile, levelCount * 3 * (2 * 4));
|
|
859
|
-
const levels = (this._levels = []);
|
|
860
|
-
while (levelCount--) {
|
|
861
|
-
levels.push({
|
|
862
|
-
byteOffset: levelReader.readUint64(),
|
|
863
|
-
byteLength: levelReader.readUint64(),
|
|
864
|
-
uncompressedByteLength: levelReader.readUint64(),
|
|
865
|
-
});
|
|
866
|
-
}
|
|
867
|
-
offsetInFile += levelReader.byteOffset;
|
|
868
|
-
/**
|
|
869
|
-
* Get the data format descriptor (DFD) blocks
|
|
870
|
-
*/
|
|
871
|
-
const dfdReader = new _Misc_dataReader__WEBPACK_IMPORTED_MODULE_0__.DataReader(this._data, header.dfdByteOffset, header.dfdByteLength);
|
|
872
|
-
const dfdBlock = (this._dfdBlock = {
|
|
873
|
-
vendorId: dfdReader.skipBytes(4 /* skip totalSize */).readUint16(),
|
|
874
|
-
descriptorType: dfdReader.readUint16(),
|
|
875
|
-
versionNumber: dfdReader.readUint16(),
|
|
876
|
-
descriptorBlockSize: dfdReader.readUint16(),
|
|
877
|
-
colorModel: dfdReader.readUint8(),
|
|
878
|
-
colorPrimaries: dfdReader.readUint8(),
|
|
879
|
-
transferFunction: dfdReader.readUint8(),
|
|
880
|
-
flags: dfdReader.readUint8(),
|
|
881
|
-
texelBlockDimension: {
|
|
882
|
-
x: dfdReader.readUint8() + 1,
|
|
883
|
-
y: dfdReader.readUint8() + 1,
|
|
884
|
-
z: dfdReader.readUint8() + 1,
|
|
885
|
-
w: dfdReader.readUint8() + 1,
|
|
886
|
-
},
|
|
887
|
-
bytesPlane: [
|
|
888
|
-
dfdReader.readUint8() /* bytesPlane0 */,
|
|
889
|
-
dfdReader.readUint8() /* bytesPlane1 */,
|
|
890
|
-
dfdReader.readUint8() /* bytesPlane2 */,
|
|
891
|
-
dfdReader.readUint8() /* bytesPlane3 */,
|
|
892
|
-
dfdReader.readUint8() /* bytesPlane4 */,
|
|
893
|
-
dfdReader.readUint8() /* bytesPlane5 */,
|
|
894
|
-
dfdReader.readUint8() /* bytesPlane6 */,
|
|
895
|
-
dfdReader.readUint8() /* bytesPlane7 */,
|
|
896
|
-
],
|
|
897
|
-
numSamples: 0,
|
|
898
|
-
samples: new Array(),
|
|
899
|
-
});
|
|
900
|
-
dfdBlock.numSamples = (dfdBlock.descriptorBlockSize - 24) / 16;
|
|
901
|
-
for (let i = 0; i < dfdBlock.numSamples; i++) {
|
|
902
|
-
const sample = {
|
|
903
|
-
bitOffset: dfdReader.readUint16(),
|
|
904
|
-
bitLength: dfdReader.readUint8() + 1,
|
|
905
|
-
channelType: dfdReader.readUint8(),
|
|
906
|
-
channelFlags: 0,
|
|
907
|
-
samplePosition: [
|
|
908
|
-
dfdReader.readUint8() /* samplePosition0 */,
|
|
909
|
-
dfdReader.readUint8() /* samplePosition1 */,
|
|
910
|
-
dfdReader.readUint8() /* samplePosition2 */,
|
|
911
|
-
dfdReader.readUint8() /* samplePosition3 */,
|
|
912
|
-
],
|
|
913
|
-
sampleLower: dfdReader.readUint32(),
|
|
914
|
-
sampleUpper: dfdReader.readUint32(),
|
|
915
|
-
};
|
|
916
|
-
sample.channelFlags = (sample.channelType & 0xf0) >> 4;
|
|
917
|
-
sample.channelType = sample.channelType & 0x0f;
|
|
918
|
-
dfdBlock.samples.push(sample);
|
|
919
|
-
}
|
|
920
|
-
/**
|
|
921
|
-
* Get the Supercompression Global Data (sgd)
|
|
922
|
-
*/
|
|
923
|
-
const sgd = (this._supercompressionGlobalData = {});
|
|
924
|
-
if (header.sgdByteLength > 0) {
|
|
925
|
-
const sgdReader = new _Misc_dataReader__WEBPACK_IMPORTED_MODULE_0__.DataReader(this._data, header.sgdByteOffset, header.sgdByteLength);
|
|
926
|
-
sgd.endpointCount = sgdReader.readUint16();
|
|
927
|
-
sgd.selectorCount = sgdReader.readUint16();
|
|
928
|
-
sgd.endpointsByteLength = sgdReader.readUint32();
|
|
929
|
-
sgd.selectorsByteLength = sgdReader.readUint32();
|
|
930
|
-
sgd.tablesByteLength = sgdReader.readUint32();
|
|
931
|
-
sgd.extendedByteLength = sgdReader.readUint32();
|
|
932
|
-
sgd.imageDescs = [];
|
|
933
|
-
const imageCount = this._getImageCount();
|
|
934
|
-
for (let i = 0; i < imageCount; i++) {
|
|
935
|
-
sgd.imageDescs.push({
|
|
936
|
-
imageFlags: sgdReader.readUint32(),
|
|
937
|
-
rgbSliceByteOffset: sgdReader.readUint32(),
|
|
938
|
-
rgbSliceByteLength: sgdReader.readUint32(),
|
|
939
|
-
alphaSliceByteOffset: sgdReader.readUint32(),
|
|
940
|
-
alphaSliceByteLength: sgdReader.readUint32(),
|
|
941
|
-
});
|
|
942
|
-
}
|
|
943
|
-
const endpointsByteOffset = header.sgdByteOffset + sgdReader.byteOffset;
|
|
944
|
-
const selectorsByteOffset = endpointsByteOffset + sgd.endpointsByteLength;
|
|
945
|
-
const tablesByteOffset = selectorsByteOffset + sgd.selectorsByteLength;
|
|
946
|
-
const extendedByteOffset = tablesByteOffset + sgd.tablesByteLength;
|
|
947
|
-
sgd.endpointsData = new Uint8Array(this._data.buffer, this._data.byteOffset + endpointsByteOffset, sgd.endpointsByteLength);
|
|
948
|
-
sgd.selectorsData = new Uint8Array(this._data.buffer, this._data.byteOffset + selectorsByteOffset, sgd.selectorsByteLength);
|
|
949
|
-
sgd.tablesData = new Uint8Array(this._data.buffer, this._data.byteOffset + tablesByteOffset, sgd.tablesByteLength);
|
|
950
|
-
sgd.extendedData = new Uint8Array(this._data.buffer, this._data.byteOffset + extendedByteOffset, sgd.extendedByteLength);
|
|
951
|
-
}
|
|
952
|
-
}
|
|
953
|
-
_getImageCount() {
|
|
954
|
-
let layerPixelDepth = Math.max(this._header.pixelDepth, 1);
|
|
955
|
-
for (let i = 1; i < this._header.levelCount; i++) {
|
|
956
|
-
layerPixelDepth += Math.max(this._header.pixelDepth >> i, 1);
|
|
957
|
-
}
|
|
958
|
-
return Math.max(this._header.layerCount, 1) * this._header.faceCount * layerPixelDepth;
|
|
959
|
-
}
|
|
960
|
-
get textureFormat() {
|
|
961
|
-
return this._dfdBlock.colorModel === 166 /* UASTC */ ? _transcoder__WEBPACK_IMPORTED_MODULE_1__.sourceTextureFormat.UASTC4x4 : _transcoder__WEBPACK_IMPORTED_MODULE_1__.sourceTextureFormat.ETC1S;
|
|
962
|
-
}
|
|
963
|
-
get hasAlpha() {
|
|
964
|
-
const tformat = this.textureFormat;
|
|
965
|
-
switch (tformat) {
|
|
966
|
-
case _transcoder__WEBPACK_IMPORTED_MODULE_1__.sourceTextureFormat.ETC1S:
|
|
967
|
-
return (this._dfdBlock.numSamples === 2 &&
|
|
968
|
-
(this._dfdBlock.samples[0].channelType === 15 /* AAA */ || this._dfdBlock.samples[1].channelType === 15 /* AAA */));
|
|
969
|
-
case _transcoder__WEBPACK_IMPORTED_MODULE_1__.sourceTextureFormat.UASTC4x4:
|
|
970
|
-
return this._dfdBlock.samples[0].channelType === 3 /* RGBA */;
|
|
971
|
-
}
|
|
972
|
-
return false;
|
|
973
|
-
}
|
|
974
|
-
get needZSTDDecoder() {
|
|
975
|
-
return this._header.supercompressionScheme === SupercompressionScheme.ZStandard;
|
|
976
|
-
}
|
|
977
|
-
get isInGammaSpace() {
|
|
978
|
-
return this._dfdBlock.transferFunction === 2 /* sRGB */;
|
|
979
|
-
}
|
|
980
|
-
static IsValid(data) {
|
|
981
|
-
if (data.byteLength >= 12) {
|
|
982
|
-
// '«', 'K', 'T', 'X', ' ', '2', '0', '»', '\r', '\n', '\x1A', '\n'
|
|
983
|
-
const identifier = new Uint8Array(data.buffer, data.byteOffset, 12);
|
|
984
|
-
if (identifier[0] === 0xab &&
|
|
985
|
-
identifier[1] === 0x4b &&
|
|
986
|
-
identifier[2] === 0x54 &&
|
|
987
|
-
identifier[3] === 0x58 &&
|
|
988
|
-
identifier[4] === 0x20 &&
|
|
989
|
-
identifier[5] === 0x32 &&
|
|
990
|
-
identifier[6] === 0x30 &&
|
|
991
|
-
identifier[7] === 0xbb &&
|
|
992
|
-
identifier[8] === 0x0d &&
|
|
993
|
-
identifier[9] === 0x0a &&
|
|
994
|
-
identifier[10] === 0x1a &&
|
|
995
|
-
identifier[11] === 0x0a) {
|
|
996
|
-
return true;
|
|
997
|
-
}
|
|
998
|
-
}
|
|
999
|
-
return false;
|
|
1000
|
-
}
|
|
1001
|
-
}
|
|
784
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
|
785
|
+
|
|
786
|
+
|
|
787
|
+
/** @hidden */
|
|
788
|
+
var SupercompressionScheme;
|
|
789
|
+
(function (SupercompressionScheme) {
|
|
790
|
+
SupercompressionScheme[SupercompressionScheme["None"] = 0] = "None";
|
|
791
|
+
SupercompressionScheme[SupercompressionScheme["BasisLZ"] = 1] = "BasisLZ";
|
|
792
|
+
SupercompressionScheme[SupercompressionScheme["ZStandard"] = 2] = "ZStandard";
|
|
793
|
+
SupercompressionScheme[SupercompressionScheme["ZLib"] = 3] = "ZLib";
|
|
794
|
+
})(SupercompressionScheme || (SupercompressionScheme = {}));
|
|
795
|
+
class KTX2FileReader {
|
|
796
|
+
/**
|
|
797
|
+
* Will throw an exception if the file can't be parsed
|
|
798
|
+
* @param data
|
|
799
|
+
*/
|
|
800
|
+
constructor(data) {
|
|
801
|
+
this._data = data;
|
|
802
|
+
}
|
|
803
|
+
get data() {
|
|
804
|
+
return this._data;
|
|
805
|
+
}
|
|
806
|
+
get header() {
|
|
807
|
+
return this._header;
|
|
808
|
+
}
|
|
809
|
+
get levels() {
|
|
810
|
+
return this._levels;
|
|
811
|
+
}
|
|
812
|
+
get dfdBlock() {
|
|
813
|
+
return this._dfdBlock;
|
|
814
|
+
}
|
|
815
|
+
get supercompressionGlobalData() {
|
|
816
|
+
return this._supercompressionGlobalData;
|
|
817
|
+
}
|
|
818
|
+
isValid() {
|
|
819
|
+
return KTX2FileReader.IsValid(this._data);
|
|
820
|
+
}
|
|
821
|
+
parse() {
|
|
822
|
+
let offsetInFile = 12; // skip the header
|
|
823
|
+
/**
|
|
824
|
+
* Get the header
|
|
825
|
+
*/
|
|
826
|
+
const hdrReader = new _Misc_dataReader__WEBPACK_IMPORTED_MODULE_0__.DataReader(this._data, offsetInFile, 17 * 4);
|
|
827
|
+
const header = (this._header = {
|
|
828
|
+
vkFormat: hdrReader.readUint32(),
|
|
829
|
+
typeSize: hdrReader.readUint32(),
|
|
830
|
+
pixelWidth: hdrReader.readUint32(),
|
|
831
|
+
pixelHeight: hdrReader.readUint32(),
|
|
832
|
+
pixelDepth: hdrReader.readUint32(),
|
|
833
|
+
layerCount: hdrReader.readUint32(),
|
|
834
|
+
faceCount: hdrReader.readUint32(),
|
|
835
|
+
levelCount: hdrReader.readUint32(),
|
|
836
|
+
supercompressionScheme: hdrReader.readUint32(),
|
|
837
|
+
dfdByteOffset: hdrReader.readUint32(),
|
|
838
|
+
dfdByteLength: hdrReader.readUint32(),
|
|
839
|
+
kvdByteOffset: hdrReader.readUint32(),
|
|
840
|
+
kvdByteLength: hdrReader.readUint32(),
|
|
841
|
+
sgdByteOffset: hdrReader.readUint64(),
|
|
842
|
+
sgdByteLength: hdrReader.readUint64(),
|
|
843
|
+
});
|
|
844
|
+
if (header.pixelDepth > 0) {
|
|
845
|
+
throw new Error(`Failed to parse KTX2 file - Only 2D textures are currently supported.`);
|
|
846
|
+
}
|
|
847
|
+
if (header.layerCount > 1) {
|
|
848
|
+
throw new Error(`Failed to parse KTX2 file - Array textures are not currently supported.`);
|
|
849
|
+
}
|
|
850
|
+
if (header.faceCount > 1) {
|
|
851
|
+
throw new Error(`Failed to parse KTX2 file - Cube textures are not currently supported.`);
|
|
852
|
+
}
|
|
853
|
+
offsetInFile += hdrReader.byteOffset;
|
|
854
|
+
/**
|
|
855
|
+
* Get the levels
|
|
856
|
+
*/
|
|
857
|
+
let levelCount = Math.max(1, header.levelCount);
|
|
858
|
+
const levelReader = new _Misc_dataReader__WEBPACK_IMPORTED_MODULE_0__.DataReader(this._data, offsetInFile, levelCount * 3 * (2 * 4));
|
|
859
|
+
const levels = (this._levels = []);
|
|
860
|
+
while (levelCount--) {
|
|
861
|
+
levels.push({
|
|
862
|
+
byteOffset: levelReader.readUint64(),
|
|
863
|
+
byteLength: levelReader.readUint64(),
|
|
864
|
+
uncompressedByteLength: levelReader.readUint64(),
|
|
865
|
+
});
|
|
866
|
+
}
|
|
867
|
+
offsetInFile += levelReader.byteOffset;
|
|
868
|
+
/**
|
|
869
|
+
* Get the data format descriptor (DFD) blocks
|
|
870
|
+
*/
|
|
871
|
+
const dfdReader = new _Misc_dataReader__WEBPACK_IMPORTED_MODULE_0__.DataReader(this._data, header.dfdByteOffset, header.dfdByteLength);
|
|
872
|
+
const dfdBlock = (this._dfdBlock = {
|
|
873
|
+
vendorId: dfdReader.skipBytes(4 /* skip totalSize */).readUint16(),
|
|
874
|
+
descriptorType: dfdReader.readUint16(),
|
|
875
|
+
versionNumber: dfdReader.readUint16(),
|
|
876
|
+
descriptorBlockSize: dfdReader.readUint16(),
|
|
877
|
+
colorModel: dfdReader.readUint8(),
|
|
878
|
+
colorPrimaries: dfdReader.readUint8(),
|
|
879
|
+
transferFunction: dfdReader.readUint8(),
|
|
880
|
+
flags: dfdReader.readUint8(),
|
|
881
|
+
texelBlockDimension: {
|
|
882
|
+
x: dfdReader.readUint8() + 1,
|
|
883
|
+
y: dfdReader.readUint8() + 1,
|
|
884
|
+
z: dfdReader.readUint8() + 1,
|
|
885
|
+
w: dfdReader.readUint8() + 1,
|
|
886
|
+
},
|
|
887
|
+
bytesPlane: [
|
|
888
|
+
dfdReader.readUint8() /* bytesPlane0 */,
|
|
889
|
+
dfdReader.readUint8() /* bytesPlane1 */,
|
|
890
|
+
dfdReader.readUint8() /* bytesPlane2 */,
|
|
891
|
+
dfdReader.readUint8() /* bytesPlane3 */,
|
|
892
|
+
dfdReader.readUint8() /* bytesPlane4 */,
|
|
893
|
+
dfdReader.readUint8() /* bytesPlane5 */,
|
|
894
|
+
dfdReader.readUint8() /* bytesPlane6 */,
|
|
895
|
+
dfdReader.readUint8() /* bytesPlane7 */,
|
|
896
|
+
],
|
|
897
|
+
numSamples: 0,
|
|
898
|
+
samples: new Array(),
|
|
899
|
+
});
|
|
900
|
+
dfdBlock.numSamples = (dfdBlock.descriptorBlockSize - 24) / 16;
|
|
901
|
+
for (let i = 0; i < dfdBlock.numSamples; i++) {
|
|
902
|
+
const sample = {
|
|
903
|
+
bitOffset: dfdReader.readUint16(),
|
|
904
|
+
bitLength: dfdReader.readUint8() + 1,
|
|
905
|
+
channelType: dfdReader.readUint8(),
|
|
906
|
+
channelFlags: 0,
|
|
907
|
+
samplePosition: [
|
|
908
|
+
dfdReader.readUint8() /* samplePosition0 */,
|
|
909
|
+
dfdReader.readUint8() /* samplePosition1 */,
|
|
910
|
+
dfdReader.readUint8() /* samplePosition2 */,
|
|
911
|
+
dfdReader.readUint8() /* samplePosition3 */,
|
|
912
|
+
],
|
|
913
|
+
sampleLower: dfdReader.readUint32(),
|
|
914
|
+
sampleUpper: dfdReader.readUint32(),
|
|
915
|
+
};
|
|
916
|
+
sample.channelFlags = (sample.channelType & 0xf0) >> 4;
|
|
917
|
+
sample.channelType = sample.channelType & 0x0f;
|
|
918
|
+
dfdBlock.samples.push(sample);
|
|
919
|
+
}
|
|
920
|
+
/**
|
|
921
|
+
* Get the Supercompression Global Data (sgd)
|
|
922
|
+
*/
|
|
923
|
+
const sgd = (this._supercompressionGlobalData = {});
|
|
924
|
+
if (header.sgdByteLength > 0) {
|
|
925
|
+
const sgdReader = new _Misc_dataReader__WEBPACK_IMPORTED_MODULE_0__.DataReader(this._data, header.sgdByteOffset, header.sgdByteLength);
|
|
926
|
+
sgd.endpointCount = sgdReader.readUint16();
|
|
927
|
+
sgd.selectorCount = sgdReader.readUint16();
|
|
928
|
+
sgd.endpointsByteLength = sgdReader.readUint32();
|
|
929
|
+
sgd.selectorsByteLength = sgdReader.readUint32();
|
|
930
|
+
sgd.tablesByteLength = sgdReader.readUint32();
|
|
931
|
+
sgd.extendedByteLength = sgdReader.readUint32();
|
|
932
|
+
sgd.imageDescs = [];
|
|
933
|
+
const imageCount = this._getImageCount();
|
|
934
|
+
for (let i = 0; i < imageCount; i++) {
|
|
935
|
+
sgd.imageDescs.push({
|
|
936
|
+
imageFlags: sgdReader.readUint32(),
|
|
937
|
+
rgbSliceByteOffset: sgdReader.readUint32(),
|
|
938
|
+
rgbSliceByteLength: sgdReader.readUint32(),
|
|
939
|
+
alphaSliceByteOffset: sgdReader.readUint32(),
|
|
940
|
+
alphaSliceByteLength: sgdReader.readUint32(),
|
|
941
|
+
});
|
|
942
|
+
}
|
|
943
|
+
const endpointsByteOffset = header.sgdByteOffset + sgdReader.byteOffset;
|
|
944
|
+
const selectorsByteOffset = endpointsByteOffset + sgd.endpointsByteLength;
|
|
945
|
+
const tablesByteOffset = selectorsByteOffset + sgd.selectorsByteLength;
|
|
946
|
+
const extendedByteOffset = tablesByteOffset + sgd.tablesByteLength;
|
|
947
|
+
sgd.endpointsData = new Uint8Array(this._data.buffer, this._data.byteOffset + endpointsByteOffset, sgd.endpointsByteLength);
|
|
948
|
+
sgd.selectorsData = new Uint8Array(this._data.buffer, this._data.byteOffset + selectorsByteOffset, sgd.selectorsByteLength);
|
|
949
|
+
sgd.tablesData = new Uint8Array(this._data.buffer, this._data.byteOffset + tablesByteOffset, sgd.tablesByteLength);
|
|
950
|
+
sgd.extendedData = new Uint8Array(this._data.buffer, this._data.byteOffset + extendedByteOffset, sgd.extendedByteLength);
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
_getImageCount() {
|
|
954
|
+
let layerPixelDepth = Math.max(this._header.pixelDepth, 1);
|
|
955
|
+
for (let i = 1; i < this._header.levelCount; i++) {
|
|
956
|
+
layerPixelDepth += Math.max(this._header.pixelDepth >> i, 1);
|
|
957
|
+
}
|
|
958
|
+
return Math.max(this._header.layerCount, 1) * this._header.faceCount * layerPixelDepth;
|
|
959
|
+
}
|
|
960
|
+
get textureFormat() {
|
|
961
|
+
return this._dfdBlock.colorModel === 166 /* UASTC */ ? _transcoder__WEBPACK_IMPORTED_MODULE_1__.sourceTextureFormat.UASTC4x4 : _transcoder__WEBPACK_IMPORTED_MODULE_1__.sourceTextureFormat.ETC1S;
|
|
962
|
+
}
|
|
963
|
+
get hasAlpha() {
|
|
964
|
+
const tformat = this.textureFormat;
|
|
965
|
+
switch (tformat) {
|
|
966
|
+
case _transcoder__WEBPACK_IMPORTED_MODULE_1__.sourceTextureFormat.ETC1S:
|
|
967
|
+
return (this._dfdBlock.numSamples === 2 &&
|
|
968
|
+
(this._dfdBlock.samples[0].channelType === 15 /* AAA */ || this._dfdBlock.samples[1].channelType === 15 /* AAA */));
|
|
969
|
+
case _transcoder__WEBPACK_IMPORTED_MODULE_1__.sourceTextureFormat.UASTC4x4:
|
|
970
|
+
return this._dfdBlock.samples[0].channelType === 3 /* RGBA */;
|
|
971
|
+
}
|
|
972
|
+
return false;
|
|
973
|
+
}
|
|
974
|
+
get needZSTDDecoder() {
|
|
975
|
+
return this._header.supercompressionScheme === SupercompressionScheme.ZStandard;
|
|
976
|
+
}
|
|
977
|
+
get isInGammaSpace() {
|
|
978
|
+
return this._dfdBlock.transferFunction === 2 /* sRGB */;
|
|
979
|
+
}
|
|
980
|
+
static IsValid(data) {
|
|
981
|
+
if (data.byteLength >= 12) {
|
|
982
|
+
// '«', 'K', 'T', 'X', ' ', '2', '0', '»', '\r', '\n', '\x1A', '\n'
|
|
983
|
+
const identifier = new Uint8Array(data.buffer, data.byteOffset, 12);
|
|
984
|
+
if (identifier[0] === 0xab &&
|
|
985
|
+
identifier[1] === 0x4b &&
|
|
986
|
+
identifier[2] === 0x54 &&
|
|
987
|
+
identifier[3] === 0x58 &&
|
|
988
|
+
identifier[4] === 0x20 &&
|
|
989
|
+
identifier[5] === 0x32 &&
|
|
990
|
+
identifier[6] === 0x30 &&
|
|
991
|
+
identifier[7] === 0xbb &&
|
|
992
|
+
identifier[8] === 0x0d &&
|
|
993
|
+
identifier[9] === 0x0a &&
|
|
994
|
+
identifier[10] === 0x1a &&
|
|
995
|
+
identifier[11] === 0x0a) {
|
|
996
|
+
return true;
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
return false;
|
|
1000
|
+
}
|
|
1001
|
+
}
|
|
1002
1002
|
|
|
1003
1003
|
|
|
1004
1004
|
/***/ }),
|
|
@@ -1029,12 +1029,12 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
1029
1029
|
/* harmony export */ "transcodeTarget": () => (/* reexport safe */ _index__WEBPACK_IMPORTED_MODULE_0__.transcodeTarget)
|
|
1030
1030
|
/* harmony export */ });
|
|
1031
1031
|
/* harmony import */ var _index__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../index */ "../../../tools/ktx2Decoder/dist/index.js");
|
|
1032
|
-
|
|
1033
|
-
const globalObject = typeof __webpack_require__.g !== "undefined" ? __webpack_require__.g : typeof window !== "undefined" ? window : undefined;
|
|
1034
|
-
if (typeof globalObject !== "undefined") {
|
|
1035
|
-
globalObject.KTX2DECODER = _index__WEBPACK_IMPORTED_MODULE_0__.KTX2Decoder;
|
|
1036
|
-
}
|
|
1037
|
-
|
|
1032
|
+
|
|
1033
|
+
const globalObject = typeof __webpack_require__.g !== "undefined" ? __webpack_require__.g : typeof window !== "undefined" ? window : undefined;
|
|
1034
|
+
if (typeof globalObject !== "undefined") {
|
|
1035
|
+
globalObject.KTX2DECODER = _index__WEBPACK_IMPORTED_MODULE_0__.KTX2Decoder;
|
|
1036
|
+
}
|
|
1037
|
+
|
|
1038
1038
|
|
|
1039
1039
|
|
|
1040
1040
|
/***/ }),
|
|
@@ -1050,221 +1050,221 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
1050
1050
|
/* harmony export */ "TranscodeDecisionTree": () => (/* binding */ TranscodeDecisionTree)
|
|
1051
1051
|
/* harmony export */ });
|
|
1052
1052
|
/* harmony import */ var _transcoder__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./transcoder */ "../../../tools/ktx2Decoder/dist/transcoder.js");
|
|
1053
|
-
/* eslint-disable @typescript-eslint/naming-convention */
|
|
1054
|
-
|
|
1055
|
-
const COMPRESSED_RGBA_BPTC_UNORM_EXT = 0x8e8c;
|
|
1056
|
-
const COMPRESSED_RGBA_ASTC_4x4_KHR = 0x93b0;
|
|
1057
|
-
const COMPRESSED_RGB_S3TC_DXT1_EXT = 0x83f0;
|
|
1058
|
-
const COMPRESSED_RGBA_S3TC_DXT5_EXT = 0x83f3;
|
|
1059
|
-
const COMPRESSED_RGBA_PVRTC_4BPPV1_IMG = 0x8c02;
|
|
1060
|
-
const COMPRESSED_RGB_PVRTC_4BPPV1_IMG = 0x8c00;
|
|
1061
|
-
const COMPRESSED_RGBA8_ETC2_EAC = 0x9278;
|
|
1062
|
-
const COMPRESSED_RGB8_ETC2 = 0x9274;
|
|
1063
|
-
const COMPRESSED_RGB_ETC1_WEBGL = 0x8d64;
|
|
1064
|
-
const RGBA8Format = 0x8058;
|
|
1065
|
-
const DecisionTree = {
|
|
1066
|
-
ETC1S: {
|
|
1067
|
-
option: "forceRGBA",
|
|
1068
|
-
yes: {
|
|
1069
|
-
transcodeFormat: _transcoder__WEBPACK_IMPORTED_MODULE_0__.transcodeTarget.RGBA32,
|
|
1070
|
-
engineFormat: RGBA8Format,
|
|
1071
|
-
roundToMultiple4: false,
|
|
1072
|
-
},
|
|
1073
|
-
no: {
|
|
1074
|
-
cap: "etc2",
|
|
1075
|
-
yes: {
|
|
1076
|
-
alpha: true,
|
|
1077
|
-
yes: {
|
|
1078
|
-
transcodeFormat: _transcoder__WEBPACK_IMPORTED_MODULE_0__.transcodeTarget.ETC2_RGBA,
|
|
1079
|
-
engineFormat: COMPRESSED_RGBA8_ETC2_EAC,
|
|
1080
|
-
},
|
|
1081
|
-
no: {
|
|
1082
|
-
transcodeFormat: _transcoder__WEBPACK_IMPORTED_MODULE_0__.transcodeTarget.ETC1_RGB,
|
|
1083
|
-
engineFormat: COMPRESSED_RGB8_ETC2,
|
|
1084
|
-
},
|
|
1085
|
-
},
|
|
1086
|
-
no: {
|
|
1087
|
-
cap: "etc1",
|
|
1088
|
-
alpha: false,
|
|
1089
|
-
yes: {
|
|
1090
|
-
transcodeFormat: _transcoder__WEBPACK_IMPORTED_MODULE_0__.transcodeTarget.ETC1_RGB,
|
|
1091
|
-
engineFormat: COMPRESSED_RGB_ETC1_WEBGL,
|
|
1092
|
-
},
|
|
1093
|
-
no: {
|
|
1094
|
-
cap: "bptc",
|
|
1095
|
-
yes: {
|
|
1096
|
-
transcodeFormat: _transcoder__WEBPACK_IMPORTED_MODULE_0__.transcodeTarget.BC7_RGBA,
|
|
1097
|
-
engineFormat: COMPRESSED_RGBA_BPTC_UNORM_EXT,
|
|
1098
|
-
},
|
|
1099
|
-
no: {
|
|
1100
|
-
cap: "s3tc",
|
|
1101
|
-
yes: {
|
|
1102
|
-
alpha: true,
|
|
1103
|
-
yes: {
|
|
1104
|
-
transcodeFormat: _transcoder__WEBPACK_IMPORTED_MODULE_0__.transcodeTarget.BC3_RGBA,
|
|
1105
|
-
engineFormat: COMPRESSED_RGBA_S3TC_DXT5_EXT,
|
|
1106
|
-
},
|
|
1107
|
-
no: {
|
|
1108
|
-
transcodeFormat: _transcoder__WEBPACK_IMPORTED_MODULE_0__.transcodeTarget.BC1_RGB,
|
|
1109
|
-
engineFormat: COMPRESSED_RGB_S3TC_DXT1_EXT,
|
|
1110
|
-
},
|
|
1111
|
-
},
|
|
1112
|
-
no: {
|
|
1113
|
-
cap: "pvrtc",
|
|
1114
|
-
needsPowerOfTwo: true,
|
|
1115
|
-
yes: {
|
|
1116
|
-
alpha: true,
|
|
1117
|
-
yes: {
|
|
1118
|
-
transcodeFormat: _transcoder__WEBPACK_IMPORTED_MODULE_0__.transcodeTarget.PVRTC1_4_RGBA,
|
|
1119
|
-
engineFormat: COMPRESSED_RGBA_PVRTC_4BPPV1_IMG,
|
|
1120
|
-
},
|
|
1121
|
-
no: {
|
|
1122
|
-
transcodeFormat: _transcoder__WEBPACK_IMPORTED_MODULE_0__.transcodeTarget.PVRTC1_4_RGB,
|
|
1123
|
-
engineFormat: COMPRESSED_RGB_PVRTC_4BPPV1_IMG,
|
|
1124
|
-
},
|
|
1125
|
-
},
|
|
1126
|
-
no: {
|
|
1127
|
-
transcodeFormat: _transcoder__WEBPACK_IMPORTED_MODULE_0__.transcodeTarget.RGBA32,
|
|
1128
|
-
engineFormat: RGBA8Format,
|
|
1129
|
-
roundToMultiple4: false,
|
|
1130
|
-
},
|
|
1131
|
-
},
|
|
1132
|
-
},
|
|
1133
|
-
},
|
|
1134
|
-
},
|
|
1135
|
-
},
|
|
1136
|
-
},
|
|
1137
|
-
UASTC: {
|
|
1138
|
-
option: "forceRGBA",
|
|
1139
|
-
yes: {
|
|
1140
|
-
transcodeFormat: _transcoder__WEBPACK_IMPORTED_MODULE_0__.transcodeTarget.RGBA32,
|
|
1141
|
-
engineFormat: RGBA8Format,
|
|
1142
|
-
roundToMultiple4: false,
|
|
1143
|
-
},
|
|
1144
|
-
no: {
|
|
1145
|
-
cap: "astc",
|
|
1146
|
-
yes: {
|
|
1147
|
-
transcodeFormat: _transcoder__WEBPACK_IMPORTED_MODULE_0__.transcodeTarget.ASTC_4x4_RGBA,
|
|
1148
|
-
engineFormat: COMPRESSED_RGBA_ASTC_4x4_KHR,
|
|
1149
|
-
},
|
|
1150
|
-
no: {
|
|
1151
|
-
cap: "bptc",
|
|
1152
|
-
yes: {
|
|
1153
|
-
transcodeFormat: _transcoder__WEBPACK_IMPORTED_MODULE_0__.transcodeTarget.BC7_RGBA,
|
|
1154
|
-
engineFormat: COMPRESSED_RGBA_BPTC_UNORM_EXT,
|
|
1155
|
-
},
|
|
1156
|
-
no: {
|
|
1157
|
-
option: "useRGBAIfASTCBC7NotAvailableWhenUASTC",
|
|
1158
|
-
yes: {
|
|
1159
|
-
transcodeFormat: _transcoder__WEBPACK_IMPORTED_MODULE_0__.transcodeTarget.RGBA32,
|
|
1160
|
-
engineFormat: RGBA8Format,
|
|
1161
|
-
roundToMultiple4: false,
|
|
1162
|
-
},
|
|
1163
|
-
no: {
|
|
1164
|
-
cap: "etc2",
|
|
1165
|
-
yes: {
|
|
1166
|
-
alpha: true,
|
|
1167
|
-
yes: {
|
|
1168
|
-
transcodeFormat: _transcoder__WEBPACK_IMPORTED_MODULE_0__.transcodeTarget.ETC2_RGBA,
|
|
1169
|
-
engineFormat: COMPRESSED_RGBA8_ETC2_EAC,
|
|
1170
|
-
},
|
|
1171
|
-
no: {
|
|
1172
|
-
transcodeFormat: _transcoder__WEBPACK_IMPORTED_MODULE_0__.transcodeTarget.ETC1_RGB,
|
|
1173
|
-
engineFormat: COMPRESSED_RGB8_ETC2,
|
|
1174
|
-
},
|
|
1175
|
-
},
|
|
1176
|
-
no: {
|
|
1177
|
-
cap: "etc1",
|
|
1178
|
-
yes: {
|
|
1179
|
-
transcodeFormat: _transcoder__WEBPACK_IMPORTED_MODULE_0__.transcodeTarget.ETC1_RGB,
|
|
1180
|
-
engineFormat: COMPRESSED_RGB_ETC1_WEBGL,
|
|
1181
|
-
},
|
|
1182
|
-
no: {
|
|
1183
|
-
cap: "s3tc",
|
|
1184
|
-
yes: {
|
|
1185
|
-
alpha: true,
|
|
1186
|
-
yes: {
|
|
1187
|
-
transcodeFormat: _transcoder__WEBPACK_IMPORTED_MODULE_0__.transcodeTarget.BC3_RGBA,
|
|
1188
|
-
engineFormat: COMPRESSED_RGBA_S3TC_DXT5_EXT,
|
|
1189
|
-
},
|
|
1190
|
-
no: {
|
|
1191
|
-
transcodeFormat: _transcoder__WEBPACK_IMPORTED_MODULE_0__.transcodeTarget.BC1_RGB,
|
|
1192
|
-
engineFormat: COMPRESSED_RGB_S3TC_DXT1_EXT,
|
|
1193
|
-
},
|
|
1194
|
-
},
|
|
1195
|
-
no: {
|
|
1196
|
-
cap: "pvrtc",
|
|
1197
|
-
needsPowerOfTwo: true,
|
|
1198
|
-
yes: {
|
|
1199
|
-
alpha: true,
|
|
1200
|
-
yes: {
|
|
1201
|
-
transcodeFormat: _transcoder__WEBPACK_IMPORTED_MODULE_0__.transcodeTarget.PVRTC1_4_RGBA,
|
|
1202
|
-
engineFormat: COMPRESSED_RGBA_PVRTC_4BPPV1_IMG,
|
|
1203
|
-
},
|
|
1204
|
-
no: {
|
|
1205
|
-
transcodeFormat: _transcoder__WEBPACK_IMPORTED_MODULE_0__.transcodeTarget.PVRTC1_4_RGB,
|
|
1206
|
-
engineFormat: COMPRESSED_RGB_PVRTC_4BPPV1_IMG,
|
|
1207
|
-
},
|
|
1208
|
-
},
|
|
1209
|
-
no: {
|
|
1210
|
-
transcodeFormat: _transcoder__WEBPACK_IMPORTED_MODULE_0__.transcodeTarget.RGBA32,
|
|
1211
|
-
engineFormat: RGBA8Format,
|
|
1212
|
-
roundToMultiple4: false,
|
|
1213
|
-
},
|
|
1214
|
-
},
|
|
1215
|
-
},
|
|
1216
|
-
},
|
|
1217
|
-
},
|
|
1218
|
-
},
|
|
1219
|
-
},
|
|
1220
|
-
},
|
|
1221
|
-
},
|
|
1222
|
-
};
|
|
1223
|
-
class TranscodeDecisionTree {
|
|
1224
|
-
constructor(textureFormat, hasAlpha, isPowerOfTwo, caps, options) {
|
|
1225
|
-
this._hasAlpha = hasAlpha;
|
|
1226
|
-
this._isPowerOfTwo = isPowerOfTwo;
|
|
1227
|
-
this._caps = caps;
|
|
1228
|
-
this._options = options !== null && options !== void 0 ? options : {};
|
|
1229
|
-
this._parseNode(textureFormat === _transcoder__WEBPACK_IMPORTED_MODULE_0__.sourceTextureFormat.UASTC4x4 ? DecisionTree.UASTC : DecisionTree.ETC1S);
|
|
1230
|
-
}
|
|
1231
|
-
static _IsLeafNode(node) {
|
|
1232
|
-
return node.transcodeFormat !== undefined;
|
|
1233
|
-
}
|
|
1234
|
-
get transcodeFormat() {
|
|
1235
|
-
return this._transcodeFormat;
|
|
1236
|
-
}
|
|
1237
|
-
get engineFormat() {
|
|
1238
|
-
return this._engineFormat;
|
|
1239
|
-
}
|
|
1240
|
-
get roundToMultiple4() {
|
|
1241
|
-
return this._roundToMultiple4;
|
|
1242
|
-
}
|
|
1243
|
-
_parseNode(node) {
|
|
1244
|
-
var _a;
|
|
1245
|
-
if (TranscodeDecisionTree._IsLeafNode(node)) {
|
|
1246
|
-
this._transcodeFormat = node.transcodeFormat;
|
|
1247
|
-
this._engineFormat = node.engineFormat;
|
|
1248
|
-
this._roundToMultiple4 = (_a = node.roundToMultiple4) !== null && _a !== void 0 ? _a : true;
|
|
1249
|
-
}
|
|
1250
|
-
else {
|
|
1251
|
-
let condition = true;
|
|
1252
|
-
if (node.cap !== undefined) {
|
|
1253
|
-
condition = condition && this._caps[node.cap];
|
|
1254
|
-
}
|
|
1255
|
-
if (node.option !== undefined) {
|
|
1256
|
-
condition = condition && this._options[node.option];
|
|
1257
|
-
}
|
|
1258
|
-
if (node.alpha !== undefined) {
|
|
1259
|
-
condition = condition && this._hasAlpha === node.alpha;
|
|
1260
|
-
}
|
|
1261
|
-
if (node.needsPowerOfTwo !== undefined) {
|
|
1262
|
-
condition = condition && this._isPowerOfTwo === node.needsPowerOfTwo;
|
|
1263
|
-
}
|
|
1264
|
-
this._parseNode(condition ? node.yes : node.no);
|
|
1265
|
-
}
|
|
1266
|
-
}
|
|
1267
|
-
}
|
|
1053
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
|
1054
|
+
|
|
1055
|
+
const COMPRESSED_RGBA_BPTC_UNORM_EXT = 0x8e8c;
|
|
1056
|
+
const COMPRESSED_RGBA_ASTC_4x4_KHR = 0x93b0;
|
|
1057
|
+
const COMPRESSED_RGB_S3TC_DXT1_EXT = 0x83f0;
|
|
1058
|
+
const COMPRESSED_RGBA_S3TC_DXT5_EXT = 0x83f3;
|
|
1059
|
+
const COMPRESSED_RGBA_PVRTC_4BPPV1_IMG = 0x8c02;
|
|
1060
|
+
const COMPRESSED_RGB_PVRTC_4BPPV1_IMG = 0x8c00;
|
|
1061
|
+
const COMPRESSED_RGBA8_ETC2_EAC = 0x9278;
|
|
1062
|
+
const COMPRESSED_RGB8_ETC2 = 0x9274;
|
|
1063
|
+
const COMPRESSED_RGB_ETC1_WEBGL = 0x8d64;
|
|
1064
|
+
const RGBA8Format = 0x8058;
|
|
1065
|
+
const DecisionTree = {
|
|
1066
|
+
ETC1S: {
|
|
1067
|
+
option: "forceRGBA",
|
|
1068
|
+
yes: {
|
|
1069
|
+
transcodeFormat: _transcoder__WEBPACK_IMPORTED_MODULE_0__.transcodeTarget.RGBA32,
|
|
1070
|
+
engineFormat: RGBA8Format,
|
|
1071
|
+
roundToMultiple4: false,
|
|
1072
|
+
},
|
|
1073
|
+
no: {
|
|
1074
|
+
cap: "etc2",
|
|
1075
|
+
yes: {
|
|
1076
|
+
alpha: true,
|
|
1077
|
+
yes: {
|
|
1078
|
+
transcodeFormat: _transcoder__WEBPACK_IMPORTED_MODULE_0__.transcodeTarget.ETC2_RGBA,
|
|
1079
|
+
engineFormat: COMPRESSED_RGBA8_ETC2_EAC,
|
|
1080
|
+
},
|
|
1081
|
+
no: {
|
|
1082
|
+
transcodeFormat: _transcoder__WEBPACK_IMPORTED_MODULE_0__.transcodeTarget.ETC1_RGB,
|
|
1083
|
+
engineFormat: COMPRESSED_RGB8_ETC2,
|
|
1084
|
+
},
|
|
1085
|
+
},
|
|
1086
|
+
no: {
|
|
1087
|
+
cap: "etc1",
|
|
1088
|
+
alpha: false,
|
|
1089
|
+
yes: {
|
|
1090
|
+
transcodeFormat: _transcoder__WEBPACK_IMPORTED_MODULE_0__.transcodeTarget.ETC1_RGB,
|
|
1091
|
+
engineFormat: COMPRESSED_RGB_ETC1_WEBGL,
|
|
1092
|
+
},
|
|
1093
|
+
no: {
|
|
1094
|
+
cap: "bptc",
|
|
1095
|
+
yes: {
|
|
1096
|
+
transcodeFormat: _transcoder__WEBPACK_IMPORTED_MODULE_0__.transcodeTarget.BC7_RGBA,
|
|
1097
|
+
engineFormat: COMPRESSED_RGBA_BPTC_UNORM_EXT,
|
|
1098
|
+
},
|
|
1099
|
+
no: {
|
|
1100
|
+
cap: "s3tc",
|
|
1101
|
+
yes: {
|
|
1102
|
+
alpha: true,
|
|
1103
|
+
yes: {
|
|
1104
|
+
transcodeFormat: _transcoder__WEBPACK_IMPORTED_MODULE_0__.transcodeTarget.BC3_RGBA,
|
|
1105
|
+
engineFormat: COMPRESSED_RGBA_S3TC_DXT5_EXT,
|
|
1106
|
+
},
|
|
1107
|
+
no: {
|
|
1108
|
+
transcodeFormat: _transcoder__WEBPACK_IMPORTED_MODULE_0__.transcodeTarget.BC1_RGB,
|
|
1109
|
+
engineFormat: COMPRESSED_RGB_S3TC_DXT1_EXT,
|
|
1110
|
+
},
|
|
1111
|
+
},
|
|
1112
|
+
no: {
|
|
1113
|
+
cap: "pvrtc",
|
|
1114
|
+
needsPowerOfTwo: true,
|
|
1115
|
+
yes: {
|
|
1116
|
+
alpha: true,
|
|
1117
|
+
yes: {
|
|
1118
|
+
transcodeFormat: _transcoder__WEBPACK_IMPORTED_MODULE_0__.transcodeTarget.PVRTC1_4_RGBA,
|
|
1119
|
+
engineFormat: COMPRESSED_RGBA_PVRTC_4BPPV1_IMG,
|
|
1120
|
+
},
|
|
1121
|
+
no: {
|
|
1122
|
+
transcodeFormat: _transcoder__WEBPACK_IMPORTED_MODULE_0__.transcodeTarget.PVRTC1_4_RGB,
|
|
1123
|
+
engineFormat: COMPRESSED_RGB_PVRTC_4BPPV1_IMG,
|
|
1124
|
+
},
|
|
1125
|
+
},
|
|
1126
|
+
no: {
|
|
1127
|
+
transcodeFormat: _transcoder__WEBPACK_IMPORTED_MODULE_0__.transcodeTarget.RGBA32,
|
|
1128
|
+
engineFormat: RGBA8Format,
|
|
1129
|
+
roundToMultiple4: false,
|
|
1130
|
+
},
|
|
1131
|
+
},
|
|
1132
|
+
},
|
|
1133
|
+
},
|
|
1134
|
+
},
|
|
1135
|
+
},
|
|
1136
|
+
},
|
|
1137
|
+
UASTC: {
|
|
1138
|
+
option: "forceRGBA",
|
|
1139
|
+
yes: {
|
|
1140
|
+
transcodeFormat: _transcoder__WEBPACK_IMPORTED_MODULE_0__.transcodeTarget.RGBA32,
|
|
1141
|
+
engineFormat: RGBA8Format,
|
|
1142
|
+
roundToMultiple4: false,
|
|
1143
|
+
},
|
|
1144
|
+
no: {
|
|
1145
|
+
cap: "astc",
|
|
1146
|
+
yes: {
|
|
1147
|
+
transcodeFormat: _transcoder__WEBPACK_IMPORTED_MODULE_0__.transcodeTarget.ASTC_4x4_RGBA,
|
|
1148
|
+
engineFormat: COMPRESSED_RGBA_ASTC_4x4_KHR,
|
|
1149
|
+
},
|
|
1150
|
+
no: {
|
|
1151
|
+
cap: "bptc",
|
|
1152
|
+
yes: {
|
|
1153
|
+
transcodeFormat: _transcoder__WEBPACK_IMPORTED_MODULE_0__.transcodeTarget.BC7_RGBA,
|
|
1154
|
+
engineFormat: COMPRESSED_RGBA_BPTC_UNORM_EXT,
|
|
1155
|
+
},
|
|
1156
|
+
no: {
|
|
1157
|
+
option: "useRGBAIfASTCBC7NotAvailableWhenUASTC",
|
|
1158
|
+
yes: {
|
|
1159
|
+
transcodeFormat: _transcoder__WEBPACK_IMPORTED_MODULE_0__.transcodeTarget.RGBA32,
|
|
1160
|
+
engineFormat: RGBA8Format,
|
|
1161
|
+
roundToMultiple4: false,
|
|
1162
|
+
},
|
|
1163
|
+
no: {
|
|
1164
|
+
cap: "etc2",
|
|
1165
|
+
yes: {
|
|
1166
|
+
alpha: true,
|
|
1167
|
+
yes: {
|
|
1168
|
+
transcodeFormat: _transcoder__WEBPACK_IMPORTED_MODULE_0__.transcodeTarget.ETC2_RGBA,
|
|
1169
|
+
engineFormat: COMPRESSED_RGBA8_ETC2_EAC,
|
|
1170
|
+
},
|
|
1171
|
+
no: {
|
|
1172
|
+
transcodeFormat: _transcoder__WEBPACK_IMPORTED_MODULE_0__.transcodeTarget.ETC1_RGB,
|
|
1173
|
+
engineFormat: COMPRESSED_RGB8_ETC2,
|
|
1174
|
+
},
|
|
1175
|
+
},
|
|
1176
|
+
no: {
|
|
1177
|
+
cap: "etc1",
|
|
1178
|
+
yes: {
|
|
1179
|
+
transcodeFormat: _transcoder__WEBPACK_IMPORTED_MODULE_0__.transcodeTarget.ETC1_RGB,
|
|
1180
|
+
engineFormat: COMPRESSED_RGB_ETC1_WEBGL,
|
|
1181
|
+
},
|
|
1182
|
+
no: {
|
|
1183
|
+
cap: "s3tc",
|
|
1184
|
+
yes: {
|
|
1185
|
+
alpha: true,
|
|
1186
|
+
yes: {
|
|
1187
|
+
transcodeFormat: _transcoder__WEBPACK_IMPORTED_MODULE_0__.transcodeTarget.BC3_RGBA,
|
|
1188
|
+
engineFormat: COMPRESSED_RGBA_S3TC_DXT5_EXT,
|
|
1189
|
+
},
|
|
1190
|
+
no: {
|
|
1191
|
+
transcodeFormat: _transcoder__WEBPACK_IMPORTED_MODULE_0__.transcodeTarget.BC1_RGB,
|
|
1192
|
+
engineFormat: COMPRESSED_RGB_S3TC_DXT1_EXT,
|
|
1193
|
+
},
|
|
1194
|
+
},
|
|
1195
|
+
no: {
|
|
1196
|
+
cap: "pvrtc",
|
|
1197
|
+
needsPowerOfTwo: true,
|
|
1198
|
+
yes: {
|
|
1199
|
+
alpha: true,
|
|
1200
|
+
yes: {
|
|
1201
|
+
transcodeFormat: _transcoder__WEBPACK_IMPORTED_MODULE_0__.transcodeTarget.PVRTC1_4_RGBA,
|
|
1202
|
+
engineFormat: COMPRESSED_RGBA_PVRTC_4BPPV1_IMG,
|
|
1203
|
+
},
|
|
1204
|
+
no: {
|
|
1205
|
+
transcodeFormat: _transcoder__WEBPACK_IMPORTED_MODULE_0__.transcodeTarget.PVRTC1_4_RGB,
|
|
1206
|
+
engineFormat: COMPRESSED_RGB_PVRTC_4BPPV1_IMG,
|
|
1207
|
+
},
|
|
1208
|
+
},
|
|
1209
|
+
no: {
|
|
1210
|
+
transcodeFormat: _transcoder__WEBPACK_IMPORTED_MODULE_0__.transcodeTarget.RGBA32,
|
|
1211
|
+
engineFormat: RGBA8Format,
|
|
1212
|
+
roundToMultiple4: false,
|
|
1213
|
+
},
|
|
1214
|
+
},
|
|
1215
|
+
},
|
|
1216
|
+
},
|
|
1217
|
+
},
|
|
1218
|
+
},
|
|
1219
|
+
},
|
|
1220
|
+
},
|
|
1221
|
+
},
|
|
1222
|
+
};
|
|
1223
|
+
class TranscodeDecisionTree {
|
|
1224
|
+
constructor(textureFormat, hasAlpha, isPowerOfTwo, caps, options) {
|
|
1225
|
+
this._hasAlpha = hasAlpha;
|
|
1226
|
+
this._isPowerOfTwo = isPowerOfTwo;
|
|
1227
|
+
this._caps = caps;
|
|
1228
|
+
this._options = options !== null && options !== void 0 ? options : {};
|
|
1229
|
+
this._parseNode(textureFormat === _transcoder__WEBPACK_IMPORTED_MODULE_0__.sourceTextureFormat.UASTC4x4 ? DecisionTree.UASTC : DecisionTree.ETC1S);
|
|
1230
|
+
}
|
|
1231
|
+
static _IsLeafNode(node) {
|
|
1232
|
+
return node.transcodeFormat !== undefined;
|
|
1233
|
+
}
|
|
1234
|
+
get transcodeFormat() {
|
|
1235
|
+
return this._transcodeFormat;
|
|
1236
|
+
}
|
|
1237
|
+
get engineFormat() {
|
|
1238
|
+
return this._engineFormat;
|
|
1239
|
+
}
|
|
1240
|
+
get roundToMultiple4() {
|
|
1241
|
+
return this._roundToMultiple4;
|
|
1242
|
+
}
|
|
1243
|
+
_parseNode(node) {
|
|
1244
|
+
var _a;
|
|
1245
|
+
if (TranscodeDecisionTree._IsLeafNode(node)) {
|
|
1246
|
+
this._transcodeFormat = node.transcodeFormat;
|
|
1247
|
+
this._engineFormat = node.engineFormat;
|
|
1248
|
+
this._roundToMultiple4 = (_a = node.roundToMultiple4) !== null && _a !== void 0 ? _a : true;
|
|
1249
|
+
}
|
|
1250
|
+
else {
|
|
1251
|
+
let condition = true;
|
|
1252
|
+
if (node.cap !== undefined) {
|
|
1253
|
+
condition = condition && this._caps[node.cap];
|
|
1254
|
+
}
|
|
1255
|
+
if (node.option !== undefined) {
|
|
1256
|
+
condition = condition && this._options[node.option];
|
|
1257
|
+
}
|
|
1258
|
+
if (node.alpha !== undefined) {
|
|
1259
|
+
condition = condition && this._hasAlpha === node.alpha;
|
|
1260
|
+
}
|
|
1261
|
+
if (node.needsPowerOfTwo !== undefined) {
|
|
1262
|
+
condition = condition && this._isPowerOfTwo === node.needsPowerOfTwo;
|
|
1263
|
+
}
|
|
1264
|
+
this._parseNode(condition ? node.yes : node.no);
|
|
1265
|
+
}
|
|
1266
|
+
}
|
|
1267
|
+
}
|
|
1268
1268
|
|
|
1269
1269
|
|
|
1270
1270
|
/***/ }),
|
|
@@ -1281,49 +1281,49 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
1281
1281
|
/* harmony export */ "sourceTextureFormat": () => (/* binding */ sourceTextureFormat),
|
|
1282
1282
|
/* harmony export */ "transcodeTarget": () => (/* binding */ transcodeTarget)
|
|
1283
1283
|
/* harmony export */ });
|
|
1284
|
-
/**
|
|
1285
|
-
* @hidden
|
|
1286
|
-
*/
|
|
1287
|
-
var sourceTextureFormat;
|
|
1288
|
-
(function (sourceTextureFormat) {
|
|
1289
|
-
sourceTextureFormat[sourceTextureFormat["ETC1S"] = 0] = "ETC1S";
|
|
1290
|
-
sourceTextureFormat[sourceTextureFormat["UASTC4x4"] = 1] = "UASTC4x4";
|
|
1291
|
-
})(sourceTextureFormat || (sourceTextureFormat = {}));
|
|
1292
|
-
/**
|
|
1293
|
-
* @hidden
|
|
1294
|
-
*/
|
|
1295
|
-
var transcodeTarget;
|
|
1296
|
-
(function (transcodeTarget) {
|
|
1297
|
-
transcodeTarget[transcodeTarget["ASTC_4x4_RGBA"] = 0] = "ASTC_4x4_RGBA";
|
|
1298
|
-
transcodeTarget[transcodeTarget["BC7_RGBA"] = 1] = "BC7_RGBA";
|
|
1299
|
-
transcodeTarget[transcodeTarget["BC3_RGBA"] = 2] = "BC3_RGBA";
|
|
1300
|
-
transcodeTarget[transcodeTarget["BC1_RGB"] = 3] = "BC1_RGB";
|
|
1301
|
-
transcodeTarget[transcodeTarget["PVRTC1_4_RGBA"] = 4] = "PVRTC1_4_RGBA";
|
|
1302
|
-
transcodeTarget[transcodeTarget["PVRTC1_4_RGB"] = 5] = "PVRTC1_4_RGB";
|
|
1303
|
-
transcodeTarget[transcodeTarget["ETC2_RGBA"] = 6] = "ETC2_RGBA";
|
|
1304
|
-
transcodeTarget[transcodeTarget["ETC1_RGB"] = 7] = "ETC1_RGB";
|
|
1305
|
-
transcodeTarget[transcodeTarget["RGBA32"] = 8] = "RGBA32";
|
|
1306
|
-
})(transcodeTarget || (transcodeTarget = {}));
|
|
1307
|
-
/**
|
|
1308
|
-
* @hidden
|
|
1309
|
-
*/
|
|
1310
|
-
class Transcoder {
|
|
1311
|
-
static CanTranscode(src, dst, isInGammaSpace) {
|
|
1312
|
-
return false;
|
|
1313
|
-
}
|
|
1314
|
-
getName() {
|
|
1315
|
-
return Transcoder.Name;
|
|
1316
|
-
}
|
|
1317
|
-
initialize() { }
|
|
1318
|
-
needMemoryManager() {
|
|
1319
|
-
return false;
|
|
1320
|
-
}
|
|
1321
|
-
setMemoryManager(memoryMgr) { }
|
|
1322
|
-
transcode(src, dst, level, width, height, uncompressedByteLength, ktx2Reader, imageDesc, encodedData) {
|
|
1323
|
-
return Promise.resolve(null);
|
|
1324
|
-
}
|
|
1325
|
-
}
|
|
1326
|
-
Transcoder.Name = "Transcoder";
|
|
1284
|
+
/**
|
|
1285
|
+
* @hidden
|
|
1286
|
+
*/
|
|
1287
|
+
var sourceTextureFormat;
|
|
1288
|
+
(function (sourceTextureFormat) {
|
|
1289
|
+
sourceTextureFormat[sourceTextureFormat["ETC1S"] = 0] = "ETC1S";
|
|
1290
|
+
sourceTextureFormat[sourceTextureFormat["UASTC4x4"] = 1] = "UASTC4x4";
|
|
1291
|
+
})(sourceTextureFormat || (sourceTextureFormat = {}));
|
|
1292
|
+
/**
|
|
1293
|
+
* @hidden
|
|
1294
|
+
*/
|
|
1295
|
+
var transcodeTarget;
|
|
1296
|
+
(function (transcodeTarget) {
|
|
1297
|
+
transcodeTarget[transcodeTarget["ASTC_4x4_RGBA"] = 0] = "ASTC_4x4_RGBA";
|
|
1298
|
+
transcodeTarget[transcodeTarget["BC7_RGBA"] = 1] = "BC7_RGBA";
|
|
1299
|
+
transcodeTarget[transcodeTarget["BC3_RGBA"] = 2] = "BC3_RGBA";
|
|
1300
|
+
transcodeTarget[transcodeTarget["BC1_RGB"] = 3] = "BC1_RGB";
|
|
1301
|
+
transcodeTarget[transcodeTarget["PVRTC1_4_RGBA"] = 4] = "PVRTC1_4_RGBA";
|
|
1302
|
+
transcodeTarget[transcodeTarget["PVRTC1_4_RGB"] = 5] = "PVRTC1_4_RGB";
|
|
1303
|
+
transcodeTarget[transcodeTarget["ETC2_RGBA"] = 6] = "ETC2_RGBA";
|
|
1304
|
+
transcodeTarget[transcodeTarget["ETC1_RGB"] = 7] = "ETC1_RGB";
|
|
1305
|
+
transcodeTarget[transcodeTarget["RGBA32"] = 8] = "RGBA32";
|
|
1306
|
+
})(transcodeTarget || (transcodeTarget = {}));
|
|
1307
|
+
/**
|
|
1308
|
+
* @hidden
|
|
1309
|
+
*/
|
|
1310
|
+
class Transcoder {
|
|
1311
|
+
static CanTranscode(src, dst, isInGammaSpace) {
|
|
1312
|
+
return false;
|
|
1313
|
+
}
|
|
1314
|
+
getName() {
|
|
1315
|
+
return Transcoder.Name;
|
|
1316
|
+
}
|
|
1317
|
+
initialize() { }
|
|
1318
|
+
needMemoryManager() {
|
|
1319
|
+
return false;
|
|
1320
|
+
}
|
|
1321
|
+
setMemoryManager(memoryMgr) { }
|
|
1322
|
+
transcode(src, dst, level, width, height, uncompressedByteLength, ktx2Reader, imageDesc, encodedData) {
|
|
1323
|
+
return Promise.resolve(null);
|
|
1324
|
+
}
|
|
1325
|
+
}
|
|
1326
|
+
Transcoder.Name = "Transcoder";
|
|
1327
1327
|
|
|
1328
1328
|
|
|
1329
1329
|
/***/ }),
|
|
@@ -1340,55 +1340,55 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
1340
1340
|
/* harmony export */ });
|
|
1341
1341
|
/* harmony import */ var _transcoder__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./transcoder */ "../../../tools/ktx2Decoder/dist/transcoder.js");
|
|
1342
1342
|
/* harmony import */ var _wasmMemoryManager__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./wasmMemoryManager */ "../../../tools/ktx2Decoder/dist/wasmMemoryManager.js");
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
/**
|
|
1346
|
-
* @hidden
|
|
1347
|
-
*/
|
|
1348
|
-
class TranscoderManager {
|
|
1349
|
-
static RegisterTranscoder(transcoder) {
|
|
1350
|
-
TranscoderManager._Transcoders.push(transcoder);
|
|
1351
|
-
}
|
|
1352
|
-
findTranscoder(src, dst, isInGammaSpace, bypass) {
|
|
1353
|
-
let transcoder = null;
|
|
1354
|
-
const key = _transcoder__WEBPACK_IMPORTED_MODULE_0__.sourceTextureFormat[src] + "_" + _transcoder__WEBPACK_IMPORTED_MODULE_0__.transcodeTarget[dst];
|
|
1355
|
-
for (let i = 0; i < TranscoderManager._Transcoders.length; ++i) {
|
|
1356
|
-
if (TranscoderManager._Transcoders[i].CanTranscode(src, dst, isInGammaSpace) && (!bypass || bypass.indexOf(TranscoderManager._Transcoders[i].Name) < 0)) {
|
|
1357
|
-
transcoder = this._getExistingTranscoder(key, TranscoderManager._Transcoders[i].Name);
|
|
1358
|
-
if (!transcoder) {
|
|
1359
|
-
transcoder = new TranscoderManager._Transcoders[i]();
|
|
1360
|
-
transcoder.initialize();
|
|
1361
|
-
if (transcoder.needMemoryManager()) {
|
|
1362
|
-
if (!this._wasmMemoryManager) {
|
|
1363
|
-
this._wasmMemoryManager = new _wasmMemoryManager__WEBPACK_IMPORTED_MODULE_1__.WASMMemoryManager();
|
|
1364
|
-
}
|
|
1365
|
-
transcoder.setMemoryManager(this._wasmMemoryManager);
|
|
1366
|
-
}
|
|
1367
|
-
if (!TranscoderManager._TranscoderInstances[key]) {
|
|
1368
|
-
TranscoderManager._TranscoderInstances[key] = [];
|
|
1369
|
-
}
|
|
1370
|
-
TranscoderManager._TranscoderInstances[key].push(transcoder);
|
|
1371
|
-
}
|
|
1372
|
-
break;
|
|
1373
|
-
}
|
|
1374
|
-
}
|
|
1375
|
-
return transcoder;
|
|
1376
|
-
}
|
|
1377
|
-
_getExistingTranscoder(key, transcoderName) {
|
|
1378
|
-
const transcoders = TranscoderManager._TranscoderInstances[key];
|
|
1379
|
-
if (transcoders) {
|
|
1380
|
-
for (let t = 0; t < transcoders.length; ++t) {
|
|
1381
|
-
const transcoder = transcoders[t];
|
|
1382
|
-
if (transcoderName === transcoder.getName()) {
|
|
1383
|
-
return transcoder;
|
|
1384
|
-
}
|
|
1385
|
-
}
|
|
1386
|
-
}
|
|
1387
|
-
return null;
|
|
1388
|
-
}
|
|
1389
|
-
}
|
|
1390
|
-
TranscoderManager._Transcoders = [];
|
|
1391
|
-
TranscoderManager._TranscoderInstances = {};
|
|
1343
|
+
|
|
1344
|
+
|
|
1345
|
+
/**
|
|
1346
|
+
* @hidden
|
|
1347
|
+
*/
|
|
1348
|
+
class TranscoderManager {
|
|
1349
|
+
static RegisterTranscoder(transcoder) {
|
|
1350
|
+
TranscoderManager._Transcoders.push(transcoder);
|
|
1351
|
+
}
|
|
1352
|
+
findTranscoder(src, dst, isInGammaSpace, bypass) {
|
|
1353
|
+
let transcoder = null;
|
|
1354
|
+
const key = _transcoder__WEBPACK_IMPORTED_MODULE_0__.sourceTextureFormat[src] + "_" + _transcoder__WEBPACK_IMPORTED_MODULE_0__.transcodeTarget[dst];
|
|
1355
|
+
for (let i = 0; i < TranscoderManager._Transcoders.length; ++i) {
|
|
1356
|
+
if (TranscoderManager._Transcoders[i].CanTranscode(src, dst, isInGammaSpace) && (!bypass || bypass.indexOf(TranscoderManager._Transcoders[i].Name) < 0)) {
|
|
1357
|
+
transcoder = this._getExistingTranscoder(key, TranscoderManager._Transcoders[i].Name);
|
|
1358
|
+
if (!transcoder) {
|
|
1359
|
+
transcoder = new TranscoderManager._Transcoders[i]();
|
|
1360
|
+
transcoder.initialize();
|
|
1361
|
+
if (transcoder.needMemoryManager()) {
|
|
1362
|
+
if (!this._wasmMemoryManager) {
|
|
1363
|
+
this._wasmMemoryManager = new _wasmMemoryManager__WEBPACK_IMPORTED_MODULE_1__.WASMMemoryManager();
|
|
1364
|
+
}
|
|
1365
|
+
transcoder.setMemoryManager(this._wasmMemoryManager);
|
|
1366
|
+
}
|
|
1367
|
+
if (!TranscoderManager._TranscoderInstances[key]) {
|
|
1368
|
+
TranscoderManager._TranscoderInstances[key] = [];
|
|
1369
|
+
}
|
|
1370
|
+
TranscoderManager._TranscoderInstances[key].push(transcoder);
|
|
1371
|
+
}
|
|
1372
|
+
break;
|
|
1373
|
+
}
|
|
1374
|
+
}
|
|
1375
|
+
return transcoder;
|
|
1376
|
+
}
|
|
1377
|
+
_getExistingTranscoder(key, transcoderName) {
|
|
1378
|
+
const transcoders = TranscoderManager._TranscoderInstances[key];
|
|
1379
|
+
if (transcoders) {
|
|
1380
|
+
for (let t = 0; t < transcoders.length; ++t) {
|
|
1381
|
+
const transcoder = transcoders[t];
|
|
1382
|
+
if (transcoderName === transcoder.getName()) {
|
|
1383
|
+
return transcoder;
|
|
1384
|
+
}
|
|
1385
|
+
}
|
|
1386
|
+
}
|
|
1387
|
+
return null;
|
|
1388
|
+
}
|
|
1389
|
+
}
|
|
1390
|
+
TranscoderManager._Transcoders = [];
|
|
1391
|
+
TranscoderManager._TranscoderInstances = {};
|
|
1392
1392
|
|
|
1393
1393
|
|
|
1394
1394
|
/***/ }),
|
|
@@ -1403,68 +1403,68 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
1403
1403
|
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
1404
1404
|
/* harmony export */ "WASMMemoryManager": () => (/* binding */ WASMMemoryManager)
|
|
1405
1405
|
/* harmony export */ });
|
|
1406
|
-
/**
|
|
1407
|
-
* @hidden
|
|
1408
|
-
*/
|
|
1409
|
-
class WASMMemoryManager {
|
|
1410
|
-
constructor(initialMemoryPages = WASMMemoryManager.InitialMemoryPages) {
|
|
1411
|
-
this._numPages = initialMemoryPages;
|
|
1412
|
-
this._memory = new WebAssembly.Memory({ initial: this._numPages });
|
|
1413
|
-
this._memoryViewByteLength = this._numPages << 16;
|
|
1414
|
-
this._memoryViewOffset = 0;
|
|
1415
|
-
this._memoryView = new Uint8Array(this._memory.buffer, this._memoryViewOffset, this._memoryViewByteLength);
|
|
1416
|
-
}
|
|
1417
|
-
static LoadWASM(path) {
|
|
1418
|
-
if (this.LoadBinariesFromCurrentThread) {
|
|
1419
|
-
return new Promise((resolve, reject) => {
|
|
1420
|
-
fetch(path)
|
|
1421
|
-
.then((response) => {
|
|
1422
|
-
if (response.ok) {
|
|
1423
|
-
return response.arrayBuffer();
|
|
1424
|
-
}
|
|
1425
|
-
throw new Error(`Could not fetch the wasm component from "${path}": ${response.status} - ${response.statusText}`);
|
|
1426
|
-
})
|
|
1427
|
-
.then((wasmBinary) => resolve(wasmBinary))
|
|
1428
|
-
.catch((reason) => {
|
|
1429
|
-
reject(reason);
|
|
1430
|
-
});
|
|
1431
|
-
});
|
|
1432
|
-
}
|
|
1433
|
-
const id = this._RequestId++;
|
|
1434
|
-
return new Promise((resolve) => {
|
|
1435
|
-
const wasmLoadedHandler = (msg) => {
|
|
1436
|
-
if (msg.data.action === "wasmLoaded" && msg.data.id === id) {
|
|
1437
|
-
self.removeEventListener("message", wasmLoadedHandler);
|
|
1438
|
-
resolve(msg.data.wasmBinary);
|
|
1439
|
-
}
|
|
1440
|
-
};
|
|
1441
|
-
self.addEventListener("message", wasmLoadedHandler);
|
|
1442
|
-
postMessage({ action: "loadWASM", path: path, id: id });
|
|
1443
|
-
});
|
|
1444
|
-
}
|
|
1445
|
-
get wasmMemory() {
|
|
1446
|
-
return this._memory;
|
|
1447
|
-
}
|
|
1448
|
-
getMemoryView(numPages, offset = 0, byteLength) {
|
|
1449
|
-
byteLength = byteLength !== null && byteLength !== void 0 ? byteLength : numPages << 16;
|
|
1450
|
-
if (this._numPages < numPages) {
|
|
1451
|
-
this._memory.grow(numPages - this._numPages);
|
|
1452
|
-
this._numPages = numPages;
|
|
1453
|
-
this._memoryView = new Uint8Array(this._memory.buffer, offset, byteLength);
|
|
1454
|
-
this._memoryViewByteLength = byteLength;
|
|
1455
|
-
this._memoryViewOffset = offset;
|
|
1456
|
-
}
|
|
1457
|
-
else {
|
|
1458
|
-
this._memoryView = new Uint8Array(this._memory.buffer, offset, byteLength);
|
|
1459
|
-
this._memoryViewByteLength = byteLength;
|
|
1460
|
-
this._memoryViewOffset = offset;
|
|
1461
|
-
}
|
|
1462
|
-
return this._memoryView;
|
|
1463
|
-
}
|
|
1464
|
-
}
|
|
1465
|
-
WASMMemoryManager.LoadBinariesFromCurrentThread = true;
|
|
1466
|
-
WASMMemoryManager.InitialMemoryPages = (1 * 1024 * 1024) >> 16; // 1 Mbytes
|
|
1467
|
-
WASMMemoryManager._RequestId = 0;
|
|
1406
|
+
/**
|
|
1407
|
+
* @hidden
|
|
1408
|
+
*/
|
|
1409
|
+
class WASMMemoryManager {
|
|
1410
|
+
constructor(initialMemoryPages = WASMMemoryManager.InitialMemoryPages) {
|
|
1411
|
+
this._numPages = initialMemoryPages;
|
|
1412
|
+
this._memory = new WebAssembly.Memory({ initial: this._numPages });
|
|
1413
|
+
this._memoryViewByteLength = this._numPages << 16;
|
|
1414
|
+
this._memoryViewOffset = 0;
|
|
1415
|
+
this._memoryView = new Uint8Array(this._memory.buffer, this._memoryViewOffset, this._memoryViewByteLength);
|
|
1416
|
+
}
|
|
1417
|
+
static LoadWASM(path) {
|
|
1418
|
+
if (this.LoadBinariesFromCurrentThread) {
|
|
1419
|
+
return new Promise((resolve, reject) => {
|
|
1420
|
+
fetch(path)
|
|
1421
|
+
.then((response) => {
|
|
1422
|
+
if (response.ok) {
|
|
1423
|
+
return response.arrayBuffer();
|
|
1424
|
+
}
|
|
1425
|
+
throw new Error(`Could not fetch the wasm component from "${path}": ${response.status} - ${response.statusText}`);
|
|
1426
|
+
})
|
|
1427
|
+
.then((wasmBinary) => resolve(wasmBinary))
|
|
1428
|
+
.catch((reason) => {
|
|
1429
|
+
reject(reason);
|
|
1430
|
+
});
|
|
1431
|
+
});
|
|
1432
|
+
}
|
|
1433
|
+
const id = this._RequestId++;
|
|
1434
|
+
return new Promise((resolve) => {
|
|
1435
|
+
const wasmLoadedHandler = (msg) => {
|
|
1436
|
+
if (msg.data.action === "wasmLoaded" && msg.data.id === id) {
|
|
1437
|
+
self.removeEventListener("message", wasmLoadedHandler);
|
|
1438
|
+
resolve(msg.data.wasmBinary);
|
|
1439
|
+
}
|
|
1440
|
+
};
|
|
1441
|
+
self.addEventListener("message", wasmLoadedHandler);
|
|
1442
|
+
postMessage({ action: "loadWASM", path: path, id: id });
|
|
1443
|
+
});
|
|
1444
|
+
}
|
|
1445
|
+
get wasmMemory() {
|
|
1446
|
+
return this._memory;
|
|
1447
|
+
}
|
|
1448
|
+
getMemoryView(numPages, offset = 0, byteLength) {
|
|
1449
|
+
byteLength = byteLength !== null && byteLength !== void 0 ? byteLength : numPages << 16;
|
|
1450
|
+
if (this._numPages < numPages) {
|
|
1451
|
+
this._memory.grow(numPages - this._numPages);
|
|
1452
|
+
this._numPages = numPages;
|
|
1453
|
+
this._memoryView = new Uint8Array(this._memory.buffer, offset, byteLength);
|
|
1454
|
+
this._memoryViewByteLength = byteLength;
|
|
1455
|
+
this._memoryViewOffset = offset;
|
|
1456
|
+
}
|
|
1457
|
+
else {
|
|
1458
|
+
this._memoryView = new Uint8Array(this._memory.buffer, offset, byteLength);
|
|
1459
|
+
this._memoryViewByteLength = byteLength;
|
|
1460
|
+
this._memoryViewOffset = offset;
|
|
1461
|
+
}
|
|
1462
|
+
return this._memoryView;
|
|
1463
|
+
}
|
|
1464
|
+
}
|
|
1465
|
+
WASMMemoryManager.LoadBinariesFromCurrentThread = true;
|
|
1466
|
+
WASMMemoryManager.InitialMemoryPages = (1 * 1024 * 1024) >> 16; // 1 Mbytes
|
|
1467
|
+
WASMMemoryManager._RequestId = 0;
|
|
1468
1468
|
|
|
1469
1469
|
|
|
1470
1470
|
/***/ }),
|
|
@@ -1479,98 +1479,98 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
1479
1479
|
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
1480
1480
|
/* harmony export */ "ZSTDDecoder": () => (/* binding */ ZSTDDecoder)
|
|
1481
1481
|
/* harmony export */ });
|
|
1482
|
-
let init;
|
|
1483
|
-
let instance;
|
|
1484
|
-
let heap;
|
|
1485
|
-
const IMPORT_OBJECT = {
|
|
1486
|
-
env: {
|
|
1487
|
-
emscripten_notify_memory_growth: function () {
|
|
1488
|
-
heap = new Uint8Array(instance.exports.memory.buffer);
|
|
1489
|
-
},
|
|
1490
|
-
},
|
|
1491
|
-
};
|
|
1492
|
-
/**
|
|
1493
|
-
* ZSTD (Zstandard) decoder.
|
|
1494
|
-
*/
|
|
1495
|
-
class ZSTDDecoder {
|
|
1496
|
-
init() {
|
|
1497
|
-
if (init) {
|
|
1498
|
-
return init;
|
|
1499
|
-
}
|
|
1500
|
-
if (typeof fetch !== "undefined") {
|
|
1501
|
-
// Web.
|
|
1502
|
-
init = fetch(ZSTDDecoder.WasmModuleURL)
|
|
1503
|
-
.then((response) => {
|
|
1504
|
-
if (response.ok) {
|
|
1505
|
-
return response.arrayBuffer();
|
|
1506
|
-
}
|
|
1507
|
-
throw new Error(`Could not fetch the wasm component for the Zstandard decompression lib: ${response.status} - ${response.statusText}`);
|
|
1508
|
-
})
|
|
1509
|
-
.then((arrayBuffer) => WebAssembly.instantiate(arrayBuffer, IMPORT_OBJECT))
|
|
1510
|
-
.then(this._init);
|
|
1511
|
-
}
|
|
1512
|
-
else {
|
|
1513
|
-
// Node.js.
|
|
1514
|
-
init = WebAssembly.instantiateStreaming(fetch(ZSTDDecoder.WasmModuleURL), IMPORT_OBJECT).then(this._init);
|
|
1515
|
-
}
|
|
1516
|
-
return init;
|
|
1517
|
-
}
|
|
1518
|
-
_init(result) {
|
|
1519
|
-
instance = result.instance;
|
|
1520
|
-
IMPORT_OBJECT.env.emscripten_notify_memory_growth(); // initialize heap.
|
|
1521
|
-
}
|
|
1522
|
-
decode(array, uncompressedSize = 0) {
|
|
1523
|
-
if (!instance) {
|
|
1524
|
-
throw new Error(`ZSTDDecoder: Await .init() before decoding.`);
|
|
1525
|
-
}
|
|
1526
|
-
// Write compressed data into WASM memory.
|
|
1527
|
-
const compressedSize = array.byteLength;
|
|
1528
|
-
const compressedPtr = instance.exports.malloc(compressedSize);
|
|
1529
|
-
heap.set(array, compressedPtr);
|
|
1530
|
-
// Decompress into WASM memory.
|
|
1531
|
-
uncompressedSize = uncompressedSize || Number(instance.exports.ZSTD_findDecompressedSize(compressedPtr, compressedSize));
|
|
1532
|
-
const uncompressedPtr = instance.exports.malloc(uncompressedSize);
|
|
1533
|
-
const actualSize = instance.exports.ZSTD_decompress(uncompressedPtr, uncompressedSize, compressedPtr, compressedSize);
|
|
1534
|
-
// Read decompressed data and free WASM memory.
|
|
1535
|
-
const dec = heap.slice(uncompressedPtr, uncompressedPtr + actualSize);
|
|
1536
|
-
instance.exports.free(compressedPtr);
|
|
1537
|
-
instance.exports.free(uncompressedPtr);
|
|
1538
|
-
return dec;
|
|
1539
|
-
}
|
|
1540
|
-
}
|
|
1541
|
-
ZSTDDecoder.WasmModuleURL = "https://preview.babylonjs.com/zstddec.wasm";
|
|
1542
|
-
/**
|
|
1543
|
-
* BSD License
|
|
1544
|
-
*
|
|
1545
|
-
* For Zstandard software
|
|
1546
|
-
*
|
|
1547
|
-
* Copyright (c) 2016-present, Yann Collet, Facebook, Inc. All rights reserved.
|
|
1548
|
-
*
|
|
1549
|
-
* Redistribution and use in source and binary forms, with or without modification,
|
|
1550
|
-
* are permitted provided that the following conditions are met:
|
|
1551
|
-
*
|
|
1552
|
-
* * Redistributions of source code must retain the above copyright notice, this
|
|
1553
|
-
* list of conditions and the following disclaimer.
|
|
1554
|
-
*
|
|
1555
|
-
* * Redistributions in binary form must reproduce the above copyright notice,
|
|
1556
|
-
* this list of conditions and the following disclaimer in the documentation
|
|
1557
|
-
* and/or other materials provided with the distribution.
|
|
1558
|
-
*
|
|
1559
|
-
* * Neither the name Facebook nor the names of its contributors may be used to
|
|
1560
|
-
* endorse or promote products derived from this software without specific
|
|
1561
|
-
* prior written permission.
|
|
1562
|
-
*
|
|
1563
|
-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
1564
|
-
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
1565
|
-
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
1566
|
-
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
|
1567
|
-
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
1568
|
-
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
1569
|
-
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
|
1570
|
-
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
1571
|
-
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
1572
|
-
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
1573
|
-
*/
|
|
1482
|
+
let init;
|
|
1483
|
+
let instance;
|
|
1484
|
+
let heap;
|
|
1485
|
+
const IMPORT_OBJECT = {
|
|
1486
|
+
env: {
|
|
1487
|
+
emscripten_notify_memory_growth: function () {
|
|
1488
|
+
heap = new Uint8Array(instance.exports.memory.buffer);
|
|
1489
|
+
},
|
|
1490
|
+
},
|
|
1491
|
+
};
|
|
1492
|
+
/**
|
|
1493
|
+
* ZSTD (Zstandard) decoder.
|
|
1494
|
+
*/
|
|
1495
|
+
class ZSTDDecoder {
|
|
1496
|
+
init() {
|
|
1497
|
+
if (init) {
|
|
1498
|
+
return init;
|
|
1499
|
+
}
|
|
1500
|
+
if (typeof fetch !== "undefined") {
|
|
1501
|
+
// Web.
|
|
1502
|
+
init = fetch(ZSTDDecoder.WasmModuleURL)
|
|
1503
|
+
.then((response) => {
|
|
1504
|
+
if (response.ok) {
|
|
1505
|
+
return response.arrayBuffer();
|
|
1506
|
+
}
|
|
1507
|
+
throw new Error(`Could not fetch the wasm component for the Zstandard decompression lib: ${response.status} - ${response.statusText}`);
|
|
1508
|
+
})
|
|
1509
|
+
.then((arrayBuffer) => WebAssembly.instantiate(arrayBuffer, IMPORT_OBJECT))
|
|
1510
|
+
.then(this._init);
|
|
1511
|
+
}
|
|
1512
|
+
else {
|
|
1513
|
+
// Node.js.
|
|
1514
|
+
init = WebAssembly.instantiateStreaming(fetch(ZSTDDecoder.WasmModuleURL), IMPORT_OBJECT).then(this._init);
|
|
1515
|
+
}
|
|
1516
|
+
return init;
|
|
1517
|
+
}
|
|
1518
|
+
_init(result) {
|
|
1519
|
+
instance = result.instance;
|
|
1520
|
+
IMPORT_OBJECT.env.emscripten_notify_memory_growth(); // initialize heap.
|
|
1521
|
+
}
|
|
1522
|
+
decode(array, uncompressedSize = 0) {
|
|
1523
|
+
if (!instance) {
|
|
1524
|
+
throw new Error(`ZSTDDecoder: Await .init() before decoding.`);
|
|
1525
|
+
}
|
|
1526
|
+
// Write compressed data into WASM memory.
|
|
1527
|
+
const compressedSize = array.byteLength;
|
|
1528
|
+
const compressedPtr = instance.exports.malloc(compressedSize);
|
|
1529
|
+
heap.set(array, compressedPtr);
|
|
1530
|
+
// Decompress into WASM memory.
|
|
1531
|
+
uncompressedSize = uncompressedSize || Number(instance.exports.ZSTD_findDecompressedSize(compressedPtr, compressedSize));
|
|
1532
|
+
const uncompressedPtr = instance.exports.malloc(uncompressedSize);
|
|
1533
|
+
const actualSize = instance.exports.ZSTD_decompress(uncompressedPtr, uncompressedSize, compressedPtr, compressedSize);
|
|
1534
|
+
// Read decompressed data and free WASM memory.
|
|
1535
|
+
const dec = heap.slice(uncompressedPtr, uncompressedPtr + actualSize);
|
|
1536
|
+
instance.exports.free(compressedPtr);
|
|
1537
|
+
instance.exports.free(uncompressedPtr);
|
|
1538
|
+
return dec;
|
|
1539
|
+
}
|
|
1540
|
+
}
|
|
1541
|
+
ZSTDDecoder.WasmModuleURL = "https://preview.babylonjs.com/zstddec.wasm";
|
|
1542
|
+
/**
|
|
1543
|
+
* BSD License
|
|
1544
|
+
*
|
|
1545
|
+
* For Zstandard software
|
|
1546
|
+
*
|
|
1547
|
+
* Copyright (c) 2016-present, Yann Collet, Facebook, Inc. All rights reserved.
|
|
1548
|
+
*
|
|
1549
|
+
* Redistribution and use in source and binary forms, with or without modification,
|
|
1550
|
+
* are permitted provided that the following conditions are met:
|
|
1551
|
+
*
|
|
1552
|
+
* * Redistributions of source code must retain the above copyright notice, this
|
|
1553
|
+
* list of conditions and the following disclaimer.
|
|
1554
|
+
*
|
|
1555
|
+
* * Redistributions in binary form must reproduce the above copyright notice,
|
|
1556
|
+
* this list of conditions and the following disclaimer in the documentation
|
|
1557
|
+
* and/or other materials provided with the distribution.
|
|
1558
|
+
*
|
|
1559
|
+
* * Neither the name Facebook nor the names of its contributors may be used to
|
|
1560
|
+
* endorse or promote products derived from this software without specific
|
|
1561
|
+
* prior written permission.
|
|
1562
|
+
*
|
|
1563
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
1564
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
1565
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
1566
|
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
|
1567
|
+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
1568
|
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
1569
|
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
|
1570
|
+
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
1571
|
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
1572
|
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
1573
|
+
*/
|
|
1574
1574
|
|
|
1575
1575
|
|
|
1576
1576
|
/***/ })
|
|
@@ -1655,9 +1655,9 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
1655
1655
|
/* harmony export */ "ktx2decoder": () => (/* reexport module object */ ktx2decoder_legacy_legacy__WEBPACK_IMPORTED_MODULE_0__)
|
|
1656
1656
|
/* harmony export */ });
|
|
1657
1657
|
/* harmony import */ var ktx2decoder_legacy_legacy__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ktx2decoder/legacy/legacy */ "../../../tools/ktx2Decoder/dist/legacy/legacy.js");
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (ktx2decoder_legacy_legacy__WEBPACK_IMPORTED_MODULE_0__);
|
|
1658
|
+
|
|
1659
|
+
|
|
1660
|
+
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (ktx2decoder_legacy_legacy__WEBPACK_IMPORTED_MODULE_0__);
|
|
1661
1661
|
|
|
1662
1662
|
})();
|
|
1663
1663
|
|