antialias = false会阻止在Mac OS上使用Safari的readPixels

问题描述 投票:0回答:1

我使用“ readPixels()”来读取webgl画布上的像素颜色。当getContext选项的antialise设置为false时,我无法读取像素。我可以在Safari / MacOS,Chrome,Firefox和Safari / iOS的下面一行中阅读以下内容。

const gl = canvas.getContext('webgl', {'preserveDrawingBuffer':true, 'antialias':true});

但是我不能在Safari / MacOS上阅读以下内容,但可以在Chrome,Firefox和Safari / iOS上阅读。

const gl = canvas.getContext('webgl', {'preserveDrawingBuffer':true, 'antialias':false});

ADD LINE:控制台输出Uint8Array [0,0,0,0],但像素具有颜色。

Safari / MacOS是否有问题,或者Safari / MacOS是否需要任何选项?我可以使用antialias = false的Safari / MacOS读取像素颜色吗?

对不起,我的英语不好,谢谢。

javascript safari webgl antialiasing glreadpixels
1个回答
0
投票

如果需要帮助调试,请发布更多代码

[这在Mac和iPhone的Safari中对我有效

function test(antialias) {
  const gl = document.createElement('canvas').getContext('webgl', {
    preserveDrawingBuffer: true,
    antialias,
  });
  gl.clearColor(1, 0.5, 0.25, 1);
  gl.clear(gl.COLOR_BUFFER_BIT);
  const pixel = new Uint8Array(4);
  gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, pixel);
  log(JSON.stringify(gl.getContextAttributes(), null, 2));
  log('pixel:', pixel);
}

function log(...args) {
  const elem = document.createElement('pre');
  elem.textContent = args.join(' ');
  document.body.appendChild(elem);
}

test(false);
test(true);
© www.soinside.com 2019 - 2024. All rights reserved.