public void TestCreation() { // Define variables and constants VertexBufferBuilder <int> defaultBuilder = BufferFactory.NewVertexBuffer <int>().WithLength(1); VertexBufferBuilder <int> builderWithFrequentWrite = defaultBuilder.WithUsage(ResourceUsage.DiscardWrite); VertexBufferBuilder <int> builderWith300Verts = builderWithFrequentWrite.WithLength(300); VertexBufferBuilder <int> builderWithInitData = defaultBuilder.WithInitialData(Enumerable.Range(0, 10).ToArray()); VertexBufferBuilder <long> builderWith200LongVert = builderWithFrequentWrite.WithVertexType <long>().WithLength(200); // Set up context // Execute VertexBuffer <int> withFreqWriteBuffer = builderWithFrequentWrite; VertexBuffer <int> with300VertBuffer = builderWith300Verts; VertexBuffer <int> withInitDataBuffer = builderWithInitData; VertexBuffer <long> with200LongBuffer = builderWith200LongVert; // Assert outcome Assert.AreEqual(ResourceUsage.DiscardWrite, withFreqWriteBuffer.Usage); Assert.AreEqual(300U, with300VertBuffer.Length); Assert.AreEqual(10U, withInitDataBuffer.Length); Assert.AreEqual(200U * sizeof(long), with200LongBuffer.Size.InBytes); try { builderWithInitData.WithUsage(ResourceUsage.StagingRead); Assert.Fail(); } catch (ArgumentException) { } withFreqWriteBuffer.Dispose(); with300VertBuffer.Dispose(); withInitDataBuffer.Dispose(); with200LongBuffer.Dispose(); }
public unsafe void TestSetShaderVertexBuffers() { VertexBufferBuilder <Vector3> vbBuilder = BufferFactory.NewVertexBuffer <Vector3>() .WithLength(100U) .WithUsage(ResourceUsage.DiscardWrite); VertexBuffer <Vector3> vb0 = vbBuilder.Create(); VertexBuffer <Vector2> vb2 = vbBuilder.WithVertexType <Vector2>().Create(); ConstantBuffer <Matrix> vpTransBuffer = BufferFactory.NewConstantBuffer <Matrix>().WithUsage(ResourceUsage.DiscardWrite); VertexShader shader = new VertexShader( @"Tests\SimpleVS.cso", new VertexInputBinding(8U, "Instance"), new ConstantBufferBinding(0U, "VPTB", vpTransBuffer), new VertexInputBinding(0U, "VB0"), new VertexInputBinding(1U, "VB1"), new VertexInputBinding(2U, "VB2") ); Dictionary <VertexInputBinding, IVertexBuffer> vbDict = new Dictionary <VertexInputBinding, IVertexBuffer>(); vbDict[shader.InputBindings[0]] = vb0; vbDict[shader.InputBindings[2]] = vb2; RenderCommand testCommand = RenderCommand.SetShaderVertexBuffers(shader, vbDict); Assert.AreEqual(RenderCommandInstruction.SetVertexBuffers, testCommand.Instruction); ResourceHandle *resHandleArray = (ResourceHandle *)new IntPtr(UnsafeUtils.Reinterpret <RenderCommandArgument, long>(testCommand.Arg1, sizeof(long))); Assert.AreEqual(vb0.ResourceHandle, resHandleArray[0]); Assert.AreEqual(ResourceHandle.NULL, resHandleArray[1]); Assert.AreEqual(vb2.ResourceHandle, resHandleArray[2]); uint *bufferStrideArray = (uint *)new IntPtr(UnsafeUtils.Reinterpret <RenderCommandArgument, long>(testCommand.Arg2, sizeof(long))); Assert.AreEqual((uint)sizeof(Vector3), bufferStrideArray[0]); Assert.AreEqual(0U, bufferStrideArray[1]); Assert.AreEqual((uint)sizeof(Vector2), bufferStrideArray[2]); Assert.AreEqual((RenderCommandArgument)9U, testCommand.Arg3); #if !DEVELOPMENT && !RELEASE try { RenderCommand.SetShaderVertexBuffers(null, vbDict); Assert.Fail(); } catch (AssuranceFailedException) { } try { RenderCommand.SetShaderVertexBuffers(shader, null); Assert.Fail(); } catch (AssuranceFailedException) { } #endif vb0.Dispose(); vb2.Dispose(); vpTransBuffer.Dispose(); vpTransBuffer.Dispose(); #if !DEVELOPMENT && !RELEASE try { RenderCommand.SetShaderVertexBuffers(shader, vbDict); Assert.Fail(); } catch (AssuranceFailedException) { } #endif shader.Dispose(); #if !DEVELOPMENT && !RELEASE try { RenderCommand.SetShaderVertexBuffers(shader, new Dictionary <VertexInputBinding, IVertexBuffer>()); Assert.Fail(); } catch (AssuranceFailedException) { } #endif }