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) })); }
public void RenderInstanced() { inputAssembler.InputLayout = inputLayout; foreach (ShapeData s in shapes.Values) { inputAssembler.SetVertexBuffers(0, s.BufferBindings); inputAssembler.PrimitiveTopology = s.PrimitiveTopology; if (s.IndexBuffer != null) { inputAssembler.SetIndexBuffer(s.IndexBuffer, s.IndexFormat, 0); device.ImmediateContext.DrawIndexedInstanced(s.IndexCount, s.InstanceDataList.Count, 0, 0, 0); } else { device.ImmediateContext.DrawInstanced(s.VertexCount, s.InstanceDataList.Count, 0, 0); } } }
void RenderLights() { inputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList; inputAssembler.InputLayout = lightVolumeInputLayout; inputAssembler.SetVertexBuffers(0, pointLightVolumeVertexBufferBinding); inputAssembler.SetIndexBuffer(pointLightVolumeIndexBuffer, Format.R32_UInt, 0); lightDepthBufferVar.SetResource(depthBufferRes); lightNormalBufferVar.SetResource(normalBufferRes); Vector3 eyePosition = MathHelper.Convert(Demo.Freelook.Eye); var previousState = _immediateContext.Rasterizer.State; // Camera outside light volume _immediateContext.Rasterizer.State = backCullState; outputMerger.SetDepthStencilState(outsideLightVolumeDepthState); foreach (var light in lights) { float radius = light.Radius; float bias = radius * 2; if ((light.Position - eyePosition).LengthSquared() >= (radius * radius) + bias) { RenderLight(light); } } // Camera inside light volume _immediateContext.Rasterizer.State = frontCullState; outputMerger.SetDepthStencilState(insideLightVolumeDepthState); foreach (var light in lights) { float bias = light.Radius * 2; if ((light.Position - eyePosition).LengthSquared() < (light.Radius * light.Radius) + bias) { RenderLight(light); } } _immediateContext.Rasterizer.State = previousState; }
/// <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); }
internal void Apply(InputAssemblerStage inputAssemblerStage) { inputAssemblerStage.SetVertexBuffers(0, nativeVertexBufferBindings); inputAssemblerStage.SetIndexBuffer(nativeIndexBuffer, indexFormat, indexBufferOffset); }
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); }