jump to navigation

Compensating for WebGL readPixels() Failure Inconsistencies August 20, 2010

Posted by Andor Saga in JavaScript, Open Source, webgl.
4 comments

While working on Processing.js ref tests, I noticed Chrome/Chromium and Minefield behave differently when they fail calling readPixels() in WebGL. If you want your code to be backward-compatible with older nightlies, you have to handle these failures differently.

When readPixels() fails on Minefield, an exception is thrown. While on Chrome/Chromium an error is raised within the WebGL state. I wrote a hack to handle these cases:

var arr;
try{
  arr = ctx.readPixels(0, 0, width, height, ctx.RGBA, ctx.UNSIGNED_BYTE);

  // If running Chrome/Chromium and the above call fails, 
  // use the new way.
  if(ctx.getError()){
    arr = new Uint8Array(width * height * 4);
    ctx.readPixels(0, 0, width, height, ctx.RGBA, ctx.UNSIGNED_BYTE, arr); 
  }
}
catch(e){
  // If running Minefield and the old way throws an 
  // exception, use the new way.
  arr = new Uint8Array(width * height * 4);
  ctx.readPixels(0, 0, width, height, ctx.RGBA, ctx.UNSIGNED_BYTE, arr);
}

I encourage any JavaScript gurus to post a cleaner way to handle this. Also, I’m running OS X 10.5, so I have nothing for WebKit…yet.

Advertisements

XP PointStream 0.4.5 Released! August 20, 2010

Posted by Andor Saga in Arius3D, Open Source, point cloud, webgl, XB PointStream.
3 comments

We’ve released XB PointStream 0.4.5! Have a WebGL-enabled browser? Check out the demos! Or check out our video.


What is XB PointStream?

XB PointStream is a JavaScript library which will emulate Arius3D‘s PointStream viewer. It is designed to quickly render a large amount of point cloud data to the <canvas> tag using WebGL.

Keeping Up With the Spec

Due to changes to the WebGL specification, we decided to do a minor release to keep our library up to date and working with new nightlies. We updated our use typed arrays, readPixels() and made changes to our shaders so they pass validation. However, we’re still supporting the deprecated versions of function signatures to keep XBPS compatible with older browsers.

Get Involved!

If you’d like to get involved in development, testing or if you simply want to suggest ideas, visit us in the #seneca channel in irc.mozilla.org. Or file some tickets on our Lighthouse page. If you wanna get your hands dirty and hack some code, fork our repository from Github.