public void Add(Batch batch) { var state = State; if (state != (int)States.Initialized) { throw new InvalidOperationException($"Frame state should have been initialized but was {(States)state}"); } if (batch == null) { throw new ArgumentNullException("batch"); } lock (BatchLock) { /* #if DEBUG && PARANOID * if (Batches.Contains(batch)) * throw new InvalidOperationException("Batch already added to this frame"); #endif */ Batches.Add(batch); batch.Container = this; } }
public void Add(Batch batch) { if (State != (int)States.Initialized) { throw new InvalidOperationException(); } if (batch == null) { throw new ArgumentNullException("batch"); } lock (BatchLock) { /* #if DEBUG && PARANOID * if (Batches.Contains(batch)) * throw new InvalidOperationException("Batch already added to this frame"); #endif */ Batches.Add(batch); batch.Container = this; } }
protected void Add(T item) { _DrawCalls.Add(item); }
/// <summary> /// Scans over a list of batches and applies batch combiners to reduce the total number of batches sent to the GPU and /// improve batch preparation efficiency. Batches eliminated by combination are replaced with null. /// </summary> /// <param name="batches">The list of batches to perform a combination pass over.</param> /// <returns>The number of batches eliminated.</returns> public static int CombineBatches(ref DenseList <Batch> batches, ref DenseList <Batch> batchesToRelease) { batches.Sort(BatchTypeSorter); int i = 0, j = i + 1, l = batches.Count, eliminatedCount = 0; Batch a, b; Type aType, bType; while ((i < l) && (j < l)) { a = batches[i]; if ((a == null) || (a.SuspendFuture != null)) { i += 1; j = i + 1; continue; } aType = a.GetType(); b = batches[j]; if ((b == null) || (b.SuspendFuture != null)) { j += 1; continue; } bType = b.GetType(); if ((aType != bType) || (a.Layer != b.Layer)) { i = j; j = i + 1; } else { bool combined = false; foreach (var combiner in Combiners) { if (combined = combiner.CanCombine(a, b)) { batches[i] = combiner.Combine(a, b); batches[i].Container = a.Container; if ((a != batches[i]) && (a.ReleaseAfterDraw)) { batchesToRelease.Add(a); } eliminatedCount += 1; break; } } j += 1; } } if (false && eliminatedCount > 0) { Console.WriteLine("Eliminated {0:0000} of {1:0000} batch(es)", eliminatedCount, batches.Count); } return(eliminatedCount); }