private unsafe static void OnRegisterIntermediateRenderers(Camera camera) { var panels = UIElementsUtility.GetPanelsIterator(); while (panels.MoveNext()) { var p = panels.Current.Value; RenderChain renderChain = (p.GetUpdater(VisualTreeUpdatePhase.Repaint) as UIRRepaintUpdater)?.renderChain; if (renderChain == null || renderChain.m_StaticIndex < 0) { continue; } Material standardMat = renderChain.GetStandardWorldSpaceMaterial(); RuntimePanel rtp = (RuntimePanel)p; int renderNodeIndex = renderChain.m_ActiveRenderNodes; if (renderNodeIndex < renderChain.m_RenderNodesData.Count) { var renderNodeData = renderChain.m_RenderNodesData[renderNodeIndex]; renderNodeData.viewport = p.visualTree.layout; renderNodeData.standardMat = standardMat; renderChain.m_RenderNodesData[renderNodeIndex] = renderNodeData; } else { renderNodeIndex = renderChain.m_RenderNodesData.Count; renderChain.m_RenderNodesData.Add(new RenderNodeData() { matPropBlock = new MaterialPropertyBlock(), viewport = p.visualTree.layout, standardMat = standardMat }); } int *userData = stackalloc int[2]; userData[0] = renderChain.m_StaticIndex; userData[1] = renderNodeIndex; UIR.Utility.RegisterIntermediateRenderer(camera, standardMat, rtp.panelToWorld, new Bounds(Vector3.zero, new Vector3(float.MaxValue, float.MaxValue, float.MaxValue)), 3, 0, false, 0, (ulong)camera.cullingMask, (int)UIR.Utility.RendererCallbacks.RendererCallback_Exec, new IntPtr(userData), sizeof(int) * 2); } }
private static void OnRegisterIntermediateRenderers(Camera camera) { int commandOrder = 0; var panels = UIElementsUtility.GetPanelsIterator(); while (panels.MoveNext()) { var p = panels.Current.Value; RenderChain renderChain = (p.GetUpdater(VisualTreeUpdatePhase.Repaint) as UIRRepaintUpdater)?.renderChain; if (renderChain == null || renderChain.m_StaticIndex < 0 || renderChain.m_FirstCommand == null) { continue; } RuntimePanel rtp = (RuntimePanel)p; Material standardMaterial = renderChain.GetStandardWorldSpaceMaterial(); RenderNodeData rndSource = new RenderNodeData(); rndSource.device = renderChain.device; rndSource.standardMaterial = standardMaterial; rndSource.atlas = renderChain.atlasManager?.atlas; rndSource.vectorAtlas = renderChain.vectorImageManager?.atlas; rndSource.shaderInfoAtlas = renderChain.shaderInfoAllocator.atlas; rndSource.dpiScale = rtp.scaledPixelsPerPoint; rndSource.transformConstants = renderChain.shaderInfoAllocator.transformConstants; rndSource.clipRectConstants = renderChain.shaderInfoAllocator.clipRectConstants; if (renderChain.m_CustomMaterialCommands == 0) { // Trivial case, custom materials not used, so we don't have to chop the chain // to multiple intermediate renderers rndSource.initialMaterial = standardMaterial; rndSource.firstCommand = renderChain.m_FirstCommand; OnRegisterIntermediateRendererMat(rtp, renderChain, ref rndSource, camera, commandOrder++); continue; } // Complex case, custom materials used // TODO: Early out once all custom materials have been counted Material lastMaterial = null; var command = renderChain.m_FirstCommand; RenderChainCommand commandToStartWith = command; while (command != null) { if (command.type != CommandType.Draw) { command = command.next; continue; } Material commandMat = command.state.material == null ? standardMaterial : command.state.material; if (commandMat != lastMaterial) { if (lastMaterial != null) { rndSource.initialMaterial = lastMaterial; rndSource.firstCommand = commandToStartWith; OnRegisterIntermediateRendererMat(rtp, renderChain, ref rndSource, camera, commandOrder++); commandToStartWith = command; } lastMaterial = commandMat; } command = command.next; } // While render chain commands to execute if (commandToStartWith != null) { rndSource.initialMaterial = lastMaterial; rndSource.firstCommand = commandToStartWith; OnRegisterIntermediateRendererMat(rtp, renderChain, ref rndSource, camera, commandOrder++); } } // For each panel }