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

Re: [Public WebGL] How to set a canvas backing store to display units?





On Fri, Jun 15, 2012 at 2:05 PM, Glenn Maynard <glenn@zewt.org> wrote:
On Fri, Jun 15, 2012 at 1:42 PM, James Darpinian <jdarpinian@google.com> wrote:
Furthermore, the kind of content WebGL is used for usually doesn't need to be rendered at full display resolution to look acceptable. Pixel-doubling the sharp vectors and text commonly rendered in a 2D context looks terrible, but pixel-doubling the more natural 3D scenes WebGL excels at looks fine. In fact, most console games render at less than full display resolution because performance is more important.

To be sure, the *ability* to render at a lower resolution and then scaling up for performance reasons is useful, but using consoles doing this as an argument that it's okay for it to be WebGL's norm--forever, even on hardware years from now--is a bit crazy.

Does anyone see any issues with an "allowHighRes" option to getContext("webgl")?  This wouldn't violate the Canvas spec, since it's only making WebGL give an additional guarantee ("if allowHighRes is not set, the backing store will not be higher resolution than the canvas's natural dimensions"), it avoids lying to Canvas (by setting its width/height to device pixels instead of the required CSS pixels), and avoids the need for CSS hacks (with the problems Ian and I have described).  It also allows giving the browser control over whether or not to actually use a high-res backing store, as Canvas intends; if you use window.devicePixelRatio (a currently unstandardized function, I believe), there's no way to do that short of the browser putting a false value in that attribute.

Canvas 2d is (mostly) a vector API, so you can write canvas 2d code that does not care how many pixels are in the backing store and it will Just Work.

That is definitely not true for OpenGL or WebGL - in general it is not possible to write code that works correctly that does not care about how many pixels are actually in the backing store.  I think this is the fundamental difference between 2d canvas and WebGL and not something we can gloss over with an option or attribute.

- James

 


--
Glenn Maynard