1
林試圖讀取的紋理我有的RGBA值,但它一直返回下面的錯誤和每一個值出來爲0:WEBGL readPixels()無效操作:無效格式/類型組合
WebGL: INVALID_OPERATION: readPixels: invalid format/type combination
下面有我在初始化代碼,其中像素是紋理值的數組:
texture = gl.createTexture()
gl.activeTexture(gl.TEXTURE0)
gl.bindTexture(gl.TEXTURE_2D, texture)
gl.pixelStorei(gl.UNPACK_ALIGNMENT, 1)
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, n, n, 0,
gl.RGBA, gl.FLOAT, new Float32Array(pixels))
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST)
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST)
FBO = gl.createFramebuffer()
gl.bindFramebuffer(gl.FRAMEBUFFER, FBO)
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0,
gl.TEXTURE_2D, texture, 0)
再後來,在點擊事件中,我運行以下命令:
gl.bindFramebuffer(gl.FRAMEBUFFER, FBO);
var data = new Uint8Array(resolution * resolution * 4);
gl.readPixels(0, 0, resolution, resolution, gl.RGBA, gl.UNSIGNED_BYTE, data);
console.log(data)
數據返回大量的零。 什麼是格式和類型的正確組合,或者我在哪裏出錯了?