public override void Draw(RenderDrawContext context, RenderView renderView, RenderViewStage renderViewStage, int startIndex, int endIndex) { // Do not call into VL if not running var renderContext = context.RenderContext; var runtime = this.runtime ?? (this.runtime = renderContext.Services.GetService <IVLRuntime>()); if (runtime != null && !runtime.IsRunning) { return; } // Build the list of layers to render singleCallLayers.Clear(); layers.Clear(); for (var index = startIndex; index < endIndex; index++) { var renderNodeReference = renderViewStage.SortedRenderNodes[index].RenderNode; var renderNode = GetRenderNode(renderNodeReference); var renderElement = (RenderDrawEffect)renderNode.RenderObject; if (renderElement.Enabled) { if (renderElement.SingleCallPerFrame) { singleCallLayers.Add(renderElement.Layer); } else { layers.Add(renderElement.Layer); } } } // Tell VL that we're calling into it - ensures that no hotswap will be happening RuntimeGraph.Enter(this); try { // Call layers which want to get invoked only once per frame first var currentFrameNr = renderContext.Time.FrameCount; if (lastFrameNr != currentFrameNr) { lastFrameNr = currentFrameNr; foreach (var layer in singleCallLayers) { try { layer?.Draw(Context, context, renderView, renderViewStage, context.CommandList); } catch (Exception e) { RuntimeGraph.ReportException(e); } } } // Call layers which can get invoked twice per frame (for each eye) foreach (var layer in layers) { try { layer?.Draw(Context, context, renderView, renderViewStage, context.CommandList); } catch (Exception e) { RuntimeGraph.ReportException(e); } } } finally { RuntimeGraph.Exit(this); } }