[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Public WebGL] ArrayBuffer, Concatenation and String-Array Conversion, a proposal

Here are a few proposals for the typed arrays specification, that I think would help with the intuitiveness of that proposal. First of all, array concatenation.

In the current spec, when concatenated via the + operator, arrays stringify.

(new Int32Array([1])+new Int32Array([1])).length == 38 

In my proposed spec change, arrays would concatenate into the same type, if both sides were the same, otherwise an arraybuffer would be returned.

(new Int32Array([1])+new Int32Array([1])).length == 2
(new Int32Array([1])+new Int8Array([1])).length == 5

The use case for this would be building primitive structs, and also progressive downloads of arraybuffer data.

Converting strings to arrays:

In the current spec, no conversion is made:

new Int8Array("data")[0]
RangeError: ArrayBufferView size is not a small enough positive integer.

In my proposed spec change, the constructor for the individual arraybuffer specialized types take string arguments, and instantiate an arraybuffer with the individual unicode code points bitmasked to the size of the data type, here 0xFF) This would be easy to understand and provide reasonable compression of data.

new Int8Array("data")[0] == 100

One use case would be converting compressed vertex data embedded in json. This would also be a use case for immutable array buffers, if such are specified.

Converting arrays to strings:

new Int8Array("data").toUnicode()=="data"

Use case: I can't really come up with one, but it seems useful.
You are currently subscribed to public_webgl@khronos.org.
To unsubscribe, send an email to majordomo@khronos.org with
the following command in the body of your email: