Exemple #1
0
        private void CreateDeviceAndSwapChain()
        {
            var desc = new SwapChainDescription
            {
                BufferCount       = 1,
                ModeDescription   = new ModeDescription(_width, _height, new Rational(60, 1), Format.R8G8B8A8_UNorm),
                IsWindowed        = true,
                OutputHandle      = Form.Handle,
                SampleDescription = new SampleDescription(1, 0),
                SwapEffect        = SwapEffect.Discard,
                Usage             = Usage.RenderTargetOutput,
                Flags             = SwapChainFlags.AllowModeSwitch
            };

            Device _device;

            Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.SingleThreaded, desc, out _device, out _swapChain);
            Device = _device;

            _immediateContext = Device.ImmediateContext;
            outputMerger      = _immediateContext.OutputMerger;
            inputAssembler    = _immediateContext.InputAssembler;

            Factory factory = _swapChain.GetParent <Factory>();

            factory.MakeWindowAssociation(Form.Handle, WindowAssociationFlags.None);
        }
Exemple #2
0
        public MeshFactory(Demo demo)
        {
            this.demo           = demo;
            this.device         = demo.Device;
            this.inputAssembler = device.ImmediateContext.InputAssembler;

            instanceDataDesc = new BufferDescription()
            {
                Usage          = ResourceUsage.Dynamic,
                BindFlags      = BindFlags.VertexBuffer,
                CpuAccessFlags = CpuAccessFlags.Write,
                OptionFlags    = ResourceOptionFlags.None,
            };

            InputElement[] elements = new InputElement[]
            {
                new InputElement("POSITION", 0, Format.R32G32B32_Float, 0, 0, InputClassification.PerVertexData, 0),
                new InputElement("NORMAL", 0, Format.R32G32B32_Float, 12, 0, InputClassification.PerVertexData, 0),
                new InputElement("WORLD", 0, Format.R32G32B32A32_Float, 0, 1, InputClassification.PerInstanceData, 1),
                new InputElement("WORLD", 1, Format.R32G32B32A32_Float, 16, 1, InputClassification.PerInstanceData, 1),
                new InputElement("WORLD", 2, Format.R32G32B32A32_Float, 32, 1, InputClassification.PerInstanceData, 1),
                new InputElement("WORLD", 3, Format.R32G32B32A32_Float, 48, 1, InputClassification.PerInstanceData, 1),
                new InputElement("COLOR", 0, Format.R8G8B8A8_UNorm, 64, 1, InputClassification.PerInstanceData, 1)
            };
            inputLayout = new InputLayout(device, demo.GetEffectPass().Description.Signature, elements);
        }
Exemple #3
0
        public PhysicsDebugDraw(DeviceManager manager)
        {
            device         = manager.Direct3DDevice;
            inputAssembler = device.ImmediateContext.InputAssembler;
            lineArray      = new PositionColored[0];

            using (var bc = HLSLCompiler.CompileFromFile(@"Shaders\PhysicsDebug.hlsl", "VSMain", "vs_5_0"))
            {
                vertexShader = new VertexShader(device, bc);

                InputElement[] elements = new InputElement[]
                {
                    new InputElement("SV_POSITION", 0, Format.R32G32B32_Float, 0, 0, InputClassification.PerVertexData, 0),
                    new InputElement("COLOR", 0, Format.R8G8B8A8_UNorm, 12, 0, InputClassification.PerVertexData, 0)
                };
                inputLayout = new InputLayout(device, bc, elements);
            }

            vertexBufferDesc = new BufferDescription()
            {
                Usage          = ResourceUsage.Dynamic,
                BindFlags      = BindFlags.VertexBuffer,
                CpuAccessFlags = CpuAccessFlags.Write
            };

            vertexBufferBinding = new VertexBufferBinding(null, PositionColored.Stride, 0);

            using (var bc = HLSLCompiler.CompileFromFile(@"Shaders\PhysicsDebug.hlsl", "PSMain", "ps_5_0"))
                pixelShader = new PixelShader(device, bc);
        }
        public MeshFactory(SharpDX11Graphics graphics)
        {
            this.device         = graphics.Device;
            this.inputAssembler = device.ImmediateContext.InputAssembler;
            this.demo           = graphics.Demo;

            instanceDataDesc = new BufferDescription()
            {
                Usage          = ResourceUsage.Dynamic,
                BindFlags      = BindFlags.VertexBuffer,
                CpuAccessFlags = CpuAccessFlags.Write,
                OptionFlags    = ResourceOptionFlags.None,
            };

            InputElement[] elements = new InputElement[]
            {
                new InputElement("POSITION", 0, Format.R32G32B32_Float, 0, 0, InputClassification.PerVertexData, 0),
                new InputElement("NORMAL", 0, Format.R32G32B32_Float, 12, 0, InputClassification.PerVertexData, 0),
                new InputElement("WORLD", 0, Format.R32G32B32A32_Float, 0, 1, InputClassification.PerInstanceData, 1),
                new InputElement("WORLD", 1, Format.R32G32B32A32_Float, 16, 1, InputClassification.PerInstanceData, 1),
                new InputElement("WORLD", 2, Format.R32G32B32A32_Float, 32, 1, InputClassification.PerInstanceData, 1),
                new InputElement("WORLD", 3, Format.R32G32B32A32_Float, 48, 1, InputClassification.PerInstanceData, 1),
                new InputElement("COLOR", 0, Format.R8G8B8A8_UNorm, 64, 1, InputClassification.PerInstanceData, 1)
            };
            inputLayout = new InputLayout(device, graphics.GetEffectPass().Description.Signature, elements);

            groundColor   = ColorToUint(Color.Green);
            activeColor   = ColorToUint(Color.Orange);
            passiveColor  = ColorToUint(Color.OrangeRed);
            softBodyColor = ColorToUint(Color.LightBlue);
        }
