[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 14/06/2012 17:00, Gregg Tavares (社用) wrote:

That's was wrong with Glenn's suggestion. Many apps will break and authors won't know until they test on HD-DPI displays that their code is wrong. This is already true for all 2600+ examples on glsl.heroku.com and several more on the shader toy since they all do effectively this math

    vec2 texCoord = gl_FragCoord.xy / resolution

Where resolution = canvas.width, canvas.height

That produces values that go from 0.0 to 1.0 across the screen

That code is broken. With or without your proposed changes it will fail when the drawing buffer size != canvas size. Currently they can be not equal either because css pixels != device pixels or because the implementation could not allocate a drawing buffer the size of the canvas. With your proposed change, the latter remains a possibility.

What is generally hiding the brokenness now is that the viewport is clamped to MAX_VIEWPORT_DIM which is commonly the limit of the allocation for very large canvases. This is not always the case. A implementation may choose to allocate a drawing buffer < MAX_VIEWPORT_DIM for memory or performance reasons or it may be forced to because MAX_RENDERBUFFER_SIZE is less than MAX_VIEWPORT_DIM.

The code is broken. It needs to be fixed to calculate resolution from gl.drawingBuffer{Width,Height}.