using System.Collections.Generic; namespace XCEngine.Rendering.Universal { internal sealed class RendererBlocks { private struct BlockRange { public int firstPassIndex; public int lastPassIndex; } private readonly BlockRange[] m_ranges = new BlockRange[(int)RendererBlock.Count]; public RendererBlocks() { Clear(); } public void Clear() { for (int i = 0; i < m_ranges.Length; ++i) { m_ranges[i].firstPassIndex = -1; m_ranges[i].lastPassIndex = -1; } } public void Build( IList activePassQueue) { Clear(); if (activePassQueue == null) { return; } for (int i = 0; i < activePassQueue.Count; ++i) { ScriptableRenderPass renderPass = activePassQueue[i]; if (renderPass == null) { continue; } RendererBlock block; if (!ScriptableRenderPass.TryResolveRendererBlock( renderPass.renderPassEvent, out block)) { continue; } int blockIndex = (int)block; BlockRange range = m_ranges[blockIndex]; if (range.firstPassIndex < 0) { range.firstPassIndex = i; } range.lastPassIndex = i; m_ranges[blockIndex] = range; } } public bool HasPasses( RendererBlock block) { BlockRange range = m_ranges[(int)block]; return range.firstPassIndex >= 0 && range.lastPassIndex >= range.firstPassIndex; } public bool TryGetPassRange( RendererBlock block, out int firstPassIndex, out int lastPassIndex) { BlockRange range = m_ranges[(int)block]; firstPassIndex = range.firstPassIndex; lastPassIndex = range.lastPassIndex; return range.firstPassIndex >= 0 && range.lastPassIndex >= range.firstPassIndex; } } }