Пример #1
0
        public void QueueToBufferBlitter_TestUnpackAndTransfer_CorrectBufferCallsAndDataTransfered()
        {
            var messenger = Substitute.For <IFrameworkMessenger>();
            IQueueToBufferBlitter blitter = new QueueToBufferBlitter();

            var q = new DrawQueue(messenger, new ComparerCollection(), 36, 8, false);

            Add(q, FillType.Coloured, 0UL, 0UL, TextureCoordinateMode.Mirror, TextureCoordinateMode.Mirror, 0);
            Add(q, FillType.Coloured, 0UL, 0UL, TextureCoordinateMode.Mirror, TextureCoordinateMode.Mirror, 0);
            Add(q, FillType.Coloured, 0UL, 0UL, TextureCoordinateMode.Mirror, TextureCoordinateMode.Mirror, 0);
            Add(q, FillType.Coloured, 0UL, 0UL, TextureCoordinateMode.Mirror, TextureCoordinateMode.Mirror, 0);
            Add(q, FillType.Coloured, 0UL, 0UL, TextureCoordinateMode.Mirror, TextureCoordinateMode.Mirror, 0);
            Add(q, FillType.Coloured, 0UL, 0UL, TextureCoordinateMode.Mirror, TextureCoordinateMode.Mirror, 0);
            Add(q, FillType.Coloured, 0UL, 0UL, TextureCoordinateMode.Mirror, TextureCoordinateMode.Mirror, 0);

            q.Sort();

            var wrap = new QueueWrap {
                Id = 0, BufferPositionOfFirstIndex = 16, BufferPositionOfFirstVertex = 32, Queue = q
            };

            var buffersMock = Substitute.For <IDrawStageBuffers>();

            blitter.UnpackAndTransferToGpu(wrap, buffersMock);

            buffersMock.Received(1).EnsureVertexBufferIsLargeEnough(Arg.Any <int>(), Arg.Any <bool>());
            buffersMock.Received(1).EnsureIndexBufferIsLargeEnough(Arg.Any <int>(), Arg.Any <bool>());

            buffersMock.ReceivedWithAnyArgs(21).CopyAVertexToStagingArray(default, default, default, default, default, default, default, default, default, default, default);
Пример #2
0
        public void DrawBatcherTools_CombineList_DoesSoInCorrectOrder()
        {
            IDrawStageBatcherTools tools = new DrawStageBatcherTools();

            var messenger = Substitute.For <IFrameworkMessenger>();

            var q0 = new DrawQueue(messenger, new ComparerCollection(), 12, 4, false);

            Add(q0, FillType.Coloured, 0UL, 0UL, TextureCoordinateMode.Mirror, TextureCoordinateMode.Mirror, 0);
            var w0 = new QueueWrap {
                Id = 0, BufferPositionOfFirstIndex = 0, BufferPositionOfFirstVertex = 0, Queue = q0
            };

            var q1 = new DrawQueue(messenger, new ComparerCollection(), 12, 4, false);

            Add(q1, FillType.Coloured, 1UL, 0UL, TextureCoordinateMode.Mirror, TextureCoordinateMode.Mirror, 0);
            var w1 = new QueueWrap {
                Id = 0, BufferPositionOfFirstIndex = 0, BufferPositionOfFirstVertex = 0, Queue = q1
            };

            var q2 = new DrawQueue(messenger, new ComparerCollection(), 12, 4, false);

            Add(q2, FillType.Coloured, 2UL, 0UL, TextureCoordinateMode.Mirror, TextureCoordinateMode.Mirror, 0);
            var w2 = new QueueWrap {
                Id = 0, BufferPositionOfFirstIndex = 0, BufferPositionOfFirstVertex = 0, Queue = q2
            };

            var others = new List <QueueWrap> {
                w1, w2
            };

            var combined = tools.CombinedList(w0, others);

            Assert.Equal(2UL, combined[2].Queue.Data.Texture0[0]);
        }
Пример #3
0
        private void TransferStagedQueueDataToGpu(QueueWrap wrapped, IDrawStageBuffers buffers)
        {
            var v0 = wrapped.BufferPositionOfFirstVertex;
            var vN = wrapped.Queue.Data.NumVerticesUsed;

            buffers.CopyVertexBufferSegmentToGpu(v0, vN);

            var i0 = wrapped.BufferPositionOfFirstIndex;
            var iN = wrapped.Queue.Data.NumIndicesUsed;

            buffers.CopyIndexBufferSegmentToGpu(i0, iN);
        }
Пример #4
0
        public void DrawBatcherTools_GenerateTheNextBatch_ConsumesOneRequestButSkipsQueueDueToInactive()
        {
            IDrawStageBatcherTools tools = new DrawStageBatcherTools();

            var messenger = Substitute.For <IFrameworkMessenger>();

            var q0 = new DrawQueue(messenger, new ComparerCollection(), 12, 4, false);

            Add(q0, FillType.Coloured, 12UL, 0UL, TextureCoordinateMode.Mirror, TextureCoordinateMode.Mirror, 3);
            Add(q0, FillType.Coloured, 12UL, 0UL, TextureCoordinateMode.Mirror, TextureCoordinateMode.Mirror, 3);
            Add(q0, FillType.Coloured, 12UL, 0UL, TextureCoordinateMode.Mirror, TextureCoordinateMode.Mirror, 11);
            var w0 = new QueueWrap {
                Id = 0, BufferPositionOfFirstIndex = 0, BufferPositionOfFirstVertex = 0, Queue = q0
            };

            var q1 = new DrawQueue(messenger, new ComparerCollection(), 12, 4, false);

            Add(q1, FillType.Coloured, 1UL, 0UL, TextureCoordinateMode.Mirror, TextureCoordinateMode.Mirror, 9, 1.0f);
            var w1 = new QueueWrap {
                Id = 0, BufferPositionOfFirstIndex = 0, BufferPositionOfFirstVertex = 0, Queue = q1
            };

            var q2 = new DrawQueue(messenger, new ComparerCollection(), 12, 4, false);

            Add(q2, FillType.Coloured, 2UL, 0UL, TextureCoordinateMode.Mirror, TextureCoordinateMode.Mirror, 10, 0.5f);
            var w2 = new QueueWrap {
                Id = 0, BufferPositionOfFirstIndex = 0, BufferPositionOfFirstVertex = 0, Queue = q2
            };

            var others = new List <QueueWrap> {
                w1, w2
            };
            var combined = tools.CombinedList(w0, others).ToArray();

            var num = 3;

            var pool = new DrawingBatch[]
            {
                new DrawingBatch()
            };

            tools.GenerateTheNextBatch(pool, 1, 0, ref num, combined, new int[] { 0, 0, 0 }, 3, new bool[] { true, false, true }, new int[] { 0, 0, 0 }, new bool[] { true, false, true });

            var batch = pool[0];

            Assert.Equal(1UL, batch.Texture0);
            Assert.Equal(3, batch.NumIndices);
        }
Пример #5
0
        public void DrawBatcherTools_IdentifyActiveInLayer_SimpleTest()
        {
            IDrawStageBatcherTools tools = new DrawStageBatcherTools();

            var messenger = Substitute.For <IFrameworkMessenger>();

            var q0 = new DrawQueue(messenger, new ComparerCollection(), 12, 4, false);

            Add(q0, FillType.Coloured, 0UL, 0UL, TextureCoordinateMode.Mirror, TextureCoordinateMode.Mirror, 3);
            var w0 = new QueueWrap {
                Id = 0, BufferPositionOfFirstIndex = 0, BufferPositionOfFirstVertex = 0, Queue = q0
            };

            var q1 = new DrawQueue(messenger, new ComparerCollection(), 12, 4, false);

            Add(q1, FillType.Coloured, 1UL, 0UL, TextureCoordinateMode.Mirror, TextureCoordinateMode.Mirror, 10);
            var w1 = new QueueWrap {
                Id = 0, BufferPositionOfFirstIndex = 0, BufferPositionOfFirstVertex = 0, Queue = q1
            };

            var q2 = new DrawQueue(messenger, new ComparerCollection(), 12, 4, false);

            Add(q2, FillType.Coloured, 2UL, 0UL, TextureCoordinateMode.Mirror, TextureCoordinateMode.Mirror, 10);
            var w2 = new QueueWrap {
                Id = 0, BufferPositionOfFirstIndex = 0, BufferPositionOfFirstVertex = 0, Queue = q2
            };

            var others = new List <QueueWrap> {
                w1, w2
            };
            var combined = tools.CombinedList(w0, others).ToArray();

            var num = 3;

            var activeInLayer = new bool[3];

            tools.IdentifyWhichQueuesAreActiveInTheCurrentLayer(ref num, combined, new int[] { 0, 0, 0 }, 10, activeInLayer, new bool[] { true, false, true });

            Assert.False(activeInLayer[0]);
            Assert.False(activeInLayer[1]);
            Assert.True(activeInLayer[2]);
        }
Пример #6
0
        public void DrawBatcherTools_FindDeepestAtLowestLayer_SimpleTest()
        {
            IDrawStageBatcherTools tools = new DrawStageBatcherTools();

            var messenger = Substitute.For <IFrameworkMessenger>();

            var q0 = new DrawQueue(messenger, new ComparerCollection(), 12, 4, false);

            Add(q0, FillType.Coloured, 0UL, 0UL, TextureCoordinateMode.Mirror, TextureCoordinateMode.Mirror, 3);
            var w0 = new QueueWrap {
                Id = 0, BufferPositionOfFirstIndex = 0, BufferPositionOfFirstVertex = 0, Queue = q0
            };

            var q1 = new DrawQueue(messenger, new ComparerCollection(), 12, 4, false);

            Add(q1, FillType.Coloured, 1UL, 0UL, TextureCoordinateMode.Mirror, TextureCoordinateMode.Mirror, 10, 1.0f);
            var w1 = new QueueWrap {
                Id = 0, BufferPositionOfFirstIndex = 0, BufferPositionOfFirstVertex = 0, Queue = q1
            };

            var q2 = new DrawQueue(messenger, new ComparerCollection(), 12, 4, false);

            Add(q2, FillType.Coloured, 2UL, 0UL, TextureCoordinateMode.Mirror, TextureCoordinateMode.Mirror, 10, 0.5f);
            var w2 = new QueueWrap {
                Id = 0, BufferPositionOfFirstIndex = 0, BufferPositionOfFirstVertex = 0, Queue = q2
            };

            var others = new List <QueueWrap> {
                w1, w2
            };
            var combined = tools.CombinedList(w0, others).ToArray();

            var num = 3;

            var index = tools.FindDeepestQueueAtLowestLayer(ref num, combined, new int[] { 0, 0, 0 }, 10, new bool[] { true, false, true });

            Assert.Equal(2, index);
        }
Пример #7
0
        public void UnpackAndTransferToGpu(QueueWrap wrappedQueue, IDrawStageBuffers buffers)
        {
            UnpackQueueDataIntoStagingArrays(wrappedQueue, buffers);

            TransferStagedQueueDataToGpu(wrappedQueue, buffers);
        }
Пример #8
0
        private void UnpackQueueDataIntoStagingArrays(QueueWrap wrappedQueue, IDrawStageBuffers buffers)
        {
            var queue = wrappedQueue.Queue.Data;

            var minRequiredSizeOfVertexBuffer = wrappedQueue.BufferPositionOfFirstVertex + queue.NumVerticesUsed;
            var minRequiredSizeOfIndexBuffer  = wrappedQueue.BufferPositionOfFirstIndex + queue.NumIndicesUsed;

            buffers.EnsureVertexBufferIsLargeEnough(minRequiredSizeOfVertexBuffer, true);
            buffers.EnsureIndexBufferIsLargeEnough(minRequiredSizeOfIndexBuffer, true);

            var posVertex = wrappedQueue.BufferPositionOfFirstVertex;
            var posIndex  = wrappedQueue.BufferPositionOfFirstIndex;

            for (var req = 0; req < queue.NumRequests; req++)
            {
                var r = queue.Ordering[req];

                var isWorld     = queue.Targets[r] == CoordinateSpace.World;
                var textureType = queue.Types[r] == FillType.Coloured ? 0 : queue.Types[r] == FillType.Textured ? 1 : 2;
                var baseColour  = queue.BaseColours[r];

                var nV = queue.NumVertices[r];
                var v0 = queue.FirstVertexPosition[r];

                var layer = queue.Layers[r];
                var depth = queue.Depths[r];

                var firstVertex = posVertex;

                for (var v = 0; v < nV; v++)
                {
                    var qPos = v0 + v;

                    var vert = queue.Vertices[qPos];

                    var mixedColour = MixColour(baseColour, vert.Colour);

                    buffers.CopyAVertexToStagingArray(posVertex,
                                                      isWorld,
                                                      textureType,
                                                      vert.Position,
                                                      layer,
                                                      depth,
                                                      mixedColour,
                                                      vert.TexCoord0,
                                                      vert.TexCoord1,
                                                      vert.TexWeighting,
                                                      false);
                    posVertex++;
                }

                var nI = queue.NumIndices[r];
                var i0 = queue.FirstIndexPosition[r];

                for (var i = 0; i < nI; i++)
                {
                    var qPos = i0 + i;

                    var index = (uint)(queue.Indices[qPos] + firstVertex);

                    var pos = (uint)posIndex;

                    //Stopped using ref overload, originally as had trouble testing with nsub, but then realised copy for ints is fine here)
                    buffers.CopyAnIndexToStagingArray(pos, index, false);

                    posIndex++;
                }
            }
        }