private static void staticUpdate() { // All requests that are already pending are ready to have their data copied from // native memory to managed memory. foreach (var req in _readyRequests) { // Retrieve, but also report how long each step took for profiling. GlintPlugin.RetrieveTextureData(req.gpuTexture, ref req.cpuData, out Glint.Profiling.lastRenderMapMs, out Glint.Profiling.lastRenderCopyMs, out Glint.Profiling.lastMainCopyMs); // Buffer for removal and recycle. _reqBuffer.Add(req); // Fire the Action! req.onRetrieved(); } // Remove any completed requests. foreach (var req in _reqBuffer) { finalizeRequest(req); } _readyRequests.Clear(); _reqBuffer.Clear(); // Decrement timers for pending requests, and fire retrieve operations, moving // those requests to the ready requests. foreach (var req in _pendingRequests) { if (req.readyForRetrieval) { // At this stage, we must IssuePluginEvent before we can actually get the // data (the memory copy has to happen on the render thread). GlintPlugin.RetrieveTextureData(req.gpuTexture, ref req.cpuData); _reqBuffer.Add(req); } } // Transfer buffered requests from pending to ready. foreach (var req in _reqBuffer) { _pendingRequests.Remove(req); _readyRequests.Add(req); } _reqBuffer.Clear(); }
public static void CreateRequest(Texture gpuTexture, float[] cpuData, Action onRetrieved, int waitTimeInFrames) { ensureInstanceExists(); var req = Pool <Request> .Spawn(); req.gpuTexture = gpuTexture; req.cpuData = cpuData; req.onRetrieved = onRetrieved; req.waitTimeInFrames = waitTimeInFrames; GlintPlugin.RequestTextureData(req.gpuTexture); _pendingRequests.Add(req); }