/// <summary> /// Queue a rendertexture for readback. The readback will happen after the number of requests reaches the batchsize. /// </summary> /// <param name="request">The request associated with this batch readback instance.</param> /// <param name="channel">Which channel this readback is for.</param> /// <param name="renderTexture">Render texture to readback.</param> public void QueueReadback(AsyncRequest <CaptureCamera.CaptureState> request, CaptureCamera.Channel channel, RenderTexture renderTexture) { Debug.Assert(request.data.GetFunctor(channel) != null, $"QueueReadback request has no completion function for {channel} channel"); var rbr = GetReadBackRequestFromPool(request, channel, renderTexture); _requestsBatch.Enqueue(rbr); if (_requestsBatch.Count == BatchSize) { Flush(); } }
ReadbackRequest GetReadBackRequestFromPool(AsyncRequest <CaptureCamera.CaptureState> request, CaptureCamera.Channel channel, RenderTexture renderTexture) { ReadbackRequest rbr; if (_requestsPool.Count > 0) { rbr = _requestsPool.Dequeue(); } else { rbr = new ReadbackRequest(); } rbr.request = request; rbr.channel = channel; rbr.callback = request.data.SetFunctor(channel, null); if (rbr.renderTexture == null || rbr.renderTexture.width != renderTexture.width || rbr.renderTexture.height != renderTexture.height || !rbr.renderTexture.CompareFormat(renderTexture.graphicsFormat)) { rbr.renderTexture = new RenderTexture(renderTexture); } Graphics.Blit(renderTexture, rbr.renderTexture); return(rbr); }