public texReader(WebGLRenderingContext webgl, WebGLTexture texRGBA, int width, int height, bool gray = true) { this.gray = gray; this.width = width; this.height = height; var fbo = webgl.CreateFramebuffer(); WebGLFramebuffer fbold = webgl.GetParameter(webgl.FRAMEBUFFER_BINDING) as WebGLFramebuffer; webgl.BindFramebuffer(webgl.FRAMEBUFFER, fbo); webgl.FramebufferTexture2D(webgl.FRAMEBUFFER, webgl.COLOR_ATTACHMENT0, webgl.TEXTURE_2D, texRGBA, 0); var readData = new Uint8Array(this.width * this.height * 4); readData[0] = 2; webgl.ReadPixels(0, 0, this.width, this.height, webgl.RGBA, webgl.UNSIGNED_BYTE, readData); webgl.DeleteFramebuffer(fbo); webgl.BindFramebuffer(webgl.FRAMEBUFFER, fbold); if (gray) { this.data = new Uint8Array(this.width * this.height); for (var i = 0; i < width * height; i++) { this.data[i] = readData[i * 4]; } } else { this.data = readData; } }