示例#1
0
        protected override void Prepare(PrepareManager manager)
        {
            _DrawCalls.Sort(_Comparer);

            int primCount = 0;

            for (int i = 0, c = _DrawCalls.Count; i < c; i++)
            {
                primCount += _DrawCalls[i].PrimitiveCount;
            }

            NativeBatch.RecordPrimitives(primCount);
        }
示例#2
0
        public RenderManager(GraphicsDevice device, Thread mainThread, ThreadGroup threadGroup)
        {
            if (mainThread == null)
            {
                throw new ArgumentNullException("mainThread");
            }

            MainThread     = mainThread;
            DeviceManager  = new DeviceManager(this, device);
            ThreadGroup    = threadGroup;
            PrepareManager = new PrepareManager(ThreadGroup);

            CreateNewBufferGenerators();

            _Frame = null;
        }
示例#3
0
        public RenderManager(GraphicsDevice device, Thread mainThread, ThreadGroup threadGroup)
        {
            if (mainThread == null)
            {
                throw new ArgumentNullException("mainThread");
            }

            MainThread     = mainThread;
            DeviceManager  = new DeviceManager(device);
            ThreadGroup    = threadGroup;
            PrepareManager = new PrepareManager(ThreadGroup);

            _BufferGenerators = new ThreadLocal <Dictionary <Type, IBufferGenerator> >(
                MakeThreadBufferGeneratorTable
                );

            _Frame = new Frame();
        }
示例#4
0
        protected override void Prepare(PrepareManager manager)
        {
            if (Count > 0)
            {
                _BufferGenerator = Container.RenderManager.GetBufferGenerator <BufferGenerator <GeometryVertex> >();

                _DrawArguments = _DrawArgumentsListPool.Allocate(null);
                var swb = _BufferGenerator.Allocate(VertexCount, IndexCount, true);
                _SoftwareBuffer = swb;

                var vb = new Internal.VertexBuffer <GeometryVertex>(swb.Vertices);
                var ib = new Internal.IndexBuffer(swb.Indices);
                int vertexOffset = 0, indexOffset = 0;
                int totalPrimCount = 0;

                foreach (var kvp in Lists)
                {
                    var l = kvp.Value;
                    var c = l.Count;

                    l.FastCLRSort(_DrawCallSorter);

                    int vertexCount = vb.Count, indexCount = ib.Count;

                    var _l = l.GetBuffer();
                    for (int i = 0; i < c; i++)
                    {
                        var dc = _l[i];
                        dc.Preparer(ref vb, ref ib, ref dc);
                    }

                    vertexCount = vb.Count - vertexCount;
                    indexCount  = ib.Count - indexCount;

                    int primCount;
                    MakeDrawArguments(kvp.Key, ref vb, ref ib, ref vertexOffset, ref indexOffset, out primCount, vertexCount, indexCount);

                    totalPrimCount += primCount;
                }

                NativeBatch.RecordPrimitives(totalPrimCount);
            }
        }
示例#5
0
        protected override void Prepare(PrepareManager manager)
        {
            // FIXME: Why the hell do we have to record these in Prepare and not Issue? >:|
            long primCount = 0;

            NativeDrawCall call;

            for (int i = 0, c = _DrawCalls.Count; i < c; i++)
            {
                _DrawCalls.GetItem(i, out call);
                if (call.InstanceCount.HasValue)
                {
                    primCount += call.PrimitiveCount * call.InstanceCount.Value;
                }
                else
                {
                    primCount += call.PrimitiveCount;
                }
            }

            RecordPrimitives(primCount);
        }
示例#6
0
 protected override void Prepare(PrepareManager manager)
 {
 }
示例#7
0
 public PrepareContext(PrepareManager manager, bool async, List <Batch> batchesToRelease)
 {
     Manager          = manager;
     Async            = async;
     BatchesToRelease = batchesToRelease;
 }
示例#8
0
 protected virtual void Prepare(PrepareManager manager)
 {
     OnPrepareDone();
 }
示例#9
0
        protected override bool PrepareDrawCalls(PrepareManager manager)
        {
            Squared.Render.NativeBatch.RecordPrimitives(_DrawCalls.Count * 2);

            AllocateNativeBatches();

            var textureCache = AbstractTextureReference.Cache.GetCurrentLocalCache();

            var count = _DrawCalls.Count;

            int[] indexArray = null;

            if (!DisableSorting)
            {
                indexArray = GetIndexArray(count);
                for (int i = 0; i < count; i++)
                {
                    indexArray[i] = i;
                }
            }

            if (DisableSorting)
            {
            }
            else if (Sorter != null)
            {
                var comparer = DrawCallSorterComparer.Value;
                comparer.Comparer = Sorter.GetComparer(true);
                _DrawCalls.Sort(comparer, indexArray);
            }
            else if (
                (UseZBuffer && ZBufferOnlySorting) ||
                DisableSortKeys ||
                (UseZBuffer && DepthPrePassOnly)
                )
            {
                // If sort keys are enabled, we want to try to draw back-to-front to maximize the effectiveness of the z-buffer
                if (DisableSortKeys)
                {
                    _DrawCalls.Sort(DrawCallTextureComparer, indexArray);
                }
                else
                {
                    _DrawCalls.Sort(DrawCallTextureAndReverseOrderComparer.Value, indexArray);
                }
            }
            else
            {
                _DrawCalls.Sort(DrawCallComparer.Value, indexArray);
            }

            _BufferGenerator = Container.RenderManager.GetBufferGenerator <BufferGenerator <BitmapVertex> >();
            _CornerBuffer    = Container.Frame.PrepareData.GetCornerBuffer(Container);

            if (Material == null)
            {
                if (!WarnedAboutNullMaterial)
                {
                    WarnedAboutNullMaterial = true;
                    Console.Error.WriteLine("WARNING: BitmapBatch prepared with null material");
                }
                return(false);
            }

            using (var callBuffer = _DrawCalls.GetBuffer(false)) {
                var callSegment       = new ArraySegment <BitmapDrawCall>(callBuffer.Data, callBuffer.Offset, callBuffer.Count);
                int drawCallsPrepared = 0;
                var parameters        = new BatchBuilderParameters {
                    material      = Material,
                    samplerState1 = SamplerState,
                    samplerState2 = SamplerState2,
                    textureCache  = textureCache
                };
                while (drawCallsPrepared < count)
                {
                    FillOneSoftwareBuffer(
                        indexArray, callSegment, ref drawCallsPrepared, count,
                        ref parameters, out bool failed
                        );
                    if (failed)
                    {
                        if (!WarnedAboutFillError)
                        {
                            WarnedAboutFillError = true;
                            Console.Error.WriteLine("WARNING: BitmapBatch prepare failed");
                        }
                        return(false);
                    }
                }
            }

            return(true);
        }
示例#10
0
文件: Batch.cs 项目: sq/Libraries
 public PrepareContext(PrepareManager manager, bool async)
 {
     Manager          = manager;
     Async            = async;
     BatchesToRelease = new DenseList <Batch>();
 }