Kode / Kha

Ultra-portable, high performance, open source multimedia framework.
http://kha.tech
zlib License
1.49k stars 173 forks source link

[HTML5] Write matrix data directly into js array #1454

Closed MoritzBrueckner closed 1 year ago

MoritzBrueckner commented 1 year ago

As discussed earlier on Discord.

In setMatrix() and setMatrix3(), we previously stored the matrix values in a kha float32array just to then allocate a js float32array* view on the kha array on the fly for each function call, which in my tests in Firefox took about 25-30% of the time of setMatrix().

* required by the GL functions

The same problem still exists in setInts() and setFloats(), however, since the size of the user-provided array isn't known beforehand I didn't implement a pre-allocated "cache" in this case. It might make sense though to implement a dynamically-sizing one in the future. Sadly, it doesn't seem to be possible to replace the buffer of a js.lib.Float32Array (it's read only), so we can't just pre-allocate a view object that we dynamically point to the user-provided kha arrays.