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

[Public WebGL] typed array convenience

Typed arrays as specified by Khronos (https://www.khronos.org/registry/typedarray/specs/latest/) do not have convenient methods to fill an array.

To illustrate the issue I created this jsperf test: http://jsperf.com/typed-array-fast-filling

The most convenient method would be to fill a section of the array from arguments, a list and other typed arrays. Something like:

fillArray(r, i, [x0, y0, 1, 0, 0]);
fillArguments(r, i, x0, y0, 1, 0, 0);
Unfortunately that's also the second slowest method to do it as the jsperf test shows (screenshot here http://codeflow.org/pictures/typed-array-test.png and attached).
The fastest method by far (a factor of 3-4x) is the following:
r[i] = x0;
r[i + 1] = y0;
r[i + 2] = 1;
r[i + 3] = 0;
r[i + 4] = 0; 
 i += 5

This is unfortunate because it's also the least maintainable and readable code possible.

I propose an addition to the typed array specification that introduces these methods like
The name or the semantic of the methods doesn't matter to me, as long as they facilitate fast, efficient and convenient filling of typed arrays.

It is quite often for tasks todo with tessellation, subdivision, geometry generation etc. to have to write code like that.

Attachment: typed-array-test.png
Description: PNG image