Google chrome glReadPixels在Mac上Chrome的WebGL2下失败
我为WebGL 2编写了这个简单的matmul代码。此代码和参数在Windows上的Chrome中运行时没有问题。然而,当我使用Google chrome glReadPixels在Mac上Chrome的WebGL2下失败,google-chrome,webgl2,Google Chrome,Webgl2,我为WebGL 2编写了这个简单的matmul代码。此代码和参数在Windows上的Chrome中运行时没有问题。然而,当我使用webgl2context-ID时,我总是在Mac上的Chrome中遇到这个错误 GL_INVALID_OPERATION : glReadPixels: format and type incompatible with the current read framebuffer 以下是我使用的参数: readOutput(gl, width, height, gl.
webgl2
context-ID时,我总是在Mac上的Chrome中遇到这个错误
GL_INVALID_OPERATION : glReadPixels: format and type incompatible with the current read framebuffer
以下是我使用的参数:
readOutput(gl, width, height, gl.RED, gl.FLOAT, c);
...
function readOutput(gl, width, height, format, type, buffer) {
gl.readPixels(0, 0, width, height, format, type, buffer);
}
这就是我创建纹理的方式:
const texA = createTexture(gl, gl.R32F, gl.RED, gl.FLOAT, shapeA[1], shapeA[0], a);
最后是createTexture的代码:
function createTexture(gl, internalFormat, format, type, width, height, data) {
// Create the texture
const texture = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, texture);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
gl.texImage2D(
gl.TEXTURE_2D,
0, // 0 - no mipmaps
internalFormat, width, height,
0, // Always 0 in OpenGL ES.
format, type, data);
checkError(gl);
return texture;
}
因此,目前两款浏览器似乎都支持使用RGBA/FLOAT而不是RED/FLOAT进行阅读,但这两款浏览器都非常感谢@gman。第二种浏览器是指Safari吗?只有两种浏览器支持WebGL2、Chrome和Firefox。Safari从未支持过WebGL2,而且可能永远也不会支持。有一个标志可以启用它,但是如果你查看WebKit源代码,绝对没有代码,并且在过去的两年中没有添加任何新的内容,至少截至2018年12月,非常感谢提供更多信息。