protected virtual void Dispose(bool disposing) { if (disposed) { return; } if (disposing) { UIRUtility.Destroy(atlas); atlas = null; if (m_Allocator != null) { m_Allocator.Dispose(); m_Allocator = null; } if (m_Blitter != null) { m_Blitter.Dispose(); m_Blitter = null; } } else { UnityEngine.UIElements.DisposeHelper.NotifyMissingDispose(this); } disposed = true; }
protected virtual void Dispose(bool disposing) { s_Instances.Remove(this); if (disposed) { return; } if (disposing) { UIRUtility.Destroy(atlas); atlas = null; UIRUtility.Destroy(m_BlitMaterial); m_BlitMaterial = null; if (m_Allocator != null) { m_Allocator.Dispose(); m_Allocator = null; } if (atlasManagerDisposed != null) { atlasManagerDisposed(this); } } else { UnityEngine.UIElements.DisposeHelper.NotifyMissingDispose(this); } disposed = true; }
/// <remarks> /// When textures that have been previously allowed into the atlas manager change, or if the project color /// space changes, this method MUST be called. Textures that had been previously accepted into the atlas may /// now be refused, and previously refused textures may now be accepted. /// </remarks> public void Reset() { if (disposed) { LogDisposeError(); return; } s_ResetSampler.Begin(); m_PendingBlits.Clear(); m_UVs.Clear(); m_Allocator = new UIRAtlasAllocator(64, 4096); m_ForceReblitAll = false; m_ColorSpace = QualitySettings.activeColorSpace; UIRUtility.Destroy(atlas); m_RequiresReset = false; if (ResetPerformed != null) { ResetPerformed(this, EventArgs.Empty); } s_ResetSampler.End(); }
protected virtual void Dispose(bool disposing) { UIRAtlasManager.s_Instances.Remove(this); bool disposed = this.disposed; if (!disposed) { if (disposing) { UIRUtility.Destroy(this.atlas); this.atlas = null; bool flag = this.m_Allocator != null; if (flag) { this.m_Allocator.Dispose(); this.m_Allocator = null; } bool flag2 = this.m_Blitter != null; if (flag2) { this.m_Blitter.Dispose(); this.m_Blitter = null; } bool flag3 = UIRAtlasManager.atlasManagerDisposed != null; if (flag3) { UIRAtlasManager.atlasManagerDisposed(this); } } this.disposed = true; } }
public UIRAtlasAllocator(int initialAtlasSize, int maxAtlasSize, int sidePadding = 1) { Assert.IsTrue(initialAtlasSize > 0 && initialAtlasSize <= maxAtlasSize); Assert.IsTrue(initialAtlasSize == Mathf.NextPowerOfTwo(initialAtlasSize)); Assert.IsTrue(maxAtlasSize == Mathf.NextPowerOfTwo(maxAtlasSize)); this.m_1SidePadding = sidePadding; this.m_2SidePadding = sidePadding << 1; this.< maxAtlasSize > k__BackingField = maxAtlasSize; this.< maxImageWidth > k__BackingField = maxAtlasSize; this.< maxImageHeight > k__BackingField = ((initialAtlasSize == maxAtlasSize) ? (maxAtlasSize / 2 + this.m_2SidePadding) : (maxAtlasSize / 4 + this.m_2SidePadding)); this.virtualWidth = initialAtlasSize; this.virtualHeight = initialAtlasSize; int num = UIRAtlasAllocator.GetLog2OfNextPower(maxAtlasSize) + 1; this.m_OpenRows = new UIRAtlasAllocator.Row[num]; RectInt rect = new RectInt(0, 0, initialAtlasSize, initialAtlasSize); this.m_FirstUnpartitionedArea = UIRAtlasAllocator.AreaNode.Acquire(rect); this.BuildAreas(); }
public DynamicAtlasCore(RenderTextureFormat format = RenderTextureFormat.ARGB32, FilterMode filterMode = FilterMode.Bilinear, int maxImageSize = 64, int initialSize = 64, int maxAtlasSize = 4096) { Debug.Assert(filterMode == FilterMode.Bilinear || filterMode == FilterMode.Point); Debug.Assert(maxAtlasSize <= SystemInfo.maxRenderTextureSize); Debug.Assert(initialSize <= maxAtlasSize); Debug.Assert(Mathf.IsPowerOfTwo(maxImageSize)); Debug.Assert(Mathf.IsPowerOfTwo(initialSize)); Debug.Assert(Mathf.IsPowerOfTwo(maxAtlasSize)); m_MaxAtlasSize = maxAtlasSize; this.format = format; this.maxImageSize = maxImageSize; m_FilterMode = filterMode; m_UVs = new Dictionary <Texture2D, RectInt>(64); m_Blitter = new TextureBlitter(64); m_InitialSize = initialSize; m_2SidePadding = filterMode == FilterMode.Point ? 0 : 2; m_1SidePadding = filterMode == FilterMode.Point ? 0 : 1; m_Allocator = new UIRAtlasAllocator(m_InitialSize, m_MaxAtlasSize, m_1SidePadding); m_ColorSpace = QualitySettings.activeColorSpace; }
/// <remarks> /// When textures that have been previously allowed into the atlas manager change, or if the project color /// space changes, this method MUST be called. Textures that had been previously accepted into the atlas may /// now be refused, and previously refused textures may now be accepted. /// </remarks> public void Reset() { if (disposed) { LogDisposeError(); return; } s_MarkerReset.Begin(); m_Blitter.Reset(); m_UVs.Clear(); m_Allocator = new UIRAtlasAllocator(m_InitialSize, 4096, m_1SidePadding); m_ForceReblitAll = false; m_ColorSpace = QualitySettings.activeColorSpace; UIRUtility.Destroy(atlas); s_MarkerReset.End(); m_ResetVersion = s_GlobalResetVersion; }
/// <remarks> /// When textures that have been previously allowed into the atlas manager change, or if the project color /// space changes, this method MUST be called. Textures that had been previously accepted into the atlas may /// now be refused, and previously refused textures may now be accepted. /// </remarks> public void Reset() { if (disposed) { LogDisposeError(); return; } s_ResetSampler.Begin(); m_Blitter.Reset(); m_UVs.Clear(); m_Allocator = new UIRAtlasAllocator(64, 4096); m_ForceReblitAll = false; m_ColorSpace = QualitySettings.activeColorSpace; UIRUtility.Destroy(atlas); s_ResetSampler.End(); m_ResetVersion = s_GlobalResetVersion; }
public void Reset() { bool disposed = this.disposed; if (disposed) { UIRAtlasManager.LogDisposeError(); } else { UIRAtlasManager.s_MarkerReset.Begin(); this.m_Blitter.Reset(); this.m_UVs.Clear(); this.m_Allocator = new UIRAtlasAllocator(this.m_InitialSize, 4096, this.m_1SidePadding); this.m_ForceReblitAll = false; this.m_ColorSpace = QualitySettings.activeColorSpace; UIRUtility.Destroy(this.atlas); this.atlas = null; UIRAtlasManager.s_MarkerReset.End(); this.m_ResetVersion = UIRAtlasManager.s_GlobalResetVersion; } }
public bool TryAllocate(int width, int height, out RectInt location) { bool result; using (UIRAtlasAllocator.s_MarkerTryAllocate.Auto()) { location = default(RectInt); bool disposed = this.disposed; if (disposed) { result = false; } else { bool flag = width < 1 || height < 1; if (flag) { result = false; } else { bool flag2 = width > this.maxImageWidth || height > this.maxImageHeight; if (flag2) { result = false; } else { int log2OfNextPower = UIRAtlasAllocator.GetLog2OfNextPower(Mathf.Max(height - this.m_2SidePadding, 1)); int rowHeight = (1 << log2OfNextPower) + this.m_2SidePadding; UIRAtlasAllocator.Row row = this.m_OpenRows[log2OfNextPower]; bool flag3 = row != null && row.width - row.Cursor < width; if (flag3) { row = null; } bool flag4 = row == null; if (flag4) { for (UIRAtlasAllocator.AreaNode areaNode = this.m_FirstUnpartitionedArea; areaNode != null; areaNode = areaNode.next) { bool flag5 = this.TryPartitionArea(areaNode, log2OfNextPower, rowHeight, width); if (flag5) { row = this.m_OpenRows[log2OfNextPower]; break; } } bool flag6 = row == null; if (flag6) { result = false; return(result); } } location = new RectInt(row.offsetX + row.Cursor, row.offsetY, width, height); row.Cursor += width; Assert.IsTrue(row.Cursor <= row.width); this.physicalWidth = Mathf.NextPowerOfTwo(Mathf.Max(this.physicalWidth, location.xMax)); this.physicalHeight = Mathf.NextPowerOfTwo(Mathf.Max(this.physicalHeight, location.yMax)); result = true; } } } } return(result); }