コード例 #1
0
        public void CanGetVertexStreamForIndexedLineList()
        {
            // Arrange.
            var device         = new Device();
            var inputAssembler = new InputAssemblerStage(device);
            var inputSignature = GetTestVertexPositionNormalTextureShaderBytecode();

            inputAssembler.InputLayout       = new InputLayout(device, TestVertex.PositionNormalTexture.InputElements, inputSignature);
            inputAssembler.PrimitiveTopology = PrimitiveTopology.LineList;
            var vertices = new[]
            {
                new TestVertex.PositionNormalTexture(),
                new TestVertex.PositionNormalTexture(),

                new TestVertex.PositionNormalTexture(new Vector3(1, 2, 3), new Vector3(3, 2, 1), new Vector2(3, 4)),
                new TestVertex.PositionNormalTexture(new Vector3(4, 5, 6), new Vector3(4, 6, 8), new Vector2(0.5f, 0.3f))
            };
            var vertexBuffer = device.CreateBuffer(new BufferDescription(BindFlags.VertexBuffer), vertices);

            inputAssembler.SetVertexBuffers(0, new[]
            {
                new VertexBufferBinding(vertexBuffer, 0, TestVertex.PositionNormalTexture.SizeInBytes)
            });
            var indexBuffer = device.CreateBuffer(new BufferDescription(BindFlags.IndexBuffer), new ushort[] { 2, 16, 1, 0 });

            inputAssembler.SetIndexBuffer(indexBuffer, Format.R16_UInt, 2);

            // Act.
            var vertexStream = inputAssembler.GetVertexStreamIndexed(inputSignature, 2, 1, 2).ToList();

            // Assert.
            Assert.That(vertexStream, Has.Count.EqualTo(2));

            Assert.That(vertexStream[0].InstanceID, Is.EqualTo(0));
            Assert.That(vertexStream[0].VertexID, Is.EqualTo(1));
            Assert.That(vertexStream[0].Data, Is.EqualTo(new[]
            {
                new Number4(4.0f, 5.0f, 6.0f, 0.0f),
                new Number4(4.0f, 6.0f, 8.0f, 0.0f),
                new Number4(0.5f, 0.3f, 0.0f, 0.0f)
            }));

            Assert.That(vertexStream[1].InstanceID, Is.EqualTo(0));
            Assert.That(vertexStream[1].VertexID, Is.EqualTo(2));
            Assert.That(vertexStream[1].Data, Is.EqualTo(new[]
            {
                new Number4(1.0f, 2.0f, 3.0f, 0.0f),
                new Number4(3.0f, 2.0f, 1.0f, 0.0f),
                new Number4(3.0f, 4.0f, 0.0f, 0.0f)
            }));
        }
コード例 #2
0
ファイル: DeviceContext.cs プロジェクト: prepare/rasterizr
 public void DrawIndexed(int indexCount, int startIndexLocation, int baseVertexLocation)
 {
     DiagnosticUtilities.RaiseEvent(this, DrawingIndexed, indexCount, startIndexLocation, baseVertexLocation);
     DrawInternal(_inputAssembler.GetVertexStreamIndexed(_vertexShader.Shader.Bytecode.InputSignature, indexCount, startIndexLocation, baseVertexLocation));
 }