No antialiasing for iOS 8 safari webgl

為{幸葍}努か 提交于 2020-01-16 05:06:13

问题


Safari on iOS 8 supporting webgl is surely a good news but after I run my demo I find that there is no antialiasing. Any solutions?


回答1:


role you own? There's lots of ways to anti-alias. Here's one. First check that you're not already anti-aliased

var gl = someCanvas.getContext("webgl");
var contextAttribs = gl.getContextAttributes();
if (!contextAttribs.antialias) {
  // do your own anti-aliasing
}

The simplest way would be to make your canvas's backing store larger than it's displayed. Assuming you have a canvas that you want to be displayed a certain size

canvas.width = desiredWidth * 2;
canvas.height = desiredHeight * 2;
canvas.style.width = desiredWidth + "px";
canvas.style.height = desiredHeight + "px";

Now your canvas will most likely be bi-linear filtered when drawn. In iOS's case since they are all HD-DPI you probably will need to do 4x

canvas.width  = desiredWidth  * 4;
canvas.height = desiredHeight * 4;
canvas.style.width  = desiredWidth  + "px";
canvas.style.height = desiredHeight + "px";

You can find out by looking at window.devicePixelRatio. In fact if you want 1x1 pixels you'd do this

var devicePixelRatio = window.devicePixelRatio || 1;
var overdraw = 1; // or 2
var scale = devicePixelRatio * overdraw;
canvas.width  = desiredWidth  * scale;
canvas.height = desiredHeight * scale;
canvas.style.width  = desiredWidth  + "px";
canvas.style.height = desiredHeight + "px";

Otherwise, another way is to render to a texture attached to a framebuffer then render the texture into the canvas using a shader that does antialiasing.



来源:https://stackoverflow.com/questions/25387949/no-antialiasing-for-ios-8-safari-webgl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!