Example #1
0
        public void Draw()
        {
            if (Interlocked.Exchange(ref State, (int)States.Drawing) != (int)States.Prepared)
            {
                throw new InvalidOperationException();
            }

            if (Tracing.RenderTrace.EnableTracing)
            {
                Tracing.RenderTrace.ImmediateMarker("Frame {0:0000} : Begin Draw", Index);
            }

            var dm     = RenderManager.DeviceManager;
            var device = dm.Device;

            int c        = Batches.Count;
            var _batches = Batches.GetBuffer(false);

            for (int i = 0; i < c; i++)
            {
                var batch = _batches[i];
                if (batch != null)
                {
                    batch.IssueAndWrapExceptions(dm);
                }
            }

            dm.Finish();

            if (Tracing.RenderTrace.EnableTracing)
            {
                Tracing.RenderTrace.ImmediateMarker("Frame {0:0000} : End Draw", Index);
            }

            if (Interlocked.Exchange(ref State, (int)States.Drawn) != (int)States.Drawing)
            {
                throw new InvalidOperationException();
            }
        }
Example #2
0
        public void Draw()
        {
            if (Interlocked.Exchange(ref State, (int)States.Drawing) != (int)States.Prepared)
            {
                throw new InvalidOperationException();
            }

            var dm = RenderManager.DeviceManager;

            dm.FrameIndex = Index;
            var device = dm.Device;

            if (Tracing.RenderTrace.EnableTracing)
            {
                Tracing.RenderTrace.ImmediateMarker(device, "{1} {0:0000} : Begin Draw", Index, Label);
            }

            dm.Begin(ChangeRenderTargets);

            int c        = Batches.Count;
            var _batches = Batches.GetBuffer(false);

            for (int i = 0; i < c; i++)
            {
                var batch = _batches[i];
                if (batch != null)
                {
                    batch.IssueAndWrapExceptions(dm);
                }
            }

            dm.Finish();

            if (Tracing.RenderTrace.EnableTracing)
            {
                Tracing.RenderTrace.ImmediateMarker(device, "Frame {0:0000} : End Draw", Index);
            }

            // HACK
            Coordinator.PolygonBuffer?.Clear();

            if (Interlocked.Exchange(ref State, (int)States.Drawn) != (int)States.Drawing)
            {
                throw new InvalidOperationException();
            }
        }
Example #3
0
        /// <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, List <Batch> batchesToRelease)
        {
            batches.Sort(BatchTypeSorter);

            int i = 0, j = i + 1, l = batches.Count, eliminatedCount = 0;

            Batch a, b;
            Type  aType, bType;

            var isWritable = false;
            var _batches   = batches.GetBuffer(false);

            while ((i < l) && (j < l))
            {
                a = _batches[i];

                if (a == null)
                {
                    i += 1;
                    j  = i + 1;
                    continue;
                }
                aType = a.GetType();

                b = _batches[j];

                if (b == 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))
                        {
                            if (!isWritable)
                            {
                                isWritable = true;
                                _batches.Dispose();
                                _batches = batches.GetBuffer(true);
                            }

                            _batches[i]           = combiner.Combine(a, b);
                            _batches[i].Container = a.Container;

                            lock (batchesToRelease) {
                                if ((a != _batches[i]) && (a.ReleaseAfterDraw))
                                {
                                    batchesToRelease.Add(a);
                                }
                            }

                            eliminatedCount += 1;
                            break;
                        }
                    }

                    j += 1;
                }
            }

            _batches.Dispose();

            if (false && eliminatedCount > 0)
            {
                Console.WriteLine("Eliminated {0:0000} of {1:0000} batch(es)", eliminatedCount, batches.Count);
            }

            return(eliminatedCount);
        }