Exemple #5
0
        public void CanBindMultipleVertexBuffers()
        {
            // Arrange.
            var device         = new Device();
            var inputAssembler = new InputAssemblerStage(device);
            var vertices       = new[]
            {
                new TestVertex.PositionNormalTexture(Vector3.Zero, Vector3.Zero, Vector2.Zero),
                new TestVertex.PositionNormalTexture(Vector3.Zero, Vector3.Zero, Vector2.Zero)
            };
            var vertexBuffer1 = device.CreateBuffer(new BufferDescription(BindFlags.VertexBuffer), vertices);
            var vertexBuffer2 = device.CreateBuffer(new BufferDescription(BindFlags.VertexBuffer), vertices);

            // Act.
            inputAssembler.SetVertexBuffers(0, new[]
            {
                new VertexBufferBinding(vertexBuffer1, 0, TestVertex.PositionNormalTexture.SizeInBytes),
                new VertexBufferBinding(vertexBuffer2, 0, TestVertex.PositionNormalTexture.SizeInBytes)
            });

            // Assert.
            var vertexBufferBindings = new VertexBufferBinding[2];

            inputAssembler.GetVertexBuffers(0, 2, vertexBufferBindings);
            Assert.That(vertexBufferBindings[0].Buffer, Is.EqualTo(vertexBuffer1));
            Assert.That(vertexBufferBindings[1].Buffer, Is.EqualTo(vertexBuffer2));
        }
Exemple #6
0
        protected virtual void OnInitializeDevice()
        {
            Form.ClientSize = new System.Drawing.Size(Width, Height);

            // SwapChain description
            var desc = new SwapChainDescription()
            {
                BufferCount       = 1,
                ModeDescription   = new ModeDescription(Width, Height, new Rational(60, 1), Format.R8G8B8A8_UNorm),
                IsWindowed        = true,
                OutputHandle      = Form.Handle,
                SampleDescription = new SampleDescription(1, 0),
                SwapEffect        = SwapEffect.Discard,
                Usage             = Usage.RenderTargetOutput
            };

            // Create Device and SwapChain
            Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.None, desc, out _device, out _swapChain);
            outputMerger   = _device.OutputMerger;
            inputAssembler = _device.InputAssembler;

            Factory factory = _swapChain.GetParent <Factory>();

            factory.MakeWindowAssociation(Form.Handle, WindowAssociationFlags.None);
        }
