I want to offload some matrix computations to a fragment shader, using WebGL.
I'm trying to send my matrix as an RGB 2D texture, using texImage2D
, but I don't know how the data must be formated.
I tried this (for a square 2x2 matrix):
var textureData = new Uint8Array([
0, 0, 0, 1, 0, 0,
2, 0, 0, 3, 0, 0
]);
//...
var texture = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, texture);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGB, gl.RGB, gl.UNSIGNED_BYTE,
textureData);
But I get the following error:
Uncaught TypeError: Failed to execute 'texImage2D' on 'WebGLRenderingContext': No function was found that matched the signature provided.