_updateDimension({width, height, video}) { const {videoTexture, model, transformFeedback, gl} = this; if (width === videoTexture.width && height === videoTexture.height) { return; } // video.width = width; // video.height = height; videoTexture.resize({width: video.videoWidth, height: video.videoHeight}); const vertexCount = width * height; model.setVertexCount(vertexCount); // update attribute const uv = new Float32Array(2 * vertexCount); let i = 0; for (let y = 0; y < height; y++) { for (let x = 0; x < width; x++) { uv[i++] = (x + 0.5) / width; uv[i++] = (y + 0.5) / height; } } model.setAttributes({uv: {size: 2, value: uv}}); const iconFrameBuffer = new Buffer(gl, { size: 4, instanced: 1, data: new Float32Array(4 * vertexCount), usage: GL.DYNAMIC_COPY }); const colorBuffer = new Buffer(gl, { size: 4, instanced: 1, data: new Float32Array(4 * vertexCount), usage: GL.DYNAMIC_COPY }); this.buffers = { instanceIconFrames: iconFrameBuffer, instanceColors: colorBuffer }; transformFeedback.setBuffers({ 0: iconFrameBuffer, 1: colorBuffer }); }
getBuffers({width, height, video}) { const {model, videoTexture, transformFeedback} = this; this._updateDimension({width, height, video}); videoTexture.setSubImageData({width: video.videoWidth, height: video.videoHeight, data: video}); model.draw({ uniforms: { video: videoTexture }, transformFeedback, parameters: { [GL.RASTERIZER_DISCARD]: true } }); return this.buffers; }