Exemple #7
0
        public void CanGetVertexStreamForLineListWithMultipleVertexBuffers()
        {
            // Arrange.
            var device         = new Device();
            var inputAssembler = new InputAssemblerStage(device);
            var inputSignature = GetTestVertexPositionNormalTextureShaderBytecode();
            var inputElements  = TestVertex.PositionNormal.InputElements
                                 .Union(new[] { new InputElement("TEXCOORD", 0, Format.R32G32_Float, 1, 0) })
                                 .ToArray();

            inputAssembler.InputLayout       = new InputLayout(device, inputElements, inputSignature);
            inputAssembler.PrimitiveTopology = PrimitiveTopology.LineList;
            var positionsAndNormals = new[]
            {
                new TestVertex.PositionNormal(new Vector3(1, 2, 3), new Vector3(3, 2, 1)),
                new TestVertex.PositionNormal(new Vector3(4, 5, 6), new Vector3(4, 6, 8))
            };
            var texCoords = new[]
            {
                new Vector2(3, 4),
                new Vector2(0.5f, 0.3f)
            };

            inputAssembler.SetVertexBuffers(0, new[]
            {
                new VertexBufferBinding(device.CreateBuffer(new BufferDescription(BindFlags.VertexBuffer), positionsAndNormals),
                                        0, TestVertex.PositionNormal.SizeInBytes),
                new VertexBufferBinding(device.CreateBuffer(new BufferDescription(BindFlags.VertexBuffer), texCoords),
                                        0, Vector2.SizeInBytes)
            });

            // Act.
            var vertexStream = inputAssembler.GetVertexStream(inputSignature, 2, 0).ToList();

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

            Assert.That(vertexStream[0].InstanceID, Is.EqualTo(0));
            Assert.That(vertexStream[0].VertexID, Is.EqualTo(0));
            Assert.That(vertexStream[0].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)
            }));

            Assert.That(vertexStream[1].InstanceID, Is.EqualTo(0));
            Assert.That(vertexStream[1].VertexID, Is.EqualTo(1));
            Assert.That(vertexStream[1].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)
            }));
        }
Exemple #8
0
 internal DeviceContext(Device device)
     : base(device)
 {
     _device         = device;
     _inputAssembler = new InputAssemblerStage(device);
     _vertexShader   = new VertexShaderStage(device);
     _geometryShader = new GeometryShaderStage(device);
     _rasterizer     = new RasterizerStage(device);
     _pixelShader    = new PixelShaderStage(device);
     _outputMerger   = new OutputMergerStage(device);
 }
Exemple #9
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)
            }));
        }
Exemple #10
0
        protected void OnInitializeDevice()
        {
            Form.ClientSize = new Size(Width, Height);

            // SwapChain description
            var desc = new SwapChainDescription()
            {
                BufferCount       = 1,
                ModeDescription   = new ModeDescription(Width, Height, new Rational(60, 1), Format.R8G8B8A8_UNorm),
                IsWindowed        = true,
                OutputHandle      = Form.Handle,
                SampleDescription = new SampleDescription(1, 0),
                SwapEffect        = SwapEffect.Discard,
                Usage             = Usage.RenderTargetOutput,
            };

            // Create Device and SwapChain
            SharpDX.Direct3D11.Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.None, desc, out _device, out _swapChain);
            _immediateContext = _device.ImmediateContext;
            outputMerger      = _immediateContext.OutputMerger;
            inputAssembler    = _immediateContext.InputAssembler;

            Factory factory = _swapChain.GetParent <Factory>();

            factory.MakeWindowAssociation(Form.Handle, WindowAssociationFlags.None);


            var blendStateDesc = new BlendStateDescription();

            blendStateDesc.RenderTarget[0].IsBlendEnabled        = true;
            blendStateDesc.RenderTarget[0].SourceBlend           = BlendOption.SourceAlpha;
            blendStateDesc.RenderTarget[0].DestinationBlend      = BlendOption.InverseSourceAlpha;
            blendStateDesc.RenderTarget[0].BlendOperation        = BlendOperation.Add;
            blendStateDesc.RenderTarget[0].SourceAlphaBlend      = BlendOption.One;
            blendStateDesc.RenderTarget[0].DestinationAlphaBlend = BlendOption.Zero;
            blendStateDesc.RenderTarget[0].AlphaBlendOperation   = BlendOperation.Add;
            blendStateDesc.RenderTarget[0].RenderTargetWriteMask = ColorWriteMaskFlags.All;
            alphaBlendState = new BlendState(_device, blendStateDesc);

            blendStateDesc.RenderTarget[0].IsBlendEnabled        = true;
            blendStateDesc.RenderTarget[0].SourceBlend           = BlendOption.One;
            blendStateDesc.RenderTarget[0].DestinationBlend      = BlendOption.One;
            blendStateDesc.RenderTarget[0].BlendOperation        = BlendOperation.Add;
            blendStateDesc.RenderTarget[0].SourceAlphaBlend      = BlendOption.One;
            blendStateDesc.RenderTarget[0].DestinationAlphaBlend = BlendOption.Zero;
            blendStateDesc.RenderTarget[0].AlphaBlendOperation   = BlendOperation.Add;
            blendStateDesc.RenderTarget[0].RenderTargetWriteMask = ColorWriteMaskFlags.All;
            additiveBlendState = new BlendState(_device, blendStateDesc);
        }
