[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Public WebGL] Uint8ClampedArray can not be used with WebGL



That's a bug. Uint8ClampedArray used to derive from Uint8Array but the type hierarchy was changed when typed arrays were folded into the ECMAScript spec. It should be fixed for both WebGL 1.0 and 2.0. I've filed https://github.com/KhronosGroup/WebGL/issues/1533 about this. Thanks for reporting the problem.

-Ken


On Sat, Mar 5, 2016 at 9:49 AM, Gregg Tavares <khronos@greggman.com> wrote:
I forgot why but currently calls to texImage2D check based on `type` that the corresponding ArrayBuffer type.

for type `UNSIGNED_BYTE` currently `Uint8Array` is required which means I get an error if I pass in a `Uint8ClampedArray`

gl = document.createElement("canvas").getContext("webgl");
gl.bindTexture(gl.TEXTURE_2D, gl.createTexture());
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, 
         new Uint8ClampedArray(4));

WebGL: INVALID_OPERATION: texImage2D: type UNSIGNED_BYTE but ArrayBufferView not Uint8Array


Should that change? Should it change for WebGL2 if not WebGL1?

How about SharedArrays?