<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Vladimir Vukićević &#187; Canvas 3D</title>
	<atom:link href="http://blog.vlad1.com/category/mozilla/canvas-3d/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.vlad1.com</link>
	<description>Words</description>
	<lastBuildDate>Mon, 26 Jul 2010 21:05:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>EGL &amp; OpenGL ES Come to Windows</title>
		<link>http://blog.vlad1.com/2010/07/26/egl-opengl-es-come-to-windows/</link>
		<comments>http://blog.vlad1.com/2010/07/26/egl-opengl-es-come-to-windows/#comments</comments>
		<pubDate>Mon, 26 Jul 2010 21:05:48 +0000</pubDate>
		<dc:creator>vladimir</dc:creator>
				<category><![CDATA[Canvas 3D]]></category>
		<category><![CDATA[Mozilla]]></category>
		<category><![CDATA[amd]]></category>
		<category><![CDATA[drivers]]></category>
		<category><![CDATA[egl]]></category>
		<category><![CDATA[opengl]]></category>
		<category><![CDATA[webgl]]></category>

		<guid isPermaLink="false">http://blog.vlad1.com/?p=325</guid>
		<description><![CDATA[It&#8217;s SIGGRAPH time, and this means all sorts of interesting announcements in the graphics world. One of these came today from AMD, who announced that they plan on shipping both EGL and OpenGL ES drivers on Windows for their recent GPUs. One of the most challenging things in getting Firefox working with WebGL and hardware [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s SIGGRAPH time, and this means all sorts of interesting announcements in the graphics world.  One of these came today from AMD, who <a href="http://blogs.amd.com/developer/2010/07/26/opengl-es-2-0-coming-to-a-desktop-near-you/">announced that they plan on shipping</a> both <a href="http://www.khronos.org/egl/">EGL</a> and <a href="http://www.khronos.org/opengles/">OpenGL ES</a> drivers on Windows for their recent GPUs.</p>
<p>One of the most challenging things in getting Firefox working with WebGL and hardware graphics acceleration has been dealing with platform-specific pieces to get access to OpenGL.  In many cases similar functionality works differently (often in subtle ways), requiring both lots of testing and lots of very specific codepaths.  EGL replaces all of these with a modern system designed with portability in mind.  Until now, however, EGL has only been adopted in the mobile space.  On the desktop, the older GLX, CGL, and WGL subsystems have held this role; in the case of GLX and WGL in particular, they bring along years of accumulated cruft.  </p>
<p>Having a native EGL driver will allow us to ship one particular hardware acceleration provider that will work and be tested across various desktop and mobile platforms.  Additionally, the same provider can connect to the <a href="http://code.google.com/p/angleproject/">ANGLE project</a>, which implements EGL and OpenGL ES on top of Direct3D 9. Having OpenGL ES will allow us to test and develop truly identical code across desktop and mobile.  As mobile graphics development has become important (not just to Mozilla, but in general!), having the same API implemented on the desktop will make it easier to catch problems and portability issues in an environment that&#8217;s much more conducive to development and debugging.</p>
<p>Native OpenGL ES on the desktop will also mean that we can tie our <a href="http://webgl.org/">WebGL</a> implementation directly to it, instead of going through the desktop OpenGL driver.  Because WebGL follows the OpenGL ES specification, the native ES driver on the desktop will allow us to make a more efficient binding between WebGL and the underlying platform, potentially leading to higher performance.</p>
<p>As with any such change, it will be a while before we can depend on the presence of these APIs on the desktop.  These first steps are important to making that change happen.  I&#8217;m looking forward to seeing other vendors following AMD here, both on Windows and on other platforms.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.vlad1.com/2010/07/26/egl-opengl-es-come-to-windows/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How To Go Mad While Trying To Render To a Texture</title>
		<link>http://blog.vlad1.com/2010/07/01/how-to-go-mad-while-trying-to-render-to-a-texture/</link>
		<comments>http://blog.vlad1.com/2010/07/01/how-to-go-mad-while-trying-to-render-to-a-texture/#comments</comments>
		<pubDate>Thu, 01 Jul 2010 08:05:18 +0000</pubDate>
		<dc:creator>vladimir</dc:creator>
				<category><![CDATA[Canvas 3D]]></category>
		<category><![CDATA[Mozilla]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[egl]]></category>
		<category><![CDATA[opengl]]></category>
		<category><![CDATA[tears]]></category>
		<category><![CDATA[webgl]]></category>

		<guid isPermaLink="false">http://blog.vlad1.com/?p=309</guid>
		<description><![CDATA[Has that happened to you? No? It&#8217;s just me? Really? Huh. (Somewhat technical OpenGL post follows; you&#8217;ve been warned.) So over the past week, I&#8217;ve been trying to make our OpenGL stuff in Firefox be a little more coherent and easy to use, especially when it comes to doing things like rendering to a texture. [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: left;">Has that happened to you?  No?  It&#8217;s just me?  Really?  Huh.</p>
<p style="text-align: left;">(Somewhat technical OpenGL post follows; you&#8217;ve been warned.)</p>
<p style="text-align: left;">So over the past week, I&#8217;ve been trying to make our OpenGL stuff in Firefox be a little more coherent and easy to use, especially when it comes to doing things like rendering to a texture.  This is something really for WebGL, and is a key to making WebGL fast&#8230; we want it all to live in video hardware, and we want to render it straight from there, instead of doing the horrible readback that it does currently.</p>
<p style="text-align: left;">Our current implementation uses PBuffers for each WebGL context.  PBuffers are old and crufty, but they mostly work ok.  But, everyone kept telling me, &#8220;PBuffers are old and crufty!  FBOs are the new hotness!  Why do you hate unicorns?&#8221;  Problem is, WebGL really wants its own context &#8212; one of the advantages of FBOs over PBuffers is that they <em>don&#8217;t</em> need a separate context.  That&#8217;s great, if what you need is to render to a texture in your game or visualization app or whatever.  But, WebGL needs a context.</p>
<p style="text-align: left;">Ok, I thought, I can just use OpenGL&#8217;s (technically, WGL, EGL, GLX, and CGL&#8217;s) context sharing feature, have everything live in one shared global namespace, and things will just work.  This has one somewhat scary problem &#8212; if you don&#8217;t clean up any resources, they stick around forever, or at least until all the contexts in the sharing group are gone.  But, I figured we can keep track and clean up.</p>
<p style="text-align: left;">So I did all this work, set up a global context to use as a &#8220;shared&#8221; context.  Everything worked great, creating a FBO is certainly easier than creating a PBuffer and all that.</p>
<p style="text-align: left;">And then I decided to test it on Android.  One of the reasons why I wanted to do this was that on a number of mobile devices, among them Nokia&#8217;s N900 and Nvidia&#8217;s Android port, PBuffers cannot be bound as a texture; they just don&#8217;t support that.  The shared-context FBO approach worked great.  Then I plugged in a Nexus One.  Failure.</p>
<p style="text-align: left;">What gives?  It turns out, a bunch of current Android devices simply <em>don&#8217;t support GL context sharing</em>.  My plan?  Ruined.  The full table of tears actually looks like this:</p>
<table style="background-color: #ccffff; text-align: left; width: 80%;" border="0" cellpadding="5" align="center">
<thead>
<tr>
<td style="text-align: center;"><strong>Target</strong></td>
<td align="center"><strong>PBuffers</strong></td>
<td style="text-align: center;"><strong>Sharing</strong></td>
<td style="text-align: center;"><strong>Other</strong></td>
</tr>
</thead>
<tbody>
<tr>
<td>Desktop &#8211; WGL</td>
<td style="text-align: center;">YES</td>
<td style="text-align: center;">YES</td>
<td></td>
</tr>
<tr>
<td>Desktop &#8211; GLX</td>
<td style="text-align: center;">no</td>
<td style="text-align: center;">YES</td>
<td style="text-align: center;">YES</td>
</tr>
<tr>
<td>Desktop &#8211; CGL</td>
<td style="text-align: center;">YES</td>
<td style="text-align: center;">YES</td>
<td style="text-align: center;">YES</td>
</tr>
<tr>
<td>Maemo (N900 + others)</td>
<td style="text-align: center;">no</td>
<td style="text-align: center;">YES</td>
<td style="text-align: center;">YES</td>
</tr>
<tr>
<td>Android &#8211; Tegra</td>
<td style="text-align: center;">no</td>
<td style="text-align: center;">YES</td>
<td style="text-align: center;">YES</td>
</tr>
<tr>
<td>Android &#8211; Nexus One</td>
<td style="text-align: center;">YES*</td>
<td style="text-align: center;">no</td>
<td></td>
</tr>
<tr>
<td>Android &#8211; Droid</td>
<td style="text-align: center;">YES*</td>
<td style="text-align: center;">no</td>
<td></td>
</tr>
<tr>
<td>Android &#8211; EVO4G</td>
<td style="text-align: center;">YES*</td>
<td style="text-align: center;">no</td>
<td></td>
</tr>
</tbody>
</table>
<p style="text-align: left;">The &#8220;Other&#8221; category means that the platform has an alternate approach that doesn&#8217;t involve either PBuffers or context sharing. These other approaches are:</p>
<p style="text-align: left;">Desktop &#8211; GLX: X11 Pixmaps can be rendered to and used as textures via texture_from_pixmap</p>
<p style="text-align: left;">Desktop &#8211; CGL: I think there&#8217;s some CoreAnimation thing that can be used here?</p>
<p style="text-align: left;">Maemo: X11 Pixmaps, as on GLX; potentially EGL_KHR_gl_texture_2D_image</p>
<p style="text-align: left;">Android &#8211; Tegra: EGL_KHR_gl_texture_2D_image, which allows a texture to be exported as an EGLImage.  This is ideal, since it gives all the benefit of FBOs without any of the downsides of context sharing.  Unfortunately, this is the only place where it&#8217;s supported, and as best I can tell nothing like this exists on the desktop.</p>
<p style="text-align: left;">The * next to some of the Android entries indicates that while they do support pbuffers, they only support power-of-two dimensions, at least for pbuffers that can be bound as textures.  This is annoying and caused me a bunch of grief until I realized that quirk.</p>
<p style="text-align: left;">So, with that information, the new plan is to attempt to share all window contexts&#8217; resources &#8212; there are advantages here in cleanup operations and being able to do texture uploads and other things on different threads.  For WebGL and other offscreen contexts though, we want to avoid sharing if we can, so the order in which we&#8217;ll try things goes like this:</p>
<ol>
<li>EGL_KHR_texture_2d_image + GL_OES_EGL_image.  Even though it&#8217;s only supported on one target, I still want to make sure that we use this where we can &#8212; it really is exactly what we want.</li>
<li>PBuffers.  Yes, they may be old and busted and difficult to create and all that, but if supported, they still do basically exactly what&#8217;s needed.</li>
<li>X11 Pixmaps + texture_from_pixmap.  Basically like PBuffers, but even more annoying and actually supported on X11.</li>
<li>Dummy window or other drawable and a FBO, plus full sharing with the windowed contexts.  This is only possible if sharing is possible, and is a little risky from a resource management perspective, but it works.</li>
<li>Can&#8217;t share, can&#8217;t texture from any renderable target?  Then we call glReadPixels and take the slow boat through system memory.</li>
</ol>
<p>So, where I was hoping to just write one path &#8212; #4 in the list above &#8212; I now have to write 5.  On the plus side, 1-3 all don&#8217;t have the sharing problem.  On the minus side, it&#8217;s 5 separate code paths instead of just 1.</p>
<p>Hopefully the above information saves someone some pain while trying to do offscreen GL rendering on various platforms, especially mobile ones.  I wish the Android EGL implementations were higher quality; the non-Nvidia ones seem to support an identical set of extensions and report identical version strings, which makes me wonder if they&#8217;re just based on some generic code that Google provides.  If so, it would be nice to see that updated with support for texture_2d_image/EGL_image.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.vlad1.com/2010/07/01/how-to-go-mad-while-trying-to-render-to-a-texture/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>mjs: Simple Vector and Matrix Math for JS</title>
		<link>http://blog.vlad1.com/2010/02/05/mjs-simple-vector-and-matrix-math-for-js/</link>
		<comments>http://blog.vlad1.com/2010/02/05/mjs-simple-vector-and-matrix-math-for-js/#comments</comments>
		<pubDate>Fri, 05 Feb 2010 09:04:19 +0000</pubDate>
		<dc:creator>vladimir</dc:creator>
				<category><![CDATA[Canvas 3D]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[Mozilla]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[math]]></category>
		<category><![CDATA[spidermonkey]]></category>
		<category><![CDATA[webgl]]></category>

		<guid isPermaLink="false">http://blog.vlad1.com/?p=253</guid>
		<description><![CDATA[One common thread running through the many different and interesting WebGL projects out there is that they all need to do vector and matrix math, do it quickly, and do it in JavaScript.  To date, developers have either rolled their own, or they&#8217;ve used Sylvester, a fairly featureful vector and matrix JavaScript library. One of [...]]]></description>
			<content:encoded><![CDATA[<p>One common thread running through the <a href="http://learningwebgl.com/blog/">many</a> <a href="http://www.c3dl.org/">different</a> and <a href="http://www.glge.org/">interesting</a> <a href="http://www.webgl.org/">WebGL</a> <a href="http://www.x3dom.org/">projects</a> out there is that they all need to do vector and matrix math, do it quickly, and do it in JavaScript.  To date, developers have either rolled their own, or they&#8217;ve used <a href="http://sylvester.jcoglan.com/">Sylvester</a>, a fairly featureful vector and matrix JavaScript library.</p>
<p>One of the problems with Sylvester is that while it&#8217;s fully featured (arbitrary NxN matrices and vectors can be created and manipulated), it suffers in performance because of it.  Since this is such a crucial part of a successful WebGL program, I&#8217;ve put together a small package that I&#8217;m calling <strong>mjs</strong>.</p>
<p><strong>mjs</strong> is designed around speed and simplicity.  For example, it doesn&#8217;t attempt to stuff vectors and matrices into JavaScript objects.  Because the language offers no operator overloading, there&#8217;s very little benefit in treating these types as discrete objects, and lots of performance and memory usage downsides.  Instead, it provides a set of functions for performing operations on vectors and matrices, which can be any array-like object.  For any function that returns a vector or matrix, an existing array can be passed in to take the result, or the function can create a new one.  Array reuse ends up being important because of the potential for expensive garbage collection churn eating away at performance.</p>
<p>Here&#8217;s a sample of the API:</p>
<pre>var r = M4x4.rotate(Math.PI/2, V3.$(0, 1, 0),  M4x4.I);</pre>
<p>Note that V3.$ and M4x4.$ are shorthand for creating a new V3 or M4x4 (I wanted to use V3() and M4x4(), but that didn&#8217;t work out too well since functions have a length property).  However, because all they return are just new array-like objects, you could also write:</p>
<pre>var r = M4x4.rotate(Math.PI/2, [0, 1, 0], M4x4.I);</pre>
<p>If the WebGL types are available, those will be used for newly created vectors/matrices.  They are a significant performance boost especially for repeated operations; but for specifying one-off vectors such as the above, literal array syntax is fine.</p>
<p>The rotate function internally makes a rotation matrix, and then multiplies it by the given matrix.  So the above could also be written as:</p>
<pre>var rotation = M4x4.makeRotate(Math.PI/2, [0, 1, 0]);
var r = M4x4.mul(M4x4.I, rotation);</pre>
<p>(The last line being redundant given that we&#8217;re multiplying by the identity matrix.)</p>
<p>All methods that return a vector or matrix take an optional final argument, that of an existing object to reuse.  For example:</p>
<pre>var m0 = M4x4.$();
r = M4x4.mul(someMatrixA, someMatrixB, m0);
// r == m0, so the assignment isn't necessary, but it's handy for chaining
// .... do something with r ...
r = M4x4.mul(someMatrixB, someMatrixC, m0);
// r == m0 still
// ... do something else with new results ...</pre>
<p>Without allocating any additional temporary objects.</p>
<p>As mentioned before, one of the goals of <strong>mjs</strong> is performance.  Matrix multiplication is one of the most common tasks, so here are some numbers comparing <strong>mjs</strong>, Sylvester, and native C code.  This was run on a Core i7 desktop using a local build of Spidermonkey, which included one patch that&#8217;s about to go into the tree that fixes the no-reuse tracing case.  (Without it, the no-reuse tracing case is much larger because it&#8217;s never actually jitted.)  The test is simple: it multiplies two matrices together in a loop 1,000,000 times.</p>
<table>
<tr>
<th>Test</th>
<th>Time</th>
</tr>
<tr>
<td>mjs, JIT, matrix reuse</td>
<td align="right">140ms</td>
</tr>
<tr>
<td>mjs, JIT, no reuse</td>
<td align="right">533ms</td>
</tr>
<tr>
<td>Sylvester, JIT, no reuse</td>
<td align="right">5,280ms</td>
</tr>
<tr>
<td>mjs, no JIT, matrix reuse</td>
<td align="right">25,833ms</td>
</tr>
<tr>
<td>mjs, no JIT, no reuse</td>
<td align="right">26,681ms</td>
</tr>
<tr>
<td>Sylvester, no JIT, no reuse</td>
<td align="right">41,996ms</td>
</tr>
<tr>
<td>Native C++, SSE2, matrix reuse</td>
<td align="right">71ms</td>
</tr>
<tr>
<td>Native C++, SSE2, no reuse</td>
<td align="right">142ms</td>
</tr>
</table>
<p>(I also have numbers for MSVC without the SSE2 compile flag, but the numbers vary greatly depending on whether the values eventually go to infinity or not; if the values end up trending towards 0, the non-SSE2 code tends to win at around 52ms vs. 71ms; if the values trend to infinity, the non-SSE2 code takes around 11,000ms!)</p>
<p>Those numbers are pretty encouraging &#8212; having native code be only 2x as slow for something like this is pretty nice to see.  Granted, this is only a very isolated test, and I&#8217;m sure there are some tricks to optimizing the native code case (it&#8217;s currently just a fully unrolled set of multiplies and adds).  The &#8220;no JIT&#8221; case is less nice, but I&#8217;m sure that our Jaegermonkey folks will be all over this testcase (right, guys?).  In any case, ideally most WebGL rendering loops will be fully traced in Firefox, so it would be less of an issue.</p>
<p><strong>mjs</strong> is still very much a work in progress; it&#8217;s missing a test suite and a whole bunch of features.  You can find it hosted at Google Code, at <a href="http://webgl-mjs.googlecode.com/">webgl-mjs</a>.  (Side note: I couldn&#8217;t just call the project mjs because a project called mjs was abandoned on Sourceforget 5 years ago, and Google Code complained.)  There&#8217;s also some documentation, <a href="http://webgl-mjs.googlecode.com/hg/docs/files/mjs-js.html">viewable online here</a>.</p>
<p>Bugs and contributions welcome!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.vlad1.com/2010/02/05/mjs-simple-vector-and-matrix-math-for-js/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>WebGL Draft Goes Public</title>
		<link>http://blog.vlad1.com/2009/12/10/webgl-draft-goes-public/</link>
		<comments>http://blog.vlad1.com/2009/12/10/webgl-draft-goes-public/#comments</comments>
		<pubDate>Thu, 10 Dec 2009 22:10:17 +0000</pubDate>
		<dc:creator>vladimir</dc:creator>
				<category><![CDATA[Canvas 3D]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[Mozilla]]></category>
		<category><![CDATA[canvas3d]]></category>
		<category><![CDATA[khronos]]></category>
		<category><![CDATA[webgl]]></category>

		<guid isPermaLink="false">http://blog.vlad1.com/?p=240</guid>
		<description><![CDATA[I&#8217;m pretty excited to have the WebGL draft spec available for review and comments today.  There&#8217;s still plenty of time for feedback, but we&#8217;re far enough along to be able to solicit meaningful feedback.  There are multiple implementations, which is a much better state than the early Canvas 3D work where things only worked during [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.khronos.org/webgl/"><img class="alignleft size-full wp-image-241" style="border: none;" title="WebGL" src="http://blog.vlad1.com/wp-content/uploads/2009/12/webgl_200px.gif" alt="WebGL" width="163" height="75" /></a>I&#8217;m pretty excited to have the WebGL draft spec available for review and comments today.  There&#8217;s still plenty of time for feedback, but we&#8217;re far enough along to be able to solicit meaningful feedback.  There are multiple implementations, which is a much better state than the early Canvas 3D work where things only worked during a full moon after saying &#8220;OpenGL&#8221; three times backwards into your monitor!</p>
<p>We&#8217;re actively working through remaining warts and edge cases (and they are a lot of them!).  Take a look at the official <a href="http://www.khronos.org/webgl/">Khronos WebGL landing page</a> and <a href="http://hacks.mozilla.org/2009/12/webgl-draft-released-today/">Arun&#8217;s blog post</a> for more information, including where to go to sign up for the public mailing list and for a set of resources about WebGL.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.vlad1.com/2009/12/10/webgl-draft-goes-public/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Heads Up: WebGL Canvas*Array renamed to WebGL*Array</title>
		<link>http://blog.vlad1.com/2009/12/02/heads-up-webgl-canvasarray-renamed-to-webglarray/</link>
		<comments>http://blog.vlad1.com/2009/12/02/heads-up-webgl-canvasarray-renamed-to-webglarray/#comments</comments>
		<pubDate>Wed, 02 Dec 2009 21:48:19 +0000</pubDate>
		<dc:creator>vladimir</dc:creator>
				<category><![CDATA[Canvas 3D]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[Mozilla]]></category>

		<guid isPermaLink="false">http://blog.vlad1.com/?p=237</guid>
		<description><![CDATA[I just checked in a patch from Mark that renames WebGL&#8217;s Canvas*Array objects to be WebGL*Array, to match the current state of the spec.  The APIs remain the same, so it should be a matter of search-and-replace to update.  Should show up in tomorrow&#8217;s nightly builds of Firefox.]]></description>
			<content:encoded><![CDATA[<p>I just checked in a patch from Mark that renames WebGL&#8217;s <a href="http://blog.vlad1.com/2009/11/06/canvasarraybuffer-and-canvasarray/">Canvas*Array objects</a> to be WebGL*Array, to match the current state of the spec.  The APIs remain the same, so it should be a matter of search-and-replace to update.  Should show up in tomorrow&#8217;s nightly builds of Firefox.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.vlad1.com/2009/12/02/heads-up-webgl-canvasarray-renamed-to-webglarray/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WebGL Goes Mobile</title>
		<link>http://blog.vlad1.com/2009/12/01/webgl-goes-mobile/</link>
		<comments>http://blog.vlad1.com/2009/12/01/webgl-goes-mobile/#comments</comments>
		<pubDate>Tue, 01 Dec 2009 18:29:52 +0000</pubDate>
		<dc:creator>vladimir</dc:creator>
				<category><![CDATA[Canvas 3D]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[Mozilla]]></category>

		<guid isPermaLink="false">http://blog.vlad1.com/?p=209</guid>
		<description><![CDATA[One of the goals of WebGL was always to enable the functionality on both desktop and mobile devices.  This is one of the reasons why OpenGL ES 2.0 was chosen as a starting point for the capabilities exposed by the spec. We&#8217;ve had support for WebGL in Firefox desktop nightlies for a few weeks now, [...]]]></description>
			<content:encoded><![CDATA[<p>One of the goals of <a href="http://en.wikipedia.org/wiki/WebGL">WebGL</a> was always to enable the functionality on both desktop and mobile devices.  This is one of the reasons why OpenGL ES 2.0 was chosen as a starting point for the capabilities exposed by the spec.</p>
<p>We&#8217;ve had support for WebGL in Firefox desktop nightlies for a few weeks now, but soon I hope to have it enabled on Firefox for mobile devices (code name Fennec) as well.  Jay demonstrated some simple demos working on <a href="http://maemo.nokia.com/n900/">Nokia&#8217;s N900</a> at the ARM techcon3 <span style="text-decoration: line-through;">today</span> a few weeks ago (took a while to get the video done!), and I&#8217;ve grabbed a quick video showing things in action.</p>
<p style="text-align: center;"><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="580" height="360" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/Ly65aWGZn1w&amp;hl=en_US&amp;fs=1" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="580" height="360" src="http://www.youtube.com/v/Ly65aWGZn1w&amp;hl=en_US&amp;fs=1" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p style="text-align: left;">This should be showing up in Firefox for mobile devices nightly builds, so we&#8217;ll see some more interesting things running on phones soon!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.vlad1.com/2009/12/01/webgl-goes-mobile/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>CanvasArrayBuffer and Canvas*Array</title>
		<link>http://blog.vlad1.com/2009/11/06/canvasarraybuffer-and-canvasarray/</link>
		<comments>http://blog.vlad1.com/2009/11/06/canvasarraybuffer-and-canvasarray/#comments</comments>
		<pubDate>Sat, 07 Nov 2009 00:30:18 +0000</pubDate>
		<dc:creator>vladimir</dc:creator>
				<category><![CDATA[Canvas 3D]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[Mozilla]]></category>
		<category><![CDATA[webgl]]></category>

		<guid isPermaLink="false">http://blog.vlad1.com/?p=213</guid>
		<description><![CDATA[WebGL introduces two interesting concepts that I think have application outside of WebGL, the CanvasArrayBuffer and CanvasArray WebGLArrayBuffer and WebGLArray. This is all subject to change, of course, though this is what the current Gecko (and others&#8217;) implementation looks like. In particular, the Canvas prefix in the names might change soon. Edit 12/2: these types [...]]]></description>
			<content:encoded><![CDATA[<p>WebGL introduces two interesting concepts that I think have application outside of WebGL, the <span style="text-decoration: line-through;">CanvasArrayBuffer and CanvasArray</span> WebGLArrayBuffer and WebGLArray.  This is all subject to change, of course, though this is what the current Gecko (and others&#8217;) implementation looks like.  In particular, the Canvas prefix in the names might change soon.</p>
<p><strong>Edit 12/2:  these types have changed names; they now have a WebGL prefix instead of a Canvas prefix.</strong></p>
<p>It became clear that pure JS arrays are not a useful way of shoveling around lots of 3D data; their very flexibility makes them impractical for performance-critical uses.  In particular, WebGL often wants to deal with arrays of a specific type &#8212; an array of integers, an array of floats, etc.  Even more complicated is the need to manage multiple types within a single memory region; for performance, it&#8217;s often preferable to allocate one chunk of video memory, and place coordinates, colors, and other types in there, replacing them as necessary.</p>
<p>There are two portions to the solution: the WebGLArrayBuffer and a set of typed WebGLArray views.  A WebGLArrayBuffer represents chunk of data.  It can be allocated with a size in bytes, but it can&#8217;t be accessed in any way.  To actually manipulate the data inside a WebGLArrayBuffer, a WebGLArray has to be created that references it.  An example:</p>
<pre>var buf = new WebGLArrayBuffer(3*4);
var floats = new WebGLFloatArray(buf);
floats[0] = 12.3;
floats[1] = 23.4;
floats[2] = 34.5;</pre>
<p>The above chunk of code allocates a 12-byte WebGLArrayBuffer, and then creates a float-typed view onto the buffer which can then be manipulated (almost) like a normal array.  Of course, the above is cumbersome to write, so there are shorthands that will allocate a WebGLArrayBuffer, and optionally fill it with data from a JS array:</p>
<pre>var f1 = new WebGLFloatArray(3);
var f2 = new WebGLFloatArray([12.3, 23.4, 34.5]);</pre>
<p>The size of each WebGLArrayBuffer is fixed; there is currently no way to change its size once allocated.</p>
<p>Multiple WebGLArrays can reference the same WebGLArrayBuffer.  For example:</p>
<pre>var buf = new WebGLArrayBuffer(12*3*4+12*4);
var points = new WebGLFloatArray(buf, 0, 12*3);
var colors = new WebGLUnsignedByteArray(buf, 12*3*4, 12*4);</pre>
<p>This creates a buffer of 192 bytes, which is enough room for 12 3-coordinate float points followed by 12 RGBA colors, with each component represented as an unsigned byte.  The arguments to the WebGLArray constructors are the offset from the start of the buffer (in bytes), and the length (in elements).  The offset must always be a multiple of the element size (to preserve alignment), and the buffer must obviously be large enough for the given offset and length.  If length is not given, the length is assumed to be &#8220;from offset until the end of the array buffer&#8221;; that value must be a multiple of the element size.  If offset is not given, it&#8217;s assumed to be zero.</p>
<p>For extra complex use cases, WebGLArrays can reference overlapping regions of a WebGLArrayBuffer:</p>
<pre>var buf = new WebGLArrayBuffer(192); // same value from above
var points = new WebGLFloatArray(buf);
var colors = new WebGLUnsignedByteArray(buf);
points[0] = 12.3;
points[1] = 23.4;
points[2] = 34.5;
colors[12] = 0xff;
colors[13] = 0xaa;
colors[14] = 0x00;
colors[15] = 0x00;</pre>
<p>In the buffer, this writes 3 float values followed by 4 byte values.  You&#8217;ll note that this use is significantly more complex, and requires the user to keep track of the current position in terms of whatever element they&#8217;re modifying (thus setting array elements 12, 13, 14, and 15 for the color).</p>
<p>If an attempt is made to store data in a WebGLArray that doesn&#8217;t fit within the right type, a C-style cast is performed.  If the data is an entirely wrong type (e.g. trying to store a string or an object), Gecko currently throws an exception, but this might become a silent 0 or similar in the future.</p>
<p>Where does this fit in WebGL?  Any API function that needs an array of data takes a WebGLArrayBuffer.  This avoids placing costly JS array type conversion in a potential critical performance path, and simplifies a number of aspects of the API.  So, VBOs, texture data (if not loaded from a DOM image element or from a CanvasImageData object), index array, etc. all use WebGLArrayBuffers/WebGLArrays for pulling data in and out.  WebGLArrays also help manage memory usage &#8212; an array of byte color data now takes up exactly as much memory as needed, instead of getting expanded out to 4 bytes.  Also, critically, floating point data can be stored as 32-bit single-precision floats instead of 64-bit doubles, taking up half as much space when the underlying graphics system can&#8217;t support 64-bit values.</p>
<p>This API is overall lacking in developer niceties, since the focus was on providing the necessary functionality.  Higher level wrappers can be written in JS to simplify usage.  In addition, by keeping it as bare-bones as it is, it allows for fast implementation on native hardware via the JITs in all the current-generation JS engines.  The web currently fudges around the problem of binary data by passing it around either in strings (because JS strings are UCS2, therefore all 8-bit elements are valid, but with a performance and memeory cost), or often encoding as base64 (again going back to strings).  I can see this type of dense/native type access being useful for both  the File and WebSockets APIs as a way to exchange and deal with binary  data.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.vlad1.com/2009/11/06/canvasarraybuffer-and-canvasarray/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>WebGL Samples/Demos and other bits</title>
		<link>http://blog.vlad1.com/2009/09/21/webgl-samples/</link>
		<comments>http://blog.vlad1.com/2009/09/21/webgl-samples/#comments</comments>
		<pubDate>Mon, 21 Sep 2009 21:26:28 +0000</pubDate>
		<dc:creator>vladimir</dc:creator>
				<category><![CDATA[Canvas 3D]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[Mozilla]]></category>

		<guid isPermaLink="false">http://blog.vlad1.com/?p=198</guid>
		<description><![CDATA[Since my post on Friday, we landed a few fixes to improve our WebGL implementation and to fix a couple of bugs we discovered on Friday.  I&#8217;m looking forward to seeing what people do with WebGL, and how it can be useful on the web right now.  For example, EA/Maxis recently added COLLADA export of [...]]]></description>
			<content:encoded><![CDATA[<p>Since <a href="http://blog.vlad1.com/2009/09/18/webgl-in-firefox-nightly-builds/">my post on Friday</a>, we landed a few fixes to improve our WebGL implementation and to fix a couple of bugs we discovered on Friday.  I&#8217;m looking forward to seeing what people do with WebGL, and how it can be useful on the web right now.  For example, EA/Maxis recently added COLLADA export of Creature designs to their popular game <a href="http://www.spore.com/">Spore</a>, and they have a <a href="http://www.spore.com/sporepedia">Sporepedia</a> where players can see others&#8217; creations.  Right now, those previews are just as images.  With WebGL, they could be fully 3D, even animated.</p>
<p><a href="http://blog.vlad1.com/wp-content/uploads/2009/09/spdemo.png"><img class="alignleft size-full wp-image-201" title="Spore Creature View (thumbnail)" src="http://blog.vlad1.com/wp-content/uploads/2009/09/spdemo-thumb.jpg" alt="Spore Creature View (thumbnail)" width="306" height="288" /></a>Over the weekend I&#8217;ve put together <a href="http://people.mozilla.com/~vladimir/webgl/spore/sporeview.html">this example</a>, which uses WebGL to render an exported Spore creature, and let the user rotate the 3D model to view it from different angles.  For those who want to try it out, you&#8217;ll need a recent Firefox nightly (one from today, September 21, or newer), and with one preference flipped as described in <a href="http://blog.vlad1.com/2009/09/18/webgl-in-firefox-nightly-builds/">this post</a>.</p>
<p>I&#8217;ll be working to update the very basic &#8220;<a href="http://people.mozilla.com/~vladimir/canvas3d/examples/gles2book/">getting started</a>&#8221; demos from the GL ES 2 book that I ported to Canvas 3D as well, so that those who are interested in experimenting can have some good basic code to look at.  They&#8217;re not updated yet, but they should be in the next day or two.</p>
<p>For those of you on Windows who don&#8217;t have an up to date OpenGL driver, or don&#8217;t have the possibility of getting one (e.g. many common Intel graphics cards doesn&#8217;t have OpenGL drivers), you can enable software rendering by downloading a Windows build of the Mesa software OpenGL implementation.  It won&#8217;t be fast, but it should be enough for you to get an idea of what&#8217;s going on, and to play with some of the demos.  To use it, download <a href="http://people.mozilla.com/~vladimir/webgl/webgl-mesa-751.zip">webgl-mesa-751.zip</a> and extract it somewhere on your computer.  It has a single file, OSMESA32.DLL, that you need to tell Firefox where to find:  open up about:config, and set the preference <em>webgl.osmesalib</em> to the path of OSMESA32.DLL.  If you extracted it to &#8220;C:\temp&#8221;, you would put in &#8220;C:\temp\osmesa32.dll&#8221; in the pref.  Then, flip <em>webgl.software_rendering</em> to true, and you should be good to go.</p>
<p>(Mac OS X users shouldn&#8217;t need to bother with software rendering, since Apple already provides a high quality OpenGL implementation, and Linux users should be ok as long as they have recent OpenGL drivers installed.)</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.vlad1.com/2009/09/21/webgl-samples/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>WebGL in Firefox Nightly Builds</title>
		<link>http://blog.vlad1.com/2009/09/18/webgl-in-firefox-nightly-builds/</link>
		<comments>http://blog.vlad1.com/2009/09/18/webgl-in-firefox-nightly-builds/#comments</comments>
		<pubDate>Fri, 18 Sep 2009 18:12:29 +0000</pubDate>
		<dc:creator>vladimir</dc:creator>
				<category><![CDATA[Canvas 3D]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[Mozilla]]></category>

		<guid isPermaLink="false">http://blog.vlad1.com/?p=189</guid>
		<description><![CDATA[Last night, I checked in some more work from Mark Steele (who&#8217;s focusing on the Firefox WebGL implementation), and along with that, enabled WebGL in trunk nightlies.  (Finally!) If you&#8217;re not familiar with WebGL, it&#8217;s the evolution of work that Mozilla started a few years ago with experiments called Canvas 3D &#8212; essentially a way [...]]]></description>
			<content:encoded><![CDATA[<p>Last night, I checked in some more work from Mark Steele (who&#8217;s <a href="http://readysetstop.blogspot.com/2009/08/keeping-up-with-khronos.html">focusing on the Firefox WebGL implementation</a>), and along with that, enabled WebGL in trunk nightlies.  (<em>Finally!</em>)</p>
<p>If you&#8217;re not familiar with WebGL, it&#8217;s the evolution of work that Mozilla started <a href="http://blog.vlad1.com/2007/11/26/canvas-3d-gl-power-web-style/">a few years ago</a> with experiments called Canvas 3D &#8212; essentially a way of accessing OpenGL from within the browser, through the HTML5 canvas tag.  Earlier this year, we <a href="http://www.khronos.org/news/press/releases/khronos-launches-initiative-for-free-standard-for-accelerated-3d-on-web/">started a standardization effort</a> within the <a href="http://www.khronos.org/">Khronos Group</a> which oversees <a href="http://www.opengl.org/">OpenGL</a>, and have made very rapid progress.</p>
<p>Along with the Firefox implementation, a WebGL implementation landed in WebKit fairly recently.  All of these implementations are going to have some interoperability issues for the next little while, as the spec is still in flux and we&#8217;re tracking it at different rates, but will hopefully start to stabilize over the next few months.</p>
<p>If you&#8217;d like to experiment with WebGL with a <a href="http://ftp.mozilla.org/pub/mozilla.org/firefox/nightly/latest-trunk/">trunk nightly build</a> (starting from Friday, September 18th), all you have to do is flip a pref: load about:config, search for &#8220;<strong>webgl</strong>&#8220;, and double-click &#8220;<strong>webgl.enabled_for_all_sites</strong>&#8221; to change the value from <strong><em>false </em></strong>to <strong><em>true</em></strong>.  You&#8217;ll currently have the most luck on MacOS X machines or Windows machines with up-to-date OpenGL drivers.</p>
<p>We still have some ways to go, as there are issues in shader security  and portability, not to mention figuring out what to do on platforms  where OpenGL is not available.  (The latter is an interesting problem;  we&#8217;re trying to ensure that the API can be implementable on top of a  non-GL native 3D API, such as Direct3D, so that might be one option.)  But progress is being quickly made.</p>
<p>When paired with high-performance JavaScript, such as what we&#8217;ve seen come from both Firefox and other browsers, should allow for some exciting fully 3D-enabled web applications.  We&#8217;ll have some simple demos linked for you soon, both here and on Mark&#8217;s blog.</p>
<p>Edit: <a href="http://blog.vlad1.com/2009/09/21/webgl-samples/">new post up</a>, with some samples!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.vlad1.com/2009/09/18/webgl-in-firefox-nightly-builds/feed/</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
		<item>
		<title>Canvas 3D Extension Update</title>
		<link>http://blog.vlad1.com/2009/03/28/canvas-3d-extension-update-2/</link>
		<comments>http://blog.vlad1.com/2009/03/28/canvas-3d-extension-update-2/#comments</comments>
		<pubDate>Sat, 28 Mar 2009 18:36:26 +0000</pubDate>
		<dc:creator>vladimir</dc:creator>
				<category><![CDATA[Canvas 3D]]></category>
		<category><![CDATA[Mozilla]]></category>
		<category><![CDATA[canvas]]></category>
		<category><![CDATA[canvas3d]]></category>
		<category><![CDATA[opengl]]></category>

		<guid isPermaLink="false">http://blog.vlad1.com/?p=119</guid>
		<description><![CDATA[An updated version of the prototype Canvas 3D extension is finally available, with a good number of improvements.  Many of these came from Ilmari Heikkinen, who&#8217;s done some great work in fixing bugs and plugging holes/errors in the implementation.  Also, with this release, support for the OpenGL ES 1.1-based context has been dropped, in order [...]]]></description>
			<content:encoded><![CDATA[<p>An updated version of the prototype Canvas 3D extension is finally available, with a good number of improvements.  Many of these came from <a href="http://fhtr.blogspot.com/">Ilmari Heikkinen</a>, who&#8217;s done some great work in fixing bugs and plugging holes/errors in the implementation.  Also, with this release, support for the OpenGL ES 1.1-based context has been dropped, in order to focus on the more forward-looking ES 2.0-based work.  You can <a href="https://people.mozilla.com/~vladimir/canvas3d/">download the new release (0.4.2) here</a>.</p>
<p>There are a few changes in this version from the <a href="http://blog.vlad1.com/canvas-3d/">API mapping and description I posted earlier</a>.  One of the things I mentioned in that original post was changing some functions to try to make them more palatable to JS.  However, no matter how much you munge the GL API, it&#8217;s still a low-level API.  So, with this version, a bunch of helpers went away, such as <em>uniformf</em>, <em>uniformi</em>, <em>uniformMatrix</em>,<em> </em>and <em>vertexAttrib</em>.  They added significant complexity on the native side, and just confused matters for those who are already familiar with the OpenGL family of APIs.  Instead of those helpers, the GL-like <em>uniform[1234][if][v]</em> and similar should be used.  This doesn&#8217;t prevent a convenience wrapper from being made, but it should be done on the JS side, not hardcoded into the native implementation.  Additionally, some arguments to functions such as <em>vertexAttribPointer</em> were originally omitted; those are back, and follow the GL prototype.  There are, however, still some changes, particularly in getter functions — the full mapping list is available on the <a href="http://people.mozilla.com/~vladimir/canvas3d/docs/glweb20binding.html">API mapping page</a>.</p>
<p>This release of the extension also adds support for software rendering, using the Mesa GL library.  Software rendering shims are included for all 3 platforms, though only for the 32-bit Intel variants (which is why the extension download is bigger than previous versions).  Software rendering should be used automatically if hardware rendering can&#8217;t be (due to lack of OpenGL or lack of specific extensions), but you can also set the <em>extensions.canvas3d.software_render</em> pref to<em> true</em> in about:config to force it.  Also, if the version of OSMesa included isn&#8217;t being found, or if you&#8217;d like to try a different OSMesa renderer, <em>extensions.canvas3d.osmesalib</em> can be set to the full path of the library to load.  Note that the functions are assumed to be prefixed with &#8220;mgl&#8221; as opposed to &#8220;gl&#8221; when loading this library.</p>
<p>I also went ahead and ported most of the native code examples from the <a href="http://opengles-book.com/">OpenGL ES 2.0 Programming Guide</a>.  These are really API examples, and are not intended to demonstrate what can be done with OpenGL support in the browser.  You can view them here:</p>
<ul>
<li><a href="http://people.mozilla.com/~vladimir/canvas3d/examples/gles2book/ch2-hello-triangle.html">Chapter 2, Hello Triangle</a></li>
<li><a href="http://people.mozilla.com/~vladimir/canvas3d/examples/gles2book/ch8-simple-vertexshader.html">Chapter 8, Simple Vertex Shader</a></li>
<li><a href="http://people.mozilla.com/~vladimir/canvas3d/examples/gles2book/ch9-simple-texture2d.html">Chapter 9, Simple 2D Texture</a></li>
<li><a href="http://people.mozilla.com/~vladimir/canvas3d/examples/gles2book/ch9-simple-texture-cubemap.html">Chapter 9, Simple Cubemap Texture</a></li>
<li><a href="http://people.mozilla.com/~vladimir/canvas3d/examples/gles2book/ch10-multitexture.html">Chapter 10, Multitexturing</a></li>
</ul>
<p>As the examples progress, they build up common functionality and move them into helper js libraries; if those are useful, feel free to use them in your own experiments.  A list of more interesting demos will be coming as soon as I compile one.</p>
<p>Along with this release, I&#8217;ve set up a <a href="http://groups.google.com/group/canvas-3d">Canvas 3D group at Google Groups</a>, as the old labs forums are going away shortly.  Please use the forums there for reporting problems (soon to be Bugzilla, but it&#8217;s not quite set up yet).  I&#8217;d like to hear any feedback, or find out about any demos/experiments that may be using Canvas 3D!</p>
<p><span style="text-decoration: line-through;">Note: I&#8217;ve identified a problem with 0.4.1 that will cause crashes on Windows systems when software rendering is used (either selected or forced).  An updated 0.4.2 with a fix for this problem will be available soon.</span></p>
<p>Note: 0.4.2 is available at the link above; it fixes the Windows crash and a number of other software rendering problems on other platforms.<span style="text-decoration: line-through;"><br />
</span></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.vlad1.com/2009/03/28/canvas-3d-extension-update-2/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>
