Webgl 如何在p5.js中快速设置像素阵列的均匀纹理?

Webgl 如何在p5.js中快速设置像素阵列的均匀纹理?,webgl,p5.js,texture2d,uniform,Webgl,P5.js,Texture2d,Uniform,我有像素阵列 arr8 = new Uint8Array(width*height*4); arr32f = new Float32Array(width*height); 我想把它送到shader的 uniform sampler2D tex; 但是p5.js function.setUniform('tex',img);似乎只接受图像(和只有rgba),我找到了唯一的方法与额外的复制到图像 img = createImage(width, height); ...... img.loa

我有像素阵列

arr8 = new Uint8Array(width*height*4);
arr32f = new Float32Array(width*height); 
我想把它送到shader的

uniform sampler2D tex;
但是p5.js function.setUniform('tex',img);似乎只接受图像(和只有rgba),我找到了唯一的方法与额外的复制到图像

img = createImage(width, height);
......
img.loadPixels();
    for(let n=0;n<height*width;n+=4){
        img.pixels[n] = arr8[n];
        img.pixels[n + 1] = ...;
        img.pixels[n + 2] = ...;
        img.pixels[n + 3] = ...;
    }
img.updatePixels();
myShader.setUniform('tex', img);
或者至少对于RGBA格式

gl.texImage2D(gl.TEXTURE_2D, 0, gl.LUMINANCE, width, height, 0, gl.LUMINANCE, gl.FLOAT, new Float32Array(arr32f));