private static void StaticReset(int frameIndex, RenderManager renderManager) { if (_LastFrameStaticReset >= frameIndex) { return; } // Any buffers that remain unused (either from being too small, or being unnecessary now) // should be disposed. XNABufferPair <TVertex> hb; using (var e = _UnusedHardwareBuffers.GetEnumerator()) while (e.GetNext(out hb)) { hb.Age += 1; bool shouldKill = (hb.Age >= MaxBufferAge) || ((_UnusedHardwareBuffers.Count > MaxUnusedBuffers) && (hb.Age > 1)); if (shouldKill) { e.RemoveCurrent(); hb.Invalidate(frameIndex); renderManager.DisposeResource(hb); } } _LastFrameStaticReset = frameIndex; }
public void Dispose() { if (_IsActive != 0) { throw new InvalidOperationException("Disposed buffer while in use"); } Interlocked.Add(ref RenderManager.TotalVertexBytes, System.Runtime.InteropServices.Marshal.SizeOf(typeof(TVertex)) * -VertexCount); Interlocked.Add(ref RenderManager.TotalIndexBytes, 2 * -IndexCount); RenderManager.DisposeResource(Vertices); RenderManager.DisposeResource(Indices); Vertices = null; Indices = null; IsAllocated = false; _IsValid = 0; }
private static void StaticReset(int frameIndex, RenderManager renderManager) { if (_LastFrameStaticReset >= frameIndex) { return; } // Any buffers that remain unused (either from being too small, or being unnecessary now) // should be disposed. XNABufferPair <TVertex> hb; using (var e = _UnusedHardwareBuffers.GetEnumerator()) while (e.GetNext(out hb)) { hb.Age += 1; int usedCount = hb.IsLarge ? _LargeUnusedBufferCount : _SmallUnusedBufferCount; int usedLimit = hb.IsLarge ? MaxLargeUnusedBuffers : MaxSmallUnusedBuffers; bool shouldKill = (!hb.ProtectedFromDeath && (hb.Age >= MaxBufferAge)) || ((usedCount > usedLimit) && (hb.Age > 1)); if (shouldKill) { e.RemoveCurrent(); hb.Invalidate(frameIndex); if (hb.IsLarge) { _LargeUnusedBufferCount--; } else { _SmallUnusedBufferCount--; } renderManager.DisposeResource(hb); } } _LastFrameStaticReset = frameIndex; }