public static ColorPage Init(UIR.RenderChain renderChain, UIR.BMPAlloc alloc) { bool isValid = alloc.IsValid(); return(new ColorPage() { isValid = isValid, pageAndID = isValid ? renderChain.shaderInfoAllocator.ColorAllocToVertexData(alloc) : new Color32() }); }
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 }
private unsafe static void OnRegisterIntermediateRendererMat(RuntimePanel rtp, RenderChain renderChain, ref RenderNodeData rnd, Camera camera, int sameDistanceSortPriority) { int renderNodeIndex = renderChain.m_ActiveRenderNodes++; if (renderNodeIndex < renderChain.m_RenderNodesData.Count) { var reuseRND = renderChain.m_RenderNodesData[renderNodeIndex]; rnd.matPropBlock = reuseRND.matPropBlock; renderChain.m_RenderNodesData[renderNodeIndex] = rnd; } else { rnd.matPropBlock = new MaterialPropertyBlock(); renderNodeIndex = renderChain.m_RenderNodesData.Count; renderChain.m_RenderNodesData.Add(rnd); } int *userData = stackalloc int[2]; userData[0] = renderChain.m_StaticIndex; userData[1] = renderNodeIndex; UIR.Utility.RegisterIntermediateRenderer(camera, rnd.initialMaterial, rtp.panelToWorld, new Bounds(Vector3.zero, new Vector3(float.MaxValue, float.MaxValue, float.MaxValue)), 3, 0, false, sameDistanceSortPriority, (ulong)camera.cullingMask, (int)UIR.Utility.RendererCallbacks.RendererCallback_Exec, new IntPtr(userData), sizeof(int) * 2); }