HTML and CSS Reference
In-Depth Information
var dst = null;
var dxtData = null;
var cachedDstSize = 0;
// The emscripten module.
var Module = null;
// Copy an array of bytes into or out of the emscripten heap.
function arrayBufferCopy(src, dst, dstByteOffset, numBytes) {
var i;
var dst32Offset = dstByteOffset / 4;
var tail = (numBytes % 4);
var src32 = new Uint32Array(src.buffer, 0, (numBytes - tail) / 4);
var dst32 = new Uint32Array(dst.buffer);
for (i = 0; i < src32.length; i++) {
dst32[dst32Offset + i] = src32[i];
for (i = numBytes - tail; i < numBytes; i++) {
dst[dstByteOffset + i] = src[i];
return // Decompression function (we'll fill this in in a moment.)
What's happening here is that you're creating an anonymous function (and with it a new variable scope), creating
your “private” variables and a utility function within that scope, and returning the actual decompression function. You
then immediately call the anonymous function and assign its return value to decompressCRN , which will be what you
call to decompress the texture.
The actual decompression function looks like the code in Listing 21-12. (It gets inserted at the return statement in
the code from Listing 21-11.)
Listing 21-12. decompressCRN function, Part 2
// This is the actual function that is executed when you call decompressCRN.
return function(arrayBuffer, callback, errorCallback) {
// Callbacks must be provided.
if (!callback || !errorCallback) { return; }
// If the emscripten module has not been loaded yet do so now.
// Executes the massive code blob at the top of the file.
if (!Module) {
Module = LoadCrunchDecoder();
// Copy the contents of the arrayBuffer into emscriptens heap.
var srcSize = arrayBuffer.byteLength;
var bytes = new Uint8Array(arrayBuffer);
var src = Module._malloc(srcSize);
arrayBufferCopy(bytes, Module.HEAPU8, src, srcSize);
Search WWH ::

Custom Search