Exemple #11
0
        public void CanGetVertexStreamForTriangleListWithNoBuffersBound()
        {
            // Arrange.
            var device         = new Device();
            var inputAssembler = new InputAssemblerStage(device);

            inputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
            var inputSignature = new InputSignatureChunk
            {
                Parameters =
                {
                    new SignatureParameterDescription("SV_VertexID",                                      0, Name.VertexID,   RegisterComponentType.UInt32,
                                                      0,                                    ComponentMask.X, ComponentMask.X),
                    new SignatureParameterDescription("SV_InstanceID",                                    0, Name.InstanceID, RegisterComponentType.UInt32,
                                                      1,                                    ComponentMask.X, ComponentMask.X),
                }
            };

            // Act.
            var vertexStream = inputAssembler.GetVertexStream(inputSignature, 3, 0).ToList();

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

            Assert.That(vertexStream[0].InstanceID, Is.EqualTo(0));
            Assert.That(vertexStream[0].VertexID, Is.EqualTo(0));
            Assert.That(vertexStream[0].Data, Is.EqualTo(new[]
            {
                new Number4(0.0f, 0, 0, 0),
                new Number4(0.0f, 0, 0, 0)
            }));

            Assert.That(vertexStream[1].InstanceID, Is.EqualTo(0));
            Assert.That(vertexStream[1].VertexID, Is.EqualTo(1));
            Assert.That(vertexStream[1].Data, Is.EqualTo(new[]
            {
                new Number4(1.0f, 0, 0, 0),
                new Number4(0.0f, 0, 0, 0)
            }));

            Assert.That(vertexStream[2].InstanceID, Is.EqualTo(0));
            Assert.That(vertexStream[2].VertexID, Is.EqualTo(2));
            Assert.That(vertexStream[2].Data, Is.EqualTo(new[]
            {
                new Number4(2.0f, 0, 0, 0),
                new Number4(0.0f, 0, 0, 0)
            }));
        }
        public PhysicsDebugDraw(SharpDXGraphics graphics)
        {
            device         = graphics.Device;
            inputAssembler = device.InputAssembler;

            InputElement[] elements = new InputElement[]
            {
                new InputElement("POSITION", 0, Format.R32G32B32_Float, 0, 0, InputClassification.PerVertexData, 0),
                new InputElement("COLOR", 0, Format.R8G8B8A8_UNorm, 12, 0, InputClassification.PerVertexData, 0)
            };
            inputLayout = new InputLayout(device, graphics.GetDebugDrawPass().Description.Signature, elements);

            vertexBufferDesc = new BufferDescription()
            {
                Usage          = ResourceUsage.Dynamic,
                BindFlags      = BindFlags.VertexBuffer,
                CpuAccessFlags = CpuAccessFlags.Write
            };

            vertexBufferBinding = new VertexBufferBinding(null, PositionColored.Stride, 0);
        }
Exemple #13
0
        public MeshFactory(Demo demo)
        {
            this.demo           = demo;
            this.device         = demo.Device;
            this.inputAssembler = device.InputAssembler;

            instanceDataDesc = new BufferDescription()
            {
                SizeInBytes    = 0,
                Usage          = ResourceUsage.Dynamic,
                BindFlags      = BindFlags.VertexBuffer,
                CpuAccessFlags = CpuAccessFlags.Write,
                OptionFlags    = ResourceOptionFlags.None,
            };

            InputElement[] elements = new InputElement[]
            {
                new InputElement("POSITION", 0, Format.R32G32B32_Float, 0, 0, InputClassification.PerVertexData, 0),
                new InputElement("NORMAL", 0, Format.R32G32B32_Float, 12, 0, InputClassification.PerVertexData, 0),
                new InputElement("WORLD", 0, Format.R32G32B32A32_Float, 0, 1, InputClassification.PerInstanceData, 1),
                new InputElement("WORLD", 1, Format.R32G32B32A32_Float, 16, 1, InputClassification.PerInstanceData, 1),
                new InputElement("WORLD", 2, Format.R32G32B32A32_Float, 32, 1, InputClassification.PerInstanceData, 1),
                new InputElement("WORLD", 3, Format.R32G32B32A32_Float, 48, 1, InputClassification.PerInstanceData, 1),
                new InputElement("COLOR", 0, Format.R8G8B8A8_UNorm, 64, 1, InputClassification.PerInstanceData, 1)
            };
            inputLayout = new InputLayout(device, demo.GetShadowGenPass().Description.Signature, elements);

            Color c = Color.Green;

            groundColor   = (uint)c.R + ((uint)c.G << 8) + ((uint)c.B << 16) + ((uint)c.A << 24);
            c             = Color.Orange;
            activeColor   = (uint)c.R + ((uint)c.G << 8) + ((uint)c.B << 16) + ((uint)c.A << 24);
            c             = Color.OrangeRed;
            passiveColor  = (uint)c.R + ((uint)c.G << 8) + ((uint)c.B << 16) + ((uint)c.A << 24);
            c             = Color.LightBlue;
            softBodyColor = (uint)c.R + ((uint)c.G << 8) + ((uint)c.B << 16) + ((uint)c.A << 24);
        }
