Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[geometry] Consider using Typed Arrays for matrices and static transform operations #123

Open
esprehn opened this issue Mar 28, 2017 · 9 comments

Comments

@esprehn
Copy link

esprehn commented Mar 28, 2017

Existing code and WebGL represent matrices as a Typed Array, perhaps we should instead make the matrix operations be statics.

ex.

Float32Array = DOMMatrix.translate(Float32Array, Float32Array);

and the self() versions would modify one of matrices in place. This better matches the API surface available today and avoids having to indirect through DOMMatrix and then convert back into a Float32Array to use it with WebGL.

@bfgeek

@zcorpan
Copy link
Member

zcorpan commented Apr 4, 2017

This seems interesting but I think we should somehow keep compatibility with web content that uses WebKitCSSMatrix. That could be done by renaming DOMMatrix to WebKitCSSMatrix and specifying a new DOMMatrix that just has static operations for typed arrays... or we could add static operations to DOMMatrix as well.

DOMMatrix currently has fromFloat32Array() and fromFloat64Array() statics (and corresponding to* operations). In your proposal would it return a Float64Array if a Float64Array is passed in?

@zcorpan zcorpan changed the title Consider using Typed Arrays for matrices and static transform operations [geometry] Consider using Typed Arrays for matrices and static transform operations Apr 4, 2017
@chrishtr
Copy link
Contributor

chrishtr commented Apr 6, 2017

Another option is to make a new constructor to DOMMatrix that takes a Float64Array or Float32Array, and spec it to use that typed array as the backing store. e.g. multiplications in-place would update that array, the implementation would use it internally, and accessors like m11 etc would mutate that typed array.

It does seem to be the case that we could add support for typed array-backed methods in the future.

@foolip
Copy link
Member

foolip commented Apr 25, 2017

It'd probably be tedious (and slower) to have DOMMatrix use either a typed array of something else, so going this route, would it make sense to just say that DOMMatrix is backed by a Float64Array by default? Whether it was provided with the constructor or not, the backing array could then be exposed as an attribute on DOMMatrix. (But not on DOMMatrixReadOnly.)

@foolip
Copy link
Member

foolip commented Apr 25, 2017

That'd make DOMMatrix more like a wrapper around typed arrays, where the wrapper would probably require much more memory than the backing array itself. Static methods by the names name but with more arguments would still make sense I think.

@chrishtr
Copy link
Contributor

Specifying a backing of typed array and exposing as a property could be done, but that wouldn't solve
the problem of using a shared or pre-allocated backing. But I think this suggestion is backward-
compatible, so it could be added later.

@foolip
Copy link
Member

foolip commented Apr 27, 2017

We could of course leave DOMMatrix instances alone and have new static methods as the only way of working with typed arrays. I have no strong preferences.

@chrishtr
Copy link
Contributor

Right exactly. To me, the important point is that it could be added later.

@dirkschulze
Copy link
Contributor

The idea here was to have an easy and straight forward way to get values from DOM to WebGL and vice versa with fromFloat32Array and fromFloat64Array (now). IMO that is good enough for now.

@zcorpan
Copy link
Member

zcorpan commented Jun 5, 2017

Those methods create a copy though, so while it might be good enough for now, it's not optimal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants