We intend to change the JavaScript representation of an array of float32
values to an array of uint8
bytes. It's implied that doing so might help us more efficiently transfer the data over HTTP requests.
To do so, we have tried:
var vertexBuffer = ...; // Float32Array
console.log('vertex buffer =', vertexBuffer);
console.log('vertex buffer byte length = ', vertexBuffer.byteLength)
var arr = new Uint8Array(vertexBuffer);
console.log('converted to Uint8Array: ', arr);
console.log('Byte length = ', arr.byteLength);
console.log('Byte length / 4 = ', arr.byteLength / 4);
The logs are:
Implication
The Size of Float32Array
is 84942
and that's the same for the resulted Uint8Array
!
Meaning each float32
value is converted to a single uint8
! Which is not what we intend to do! Right?
We intend to interpret each float32
as four uint8
values. How can we do so in the most efficient way? The change of interpretation shouldn't require any computation, right?