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

Re: [Public WebGL] How to unambiguously set canvas pixel size to be pixel-perfect?




Hi Jukka

I've spent much time with this issue.
Unfortunately, the problem is VERY serious because all HTML 5 API is based on Integer.
All page layout (almost all except one method) operates with integer numbers. And this is the root of problem. For some zoom factors and some lay-outing you can not achieve pixel-to-pixel match.


For example: assume devicePixelRatio is 1.3333333 (33% zoom) and all you HTML Elements coordinates will be divided by 1.(33) and then ROUNDED.
So then if you get the element coordinated back and multiply by 1.(33) to get display pixels, you may get +-1 pixel error after second rounding:


What browser does:
 HTML.element.x = Math.round(Layout.x(y) / devicePixelRatio);
Then you get this value and do reverse
 int deviceCoord = Math.round(HTML.element.x * devicePixelRatio);
Canvas.setPos(deviceCoord);

Two sequential rounds may produce 1 pixel error which will result to blurry image.


Unfortunately, this is a fundamental HTML API issue. In perfect world all HTML elements layout API sould be in double precision.

-Kirill


On 11.06.2014 5:46, Jukka Jylänki wrote:
Hi there,

I raised a discussion about the need for explicit API or spec-guaranteed mechanism for resizing a WebGL canvas size to be pixel-perfect in the WebGL issue tracker. In the interest of not retyping everything, here's a link to the details:

https://github.com/KhronosGroup/WebGL/issues/587

The quick summary: When trying to come up the proper device pixel size for a WebGL canvas so that it properly matches the actual size displayed by the browser, fractional window.devicePixelRatio values in the wild (1.5 and 2.25 have been seen) pose problems, and to get the right result, one has to either floor, round or ceil the result depending on the devicePixelRatio and device resolution in question.

We need to spec down a method that is guaranteed to work so that off-by-one-pixel errors cannot possibly occur. What should such a mechanism look like that can take into account arbitrarily fractional devicePixelRatios out there?

Jukka


-----------------------------------------------------------
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:
unsubscribe public_webgl
-----------------------------------------------------------