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

Re: [Public WebGL] WebKitCSSMatrix and WebGL

On Jun 19, 2010, at 5:29 AM, stephen white wrote:

> Is there any current or future correlation between WebKitCSSMatrix and WebGL?
> > m = new WebKitCSSMatrix
> WebKitCSSMatrix
> > a = new WebGLFloatArray(m)
> WebGLFloatArray
> > a.length
> 0 // Doesn't work.
> It would also be interesting to see benchmarks if it works, as Chris likes to say. :)

I've made an implementation of a Matrix class which uses WebKitCSSMatrix if available:


with a test case here:


In doing some informal benchmarking, I'm not seeing significant speedup. I believe this is mainly due to the fact that CSSMatrix is immutable (i.e., it returns a new CSSMatrix from every call). This causes a lot of GC churn which affects performance. We made it immutable to match SVGMatrix, but in retrospect, that might have been a mistake. I'm looking now at possibly trying to change the CSSMatrix spec to mutate the passed matrix in place, or at least add methods that do mutation.

Interestingly, J3DIMatrix can also use a "copy" function. This is a method I experimentally added to CSSMatrix. You pass a Float32Array with space for at least 16 floats and the current matrix will be copied into it. This yielded an improvement of 30-40% over both the version that did matrix math in JS and the CSSMatrix version which picked values out of the matrix by hand. This tells me that CSSMatrix probably IS faster, but the GC overhead is eating all that extra performance. It also tells me that with a few small changes and additions, we can significantly improve matrix math in WebGL.

PS - In your example above, for instance, if you had the CSSMatrix.copy() function you would say:

	var a = WebGLFloatArray(16);

and 'a' will then have the matrix, all without any additional object creation.


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: