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

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

My notes in the body.

On 10/05/2010 12:55 PM, Chris Marrin wrote:
It made it!

On Oct 5, 2010, at 12:17 PM, Samuel Kleiner wrote:

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
This would amount to a change in JavaScript semantics. You could apply this proposal to all Arrays, but instead they use a concat() function. I think it would be better to add a concat() function to the Typed Arrays. And you could write such a function in JavaScript, so I'm not sure it would be useful to add to the spec.

Also, you can do the equivalent of the proposed array concatenation by simply providing a list of the arrays to one of the forms of the constructor.
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.
The question here is why isn't there a function for doing these conversions between JavaScript Strings and Arrays? I suppose the answer is that it's not common enough; storing a unicode value in an array isn't done very much. So JS functions which loop over the string, calling charCodeAt() for each character, give you a reasonable solution. I'm not sure why that would not be a reasonable solution here as well. I'm not sure your example would be commonly used. Assuming we get the ability to read an ArrayBuffer from XHR, the better way to load large vertex data will be to load the binary data directly.
And it works like a charm!


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: