.readRenderTargetPixels
seems broken on Safari.
Error: WebGL: INVALID_ENUM: readPixels: invalid type
The bug can be reproduced on the official example: https://threejs.org/examples/webgl_read_float_buffer.html
I haven't had time to debug it, but it seems to affect also Safari iOS
(In my specific case, I've fixed using UnsignedByteType
instead of FloatType
)
Only unsigned byte is guaranteed by the WebGL spec.
https://www.khronos.org/registry/webgl/specs/latest/1.0/index.html#readpixels
The implementation specific format checks obviously don't catch the Safari case.
The problem is that renderer.extensions.get( 'OES_texture_float' )
returns not null in Safari. So when using a float texture, the entire if
statements evaluates to false
.
BTW: Just executing the following code in the example returns 0
in Safari.
const gl = renderer.context;
console.log( gl.getParameter( gl.IMPLEMENTATION_COLOR_READ_TYPE ) );
In Chrome and Firefox, the value 5121
is logged which means UNSIGNED_BYTE
. What does actually 0
mean?
Is this a recent breakage with Safari, or Three? I'm surprised this issue hasn't been raised before.
Incidentally the documentation for readRenderTargetPixels() only suggests float buffers are accepted as destinations when the reality is somewhat different.
After a quick search It looks like the Safari behaviour has been around awhile now.
Um, since this is obviously a browser issue, I would prefer to leave the code as it is. There is already a bug report after all.
Incidentally the documentation for readRenderTargetPixels() only suggests float buffers are accepted as destinations when the reality is somewhat different.
You mean the documentation of three.js
? I can't find the mentioned section.
https://threejs.org/docs/index.html#api/en/renderers/WebGLRenderer.readRenderTargetPixels
Sorry, I was misreading the type annotation in the three docs.
I think the Khronos WebGL 1.0 spec is potentially ambiguous, it guarantees unsigned byte is supported and a potentially source dependent implementation specific type/format. So supporting float isn't a given and I suspect the getParameter() result of 0 indicates no second format support. The spec doesn't say 'must' or 'should'.
I think it is probably worth documenting that unsigned byte/RGBA is the only combination universally supported?
I think it is probably worth documenting that unsigned byte/RGBA is the only combination universally supported?
Sounds good.
Closing. This needs to be fixed in Safari.
Hey, it looks like they are already working on a fix 馃帀
Most helpful comment
Hey, it looks like they are already working on a fix 馃帀
https://bugs.webkit.org/show_bug.cgi?id=171432#c3