Exemple #14
0
 /// <summary>
 /// Sets an index buffer using a binding.
 /// </summary>
 /// <param name="inputAssembler">Assembler to set.</param>
 /// <param name="binding">Binding to set to the device for indices.</param>
 /// <param name="offset">Offset from the beginning of the index buffer to start reading.</param>
 public static void SetIndexBuffer(this InputAssemblerStage inputAssembler, IndexBuffer binding, int offset = 0)
 {
     inputAssembler.SetIndexBuffer(binding.Buffer, binding.Format, offset);
 }
Exemple #15
0
        public void CanGetVertexStreamForInstancedLineList()
        {
            // Arrange.
            var device         = new Device();
            var inputAssembler = new InputAssemblerStage(device);
            var inputSignature = GetInstancedTestVertexPositionNormalShaderBytecode();
            var inputElements  = TestVertex.PositionNormal.InputElements
                                 .Union(new[]
            {
                new InputElement("INSTANCEPOS", 0, Format.R32G32B32_Float, 1, InputElement.AppendAligned,
                                 InputClassification.PerInstanceData, 1),
                new InputElement("INSTANCESCALE", 0, Format.R32G32B32_Float, 1, InputElement.AppendAligned,
                                 InputClassification.PerInstanceData, 1),
                new InputElement("INSTANCECOLOR", 0, Format.R32G32B32_Float, 2, InputElement.AppendAligned,
                                 InputClassification.PerInstanceData, 2)
            })
                                 .ToArray();

            inputAssembler.InputLayout       = new InputLayout(device, inputElements, inputSignature);
            inputAssembler.PrimitiveTopology = PrimitiveTopology.LineList;
            var positionsAndNormals = new[]
            {
                new TestVertex.PositionNormal(new Vector3(1, 2, 3), new Vector3(3, 2, 1)),
                new TestVertex.PositionNormal(new Vector3(4, 5, 6), new Vector3(4, 6, 8))
            };
            var instancePositions = new[]
            {
                new Vector3(0, 0, 0),
                new Vector3(0, 0, 0),

                new Vector3(-2, 3, 16),               // Position
                new Vector3(1, 1, 1),                 // Scale

                new Vector3(5, 3, 11),
                new Vector3(2, 2, 2),

                new Vector3(2, 5, 10),
                new Vector3(3, 3, 3),

                new Vector3(12, 15, 8),
                new Vector3(0.5f, 0.5f, 0.5f)
            };
            var instanceColors = new[]
            {
                new Color3F(0, 0, 0),

                new Color3F(1, 0, 0),
                new Color3F(0, 1, 0)
            };

            inputAssembler.SetVertexBuffers(0, new[]
            {
                new VertexBufferBinding(device.CreateBuffer(new BufferDescription(BindFlags.VertexBuffer), positionsAndNormals),
                                        0, TestVertex.PositionNormal.SizeInBytes),
                new VertexBufferBinding(device.CreateBuffer(new BufferDescription(BindFlags.VertexBuffer), instancePositions),
                                        0, Vector3.SizeInBytes * 2),
                new VertexBufferBinding(device.CreateBuffer(new BufferDescription(BindFlags.VertexBuffer), instanceColors),
                                        0, Color3F.SizeInBytes)
            });

            // Act.
            var vertexStream = inputAssembler.GetVertexStreamInstanced(inputSignature, 2, 4, 0, 1).ToList();

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

            Assert.That(vertexStream[0].InstanceID, Is.EqualTo(0));
            Assert.That(vertexStream[0].VertexID, Is.EqualTo(0));
            Assert.That(vertexStream[0].Data, Is.EqualTo(new[]
            {
                new Number4(1.0f, 2.0f, 3.0f, 0.0f),                        // Position
                new Number4(3.0f, 2.0f, 1.0f, 0.0f),                        // Normal
                new Number4(-2.0f, 3.0f, 16.0f, 0.0f),                      // Instance Pos
                new Number4(1.0f, 1.0f, 1.0f, 0.0f),                        // Instance Scale
                new Number4(1.0f, 0.0f, 0.0f, 0.0f)                         // Instance Colour
            }));

            Assert.That(vertexStream[1].InstanceID, Is.EqualTo(0));
            Assert.That(vertexStream[1].VertexID, Is.EqualTo(1));
            Assert.That(vertexStream[1].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(-2.0f, 3.0f, 16.0f, 0.0f),
                new Number4(1.0f, 1.0f, 1.0f, 0.0f),
                new Number4(1.0f, 0.0f, 0.0f, 0.0f)
            }));

            Assert.That(vertexStream[2].InstanceID, Is.EqualTo(1));
            Assert.That(vertexStream[2].VertexID, Is.EqualTo(0));
            Assert.That(vertexStream[2].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(5.0f, 3.0f, 11.0f, 0.0f),
                new Number4(2.0f, 2.0f, 2.0f, 0.0f),
                new Number4(1.0f, 0.0f, 0.0f, 0.0f)
            }));

            Assert.That(vertexStream[3].InstanceID, Is.EqualTo(1));
            Assert.That(vertexStream[3].VertexID, Is.EqualTo(1));
            Assert.That(vertexStream[3].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(5.0f, 3.0f, 11.0f, 0.0f),
                new Number4(2.0f, 2.0f, 2.0f, 0.0f),
                new Number4(1.0f, 0.0f, 0.0f, 0.0f)
            }));

            Assert.That(vertexStream[4].InstanceID, Is.EqualTo(2));
            Assert.That(vertexStream[4].VertexID, Is.EqualTo(0));
            Assert.That(vertexStream[4].Data, Is.EqualTo(new[]
            {
                new Number4(1.0f, 2.0f, 3.0f, 0.0f),                        // Position
                new Number4(3.0f, 2.0f, 1.0f, 0.0f),                        // Normal
                new Number4(2.0f, 5.0f, 10.0f, 0.0f),                       // Instance Pos
                new Number4(3.0f, 3.0f, 3.0f, 0.0f),                        // Instance Scale
                new Number4(0.0f, 1.0f, 0.0f, 0.0f)                         // Instance Colour
            }));

            Assert.That(vertexStream[5].InstanceID, Is.EqualTo(2));
            Assert.That(vertexStream[5].VertexID, Is.EqualTo(1));
            Assert.That(vertexStream[5].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(2.0f, 5.0f, 10.0f, 0.0f),
                new Number4(3.0f, 3.0f, 3.0f, 0.0f),
                new Number4(0.0f, 1.0f, 0.0f, 0.0f)
            }));

            Assert.That(vertexStream[6].InstanceID, Is.EqualTo(3));
            Assert.That(vertexStream[6].VertexID, Is.EqualTo(0));
            Assert.That(vertexStream[6].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(12.0f, 15.0f, 8.0f, 0.0f),
                new Number4(0.5f, 0.5f, 0.5f, 0.0f),
                new Number4(0.0f, 1.0f, 0.0f, 0.0f)
            }));

            Assert.That(vertexStream[7].InstanceID, Is.EqualTo(3));
            Assert.That(vertexStream[7].VertexID, Is.EqualTo(1));
            Assert.That(vertexStream[7].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(12.0f, 15.0f, 8.0f, 0.0f),
                new Number4(0.5f, 0.5f, 0.5f, 0.0f),
                new Number4(0.0f, 1.0f, 0.0f, 0.0f)
            }));
        }
Exemple #16
0
 internal void Apply(InputAssemblerStage inputAssemblerStage)
 {
     inputAssemblerStage.SetVertexBuffers(0, nativeVertexBufferBindings);
     inputAssemblerStage.SetIndexBuffer(nativeIndexBuffer, indexFormat, indexBufferOffset);
 }
Exemple #17
0
 public void Bind(InputAssemblerStage inputAssembler)
 {
     inputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
     inputAssembler.SetVertexBuffers(0, new VertexBufferBinding(vertexBuffer, VertexInfo.SizeInBytes, 0));
     inputAssembler.SetIndexBuffer(indexBuffer, SharpDX.DXGI.Format.R32_UInt, 0);
 }