当前位置: 首页>>代码示例>>C#>>正文


C# Device.CreateBuffer方法代码示例

本文整理汇总了C#中Device.CreateBuffer方法的典型用法代码示例。如果您正苦于以下问题:C# Device.CreateBuffer方法的具体用法?C# Device.CreateBuffer怎么用?C# Device.CreateBuffer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Device的用法示例。


在下文中一共展示了Device.CreateBuffer方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RenderScene

        private static Number4[] RenderScene(Device device)
		{
			const int width = 200;
			const int height = 100;

			// Create device and swap chain.
            var swapChainPresenter = new RawSwapChainPresenter();
			var swapChain = device.CreateSwapChain(
                new SwapChainDescription(width, height), 
                swapChainPresenter);
			var deviceContext = device.ImmediateContext;

			// Create RenderTargetView from the backbuffer.
			var backBuffer = Texture2D.FromSwapChain(swapChain, 0);
			var renderTargetView = device.CreateRenderTargetView(backBuffer);

			// Compile Vertex and Pixel shaders
			var vertexShaderByteCode = ShaderCompiler.CompileFromFile("Assets/MiniTri.fx", "VS", "vs_4_0");
			var vertexShader = device.CreateVertexShader(vertexShaderByteCode);

			var pixelShaderByteCode = ShaderCompiler.CompileFromFile("Assets/MiniTri.fx", "PS", "ps_4_0");
			var pixelShader = device.CreatePixelShader(pixelShaderByteCode);

			// Layout from VertexShader input signature
			var layout = device.CreateInputLayout(
				new[]
				{
					new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0),
					new InputElement("COLOR", 0, Format.R32G32B32A32_Float, 0)
				}, vertexShaderByteCode);

			// Instantiate Vertex buffer from vertex data
			var vertices = device.CreateBuffer(new BufferDescription(BindFlags.VertexBuffer), new[]
			{
				new Vector4(0.0f, 0.5f, 0.5f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f),
				new Vector4(0.5f, -0.5f, 0.5f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f),
				new Vector4(-0.5f, -0.5f, 0.5f, 1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f)
			});

			// Prepare all the stages
			deviceContext.InputAssembler.InputLayout = layout;
			deviceContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
			deviceContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(vertices, 0, 32));
			deviceContext.VertexShader.Shader = vertexShader;
			deviceContext.Rasterizer.SetViewports(new Viewport(0, 0, width, height, 0.0f, 1.0f));
			deviceContext.PixelShader.Shader = pixelShader;
			deviceContext.OutputMerger.SetTargets(null, renderTargetView);

            deviceContext.ClearRenderTargetView(renderTargetView, Color4.Black);
			deviceContext.Draw(3, 0);
			swapChain.Present();

            return swapChainPresenter.Data;
		}
开发者ID:modulexcite,项目名称:rasterizr,代码行数:54,代码来源:ReplayerTests.cs

示例2: CanBindSingleVertexBuffer

		public void CanBindSingleVertexBuffer()
		{
			// 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 vertexBuffer = device.CreateBuffer(new BufferDescription(BindFlags.VertexBuffer), vertices);

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

			// Assert.
			var vertexBufferBindings = new VertexBufferBinding[1];
			inputAssembler.GetVertexBuffers(0, 1, vertexBufferBindings);
			Assert.That(vertexBufferBindings[0].Buffer, Is.EqualTo(vertexBuffer));
		}
开发者ID:modulexcite,项目名称:rasterizr,代码行数:23,代码来源:InputAssemblerStageTests.cs

示例3: Initialize

        public override WriteableBitmap Initialize(Device device)
		{
			const int width = 600;
			const int height = 400;

			// Create device and swap chain.
            var swapChainPresenter = new WpfSwapChainPresenter();
            _swapChain = device.CreateSwapChain(width, height, swapChainPresenter);
			_deviceContext = device.ImmediateContext;

			// Create RenderTargetView from the backbuffer.
			var backBuffer = Texture2D.FromSwapChain(_swapChain, 0);
			_renderTargetView = device.CreateRenderTargetView(backBuffer);

			// Compile Vertex and Pixel shaders
			var vertexShaderByteCode = ShaderCompiler.CompileFromFile("Modules/SampleBrowser/Samples/BasicTriangle/MiniTri.fx", "VS", "vs_4_0");
			var vertexShader = device.CreateVertexShader(vertexShaderByteCode);

            var pixelShaderByteCode = ShaderCompiler.CompileFromFile("Modules/SampleBrowser/Samples/BasicTriangle/MiniTri.fx", "PS", "ps_4_0");
			var pixelShader = device.CreatePixelShader(pixelShaderByteCode);

			// Layout from VertexShader input signature
			var layout = device.CreateInputLayout(
				new[]
				{
					new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0),
					new InputElement("COLOR", 0, Format.R32G32B32A32_Float, 0)
				}, vertexShaderByteCode);

			// Instantiate Vertex buffer from vertex data
			var vertices = device.CreateBuffer(new BufferDescription(BindFlags.VertexBuffer), new[]
			{
				new Vector4(0.0f, 0.5f, 0.5f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f),
				new Vector4(0.5f, -0.5f, 0.5f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f),
				new Vector4(-0.5f, -0.5f, 0.5f, 1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f)
			});

		    _model = new Model();
		    _model.AddMesh(new ModelMesh
		    {
		        IndexBuffer = device.CreateBuffer(new BufferDescription
		        {
		            BindFlags = BindFlags.IndexBuffer
		        }, new uint[] { 0, 1, 2 }),
                IndexCount = 3,
                InputLayout = layout,
                PrimitiveCount = 1,
                PrimitiveTopology = PrimitiveTopology.TriangleList,
                VertexBuffer = vertices,
                VertexCount = 3,
                VertexSize = 32
		    });

			// Prepare all the stages
			_deviceContext.VertexShader.Shader = vertexShader;
			_deviceContext.Rasterizer.SetViewports(new Viewport(0, 0, width, height, 0.0f, 1.0f));
			_deviceContext.PixelShader.Shader = pixelShader;
			_deviceContext.OutputMerger.SetTargets(null, _renderTargetView);

            return swapChainPresenter.Bitmap;
		}
开发者ID:modulexcite,项目名称:rasterizr,代码行数:61,代码来源:BasicTriangleSample.cs

示例4: ImageGenerator

            public ImageGenerator(IResourceManager resourceLoader)
	        {
                const int width = 400;
                const int height = 400;

                // Create device and swap chain.
                _device = new Device();
                var swapChainPresenter = new WpfSwapChainPresenter();
                _swapChain = _device.CreateSwapChain(width, height, swapChainPresenter);
                _outputBitmap = swapChainPresenter.Bitmap;
                _deviceContext = _device.ImmediateContext;

                // Create RenderTargetView from the backbuffer.
                var backBuffer = Texture2D.FromSwapChain(_swapChain, 0);
                _renderTargetView = _device.CreateRenderTargetView(backBuffer);

                // Create the depth buffer
                var depthBuffer = _device.CreateTexture2D(new Texture2DDescription
                {
                    ArraySize = 1,
                    MipLevels = 1,
                    Width = width,
                    Height = height,
                    BindFlags = BindFlags.DepthStencil
                });

                // Create the depth buffer view
                _depthView = _device.CreateDepthStencilView(depthBuffer);

                // Compile Vertex and Pixel shaders
                var vertexShaderByteCode = ShaderCompiler.CompileFromFile("Modules/SampleBrowser/TechDemos/Resources/TextureSampling/Texture.fx", "VS", "vs_4_0");
                var vertexShader = _device.CreateVertexShader(vertexShaderByteCode);

                var pixelShaderByteCode = ShaderCompiler.CompileFromFile("Modules/SampleBrowser/TechDemos/Resources/TextureSampling/Texture.fx", "PS", "ps_4_1");
                var pixelShader = _device.CreatePixelShader(pixelShaderByteCode);

                // Layout from VertexShader input signature
                var layout = _device.CreateInputLayout(
                    new[]
	                {
	                    new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0, 0),
	                    new InputElement("TEXCOORD", 0, Format.R32G32_Float, 0, 16)
	                }, vertexShaderByteCode);

                // Instantiate Vertex buiffer from vertex data
                var vertices = _device.CreateBuffer(new BufferDescription(BindFlags.VertexBuffer), new[]
	            {
	                // 3D coordinates              UV Texture coordinates
	                -1.0f, -1.0f, -1.0f, 1.0f, 0.0f, 1.0f, // Front
	                -1.0f, 1.0f, -1.0f, 1.0f, 0.0f, 0.0f,
	                1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 0.0f,
	                -1.0f, -1.0f, -1.0f, 1.0f, 0.0f, 1.0f,
	                1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 0.0f,
	                1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.0f,

	                -1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 0.0f, // BACK
	                1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f,
	                -1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
	                -1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 0.0f,
	                1.0f, -1.0f, 1.0f, 1.0f, 0.0f, 0.0f,
	                1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f,

	                -1.0f, 1.0f, -1.0f, 1.0f, 0.0f, 1.0f, // Top
	                -1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f,
	                1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f,
	                -1.0f, 1.0f, -1.0f, 1.0f, 0.0f, 1.0f,
	                1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f,
	                1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 1.0f,

	                -1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 0.0f, // Bottom
	                1.0f, -1.0f, 1.0f, 1.0f, 0.0f, 1.0f,
	                -1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
	                -1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 0.0f,
	                1.0f, -1.0f, -1.0f, 1.0f, 0.0f, 0.0f,
	                1.0f, -1.0f, 1.0f, 1.0f, 0.0f, 1.0f,

	                -1.0f, -1.0f, -1.0f, 1.0f, 0.0f, 1.0f, // Left
	                -1.0f, -1.0f, 1.0f, 1.0f, 0.0f, 0.0f,
	                -1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f,
	                -1.0f, -1.0f, -1.0f, 1.0f, 0.0f, 1.0f,
	                -1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f,
	                -1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 1.0f,

	                1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 0.0f, // Right
	                1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f,
	                1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
	                1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 0.0f,
	                1.0f, 1.0f, -1.0f, 1.0f, 0.0f, 0.0f,
	                1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f
	            });

                // Create Constant Buffer
                _constantBuffer = _device.CreateBuffer(new BufferDescription
                {
                    SizeInBytes = Utilities.SizeOf<Matrix>(),
                    BindFlags = BindFlags.ConstantBuffer
                });

                // Load texture and create sampler
                var textureStream = resourceLoader.GetStream(
//.........这里部分代码省略.........
开发者ID:modulexcite,项目名称:rasterizr,代码行数:101,代码来源:TextureSamplingViewModel.cs

示例5: Initialize

        public override WriteableBitmap Initialize(Device device)
		{
            const int width = 600;
			const int height = 400;

			// Create device and swap chain.
            var swapChainPresenter = new WpfSwapChainPresenter();
            _swapChain = device.CreateSwapChain(width, height, swapChainPresenter);
			_deviceContext = device.ImmediateContext;

			// Create RenderTargetView from the backbuffer.
			var backBuffer = Texture2D.FromSwapChain(_swapChain, 0);
			_renderTargetView = device.CreateRenderTargetView(backBuffer);

			// Create the depth buffer
			var depthBuffer = device.CreateTexture2D(new Texture2DDescription
			{
				ArraySize = 1,
				MipLevels = 1,
				Width = width,
				Height = height,
				BindFlags = BindFlags.DepthStencil
			});

			// Create the depth buffer view
			_depthView = device.CreateDepthStencilView(depthBuffer);

            // Load model.
		    var modelLoader = new ModelLoader(device, TextureLoader.CreateTextureFromStream);
            _model = modelLoader.Load("Modules/SampleBrowser/Samples/ModelLoading/Car/car.obj");

            // Compile Vertex and Pixel shaders
            var vertexShaderByteCode = ShaderCompiler.CompileFromFile("Modules/SampleBrowser/Samples/ModelLoading/ModelLoading.fx", "VS", "vs_4_0");
            var vertexShader = device.CreateVertexShader(vertexShaderByteCode);

            var pixelShaderByteCode = ShaderCompiler.CompileFromFile("Modules/SampleBrowser/Samples/ModelLoading/ModelLoading.fx", "PS", "ps_4_0");
            var pixelShader = device.CreatePixelShader(pixelShaderByteCode);

		    _model.SetInputLayout(device, vertexShaderByteCode.InputSignature);

			var sampler = device.CreateSamplerState(new SamplerStateDescription
			{
				Filter = Filter.MinMagMipPoint,
				AddressU = TextureAddressMode.Wrap,
				AddressV = TextureAddressMode.Wrap,
				AddressW = TextureAddressMode.Wrap,
				BorderColor = Color4.Black,
				ComparisonFunction = Comparison.Never,
				MaximumAnisotropy = 16,
				MipLodBias = 0,
				MinimumLod = 0,
				MaximumLod = 16,
			});

            // Create constant buffers.
            _vertexConstantBuffer = device.CreateBuffer(new BufferDescription
            {
                SizeInBytes = Utilities.SizeOf<VertexShaderData>(),
                BindFlags = BindFlags.ConstantBuffer
            });
            _pixelConstantBuffer = device.CreateBuffer(new BufferDescription
            {
                SizeInBytes = Utilities.SizeOf<PixelShaderData>(),
                BindFlags = BindFlags.ConstantBuffer
            });

			// Prepare all the stages
            _deviceContext.VertexShader.SetConstantBuffers(0, _vertexConstantBuffer);
            _deviceContext.VertexShader.Shader = vertexShader;
            _deviceContext.PixelShader.SetConstantBuffers(0, _pixelConstantBuffer);
            _deviceContext.PixelShader.Shader = pixelShader;
			_deviceContext.PixelShader.SetSamplers(0, sampler);

            _vertexShaderData = new VertexShaderData();

            _pixelShaderData = new PixelShaderData
            {
                LightDirection = new Vector4(Vector3.Normalize(new Vector3(0.5f, 0, -1)), 1)
            };
            _deviceContext.SetBufferData(_pixelConstantBuffer, ref _pixelShaderData);

		    // Setup targets and viewport for rendering
			_deviceContext.Rasterizer.SetViewports(new Viewport(0, 0, width, height, 0.0f, 1.0f));
			_deviceContext.OutputMerger.SetTargets(_depthView, _renderTargetView);

            //_deviceContext.Rasterizer.State = device.CreateRasterizerState(new Pipeline.Rasterizer.RasterizerStateDescription
            //{
            //    FillMode = Pipeline.Rasterizer.FillMode.Wireframe
            //});

			// Prepare matrices
			_projection = Matrix.PerspectiveFovLH(MathUtil.Pi / 3.0f, 
				width / (float) height, 1f, 1000.0f);

            return swapChainPresenter.Bitmap;
		}
开发者ID:modulexcite,项目名称:rasterizr,代码行数:96,代码来源:ModelLoadingSample.cs

示例6: Initialize

        public override WriteableBitmap Initialize(Device device)
		{
			const int width = 600;
			const int height = 400;

			// Create device and swap chain.
            var swapChainPresenter = new WpfSwapChainPresenter();
            _swapChain = device.CreateSwapChain(width, height, swapChainPresenter);
			_deviceContext = device.ImmediateContext;

			// Create RenderTargetView from the backbuffer.
			var backBuffer = Texture2D.FromSwapChain(_swapChain, 0);
			_renderTargetView = device.CreateRenderTargetView(backBuffer);

			// Create the depth buffer
			var depthBuffer = device.CreateTexture2D(new Texture2DDescription
			{
				ArraySize = 1,
				MipLevels = 1,
				Width = width,
				Height = height,
				BindFlags = BindFlags.DepthStencil
			});

			// Create the depth buffer view
			_depthView = device.CreateDepthStencilView(depthBuffer);

			// Compile Vertex and Pixel shaders
            var vertexShaderByteCode = ShaderCompiler.CompileFromFile("Modules/SampleBrowser/Samples/MiniCubeTexture/MiniCubeTexture.fx", "VS", "vs_4_0");
			var vertexShader = device.CreateVertexShader(vertexShaderByteCode);

            var pixelShaderByteCode = ShaderCompiler.CompileFromFile("Modules/SampleBrowser/Samples/MiniCubeTexture/MiniCubeTexture.fx", "PS", "ps_4_0");
			var pixelShader = device.CreatePixelShader(pixelShaderByteCode);

			// Layout from VertexShader input signature
			var layout = device.CreateInputLayout(
				new[]
				{
					new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0, 0),
					new InputElement("TEXCOORD", 0, Format.R32G32_Float, 0, 16)
				}, vertexShaderByteCode);

			// Instantiate Vertex buiffer from vertex data
			var vertices = device.CreateBuffer(new BufferDescription(BindFlags.VertexBuffer), new[]
			{
				// 3D coordinates              UV Texture coordinates
                -1.0f, -1.0f, -1.0f, 1.0f,     0.0f, 1.0f, // Front
                -1.0f,  1.0f, -1.0f, 1.0f,     0.0f, 0.0f,
                1.0f,  1.0f, -1.0f, 1.0f,     1.0f, 0.0f,
                -1.0f, -1.0f, -1.0f, 1.0f,     0.0f, 1.0f,
                1.0f,  1.0f, -1.0f, 1.0f,     1.0f, 0.0f,
                1.0f, -1.0f, -1.0f, 1.0f,     1.0f, 1.0f,

                -1.0f, -1.0f,  1.0f, 1.0f,     1.0f, 0.0f, // BACK
                1.0f,  1.0f,  1.0f, 1.0f,     0.0f, 1.0f,
                -1.0f,  1.0f,  1.0f, 1.0f,     1.0f, 1.0f,
                -1.0f, -1.0f,  1.0f, 1.0f,     1.0f, 0.0f,
                1.0f, -1.0f,  1.0f, 1.0f,     0.0f, 0.0f,
                1.0f,  1.0f,  1.0f, 1.0f,     0.0f, 1.0f,

                -1.0f, 1.0f, -1.0f,  1.0f,     0.0f, 1.0f, // Top
                -1.0f, 1.0f,  1.0f,  1.0f,     0.0f, 0.0f,
                1.0f, 1.0f,  1.0f,  1.0f,     1.0f, 0.0f,
                -1.0f, 1.0f, -1.0f,  1.0f,     0.0f, 1.0f,
                1.0f, 1.0f,  1.0f,  1.0f,     1.0f, 0.0f,
                1.0f, 1.0f, -1.0f,  1.0f,     1.0f, 1.0f,

                -1.0f,-1.0f, -1.0f,  1.0f,     1.0f, 0.0f, // Bottom
                1.0f,-1.0f,  1.0f,  1.0f,     0.0f, 1.0f,
                -1.0f,-1.0f,  1.0f,  1.0f,     1.0f, 1.0f,
                -1.0f,-1.0f, -1.0f,  1.0f,     1.0f, 0.0f,
                1.0f,-1.0f, -1.0f,  1.0f,     0.0f, 0.0f,
                1.0f,-1.0f,  1.0f,  1.0f,     0.0f, 1.0f,

                -1.0f, -1.0f, -1.0f, 1.0f,     0.0f, 1.0f, // Left
                -1.0f, -1.0f,  1.0f, 1.0f,     0.0f, 0.0f,
                -1.0f,  1.0f,  1.0f, 1.0f,     1.0f, 0.0f,
                -1.0f, -1.0f, -1.0f, 1.0f,     0.0f, 1.0f,
                -1.0f,  1.0f,  1.0f, 1.0f,     1.0f, 0.0f,
                -1.0f,  1.0f, -1.0f, 1.0f,     1.0f, 1.0f,

                1.0f, -1.0f, -1.0f, 1.0f,     1.0f, 0.0f, // Right
                1.0f,  1.0f,  1.0f, 1.0f,     0.0f, 1.0f,
                1.0f, -1.0f,  1.0f, 1.0f,     1.0f, 1.0f,
                1.0f, -1.0f, -1.0f, 1.0f,     1.0f, 0.0f,
                1.0f,  1.0f, -1.0f, 1.0f,     0.0f, 0.0f,
                1.0f,  1.0f,  1.0f, 1.0f,     0.0f, 1.0f
			});

			// Create Constant Buffer
			_constantBuffer = device.CreateBuffer(new BufferDescription
			{
				SizeInBytes = Utilities.SizeOf<Matrix>(),
				BindFlags = BindFlags.ConstantBuffer
			});

			// Load texture and create sampler
			var textureStream = _resourceLoader.GetStream(
                "Modules/SampleBrowser/Samples/MiniCubeTexture/GeneticaMortarlessBlocks.jpg",
                GetType().Assembly.FullName);
//.........这里部分代码省略.........
开发者ID:modulexcite,项目名称:rasterizr,代码行数:101,代码来源:MiniCubeTextureSample.cs

示例7: Initialize

        public override WriteableBitmap Initialize(Device device)
		{
			// Create device and swap chain.
            var swapChainPresenter = new WpfSwapChainPresenter();
            _swapChain = device.CreateSwapChain(Width, Height, swapChainPresenter);
			_deviceContext = device.ImmediateContext;

			// Create RenderTargetView from the backbuffer.
			var backBuffer = Texture2D.FromSwapChain(_swapChain, 0);
			_renderTargetView = device.CreateRenderTargetView(backBuffer);

			// Create the depth buffer
			var depthBuffer = device.CreateTexture2D(new Texture2DDescription
			{
				ArraySize = 1,
				MipLevels = 1,
				Width = Width,
				Height = Height,
				BindFlags = BindFlags.DepthStencil
			});

			// Create the depth buffer view
			_depthView = device.CreateDepthStencilView(depthBuffer);

            // Create cube map resources.
            var cubeMapTexture = device.CreateTexture2D(new Texture2DDescription
            {
                Width = CubeMapSize,
                Height= CubeMapSize,
                ArraySize = 6,
                BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource,
                MipLevels = 1
            });
            _renderTargetViewCube = device.CreateRenderTargetView(cubeMapTexture);
            _resourceViewCube = device.CreateShaderResourceView(cubeMapTexture);
            var depthBufferCube = device.CreateTexture2D(new Texture2DDescription
            {
                ArraySize = 6,
                MipLevels = 1,
                Width = CubeMapSize,
                Height = CubeMapSize,
                BindFlags = BindFlags.DepthStencil
            });
            _depthViewCube = device.CreateDepthStencilView(depthBufferCube);

            // Load model.
		    var modelLoader = new ModelLoader(device, TextureLoader.CreateTextureFromStream);
            _model = modelLoader.Load("Modules/SampleBrowser/Samples/EnvironmentMapping/teapot.obj");

            // Compile Vertex and Pixel shaders
            var vertexShaderByteCode = ShaderCompiler.CompileFromFile("Modules/SampleBrowser/Samples/EnvironmentMapping/EnvironmentMapping.fx", "VS_CubeMap", "vs_4_0");
            _vertexShaderCubeMap = device.CreateVertexShader(vertexShaderByteCode);
            _vertexShaderStandard = device.CreateVertexShader(ShaderCompiler.CompileFromFile("Modules/SampleBrowser/Samples/EnvironmentMapping/EnvironmentMapping.fx", "VS_Standard", "vs_4_0"));

            _geometryShaderCubeMap = device.CreateGeometryShader(ShaderCompiler.CompileFromFile("Modules/SampleBrowser/Samples/EnvironmentMapping/EnvironmentMapping.fx", "GS_CubeMap", "gs_4_0"));

            _pixelShaderCubeMap = device.CreatePixelShader(ShaderCompiler.CompileFromFile("Modules/SampleBrowser/Samples/EnvironmentMapping/EnvironmentMapping.fx", "PS_CubeMap", "ps_4_0"));
            _pixelShaderStandard = device.CreatePixelShader(ShaderCompiler.CompileFromFile("Modules/SampleBrowser/Samples/EnvironmentMapping/EnvironmentMapping.fx", "PS_Standard", "ps_4_0"));
            _pixelShaderReflective = device.CreatePixelShader(ShaderCompiler.CompileFromFile("Modules/SampleBrowser/Samples/EnvironmentMapping/EnvironmentMapping.fx", "PS_Reflective", "ps_4_0"));

		    _model.SetInputLayout(device, vertexShaderByteCode.InputSignature);

            var sampler = device.CreateSamplerState(SamplerStateDescription.Default);

            // Create constant buffers.
            _vertexConstantBuffer = device.CreateBuffer(new BufferDescription
            {
                SizeInBytes = Utilities.SizeOf<VertexShaderData>(),
                BindFlags = BindFlags.ConstantBuffer
            });
            _geometryConstantBuffer = device.CreateBuffer(new BufferDescription
            {
                SizeInBytes = Utilities.SizeOf<GeometryShaderData>(),
                BindFlags = BindFlags.ConstantBuffer
            });
            var pixelConstantBuffer = device.CreateBuffer(new BufferDescription
            {
                SizeInBytes = Utilities.SizeOf<PixelShaderData>(),
                BindFlags = BindFlags.ConstantBuffer
            });

			// Prepare all the stages
            _deviceContext.VertexShader.SetConstantBuffers(0, _vertexConstantBuffer);
            _deviceContext.GeometryShader.SetConstantBuffers(0, _geometryConstantBuffer);
            _deviceContext.PixelShader.SetConstantBuffers(0, pixelConstantBuffer);
			_deviceContext.PixelShader.SetSamplers(0, sampler);

            _vertexShaderData = new VertexShaderData();

            _view1 = Matrix.LookAtLH(Vector3.Zero, new Vector3(1, 0, 0), Vector3.UnitY);
            _view2 = Matrix.LookAtLH(Vector3.Zero, new Vector3(-1, 0, 0), Vector3.UnitY);
            _view3 = Matrix.LookAtLH(Vector3.Zero, new Vector3(0, 1, 0), -Vector3.UnitZ);
            _view4 = Matrix.LookAtLH(Vector3.Zero, new Vector3(0, -1, 0), Vector3.UnitZ);
            _view5 = Matrix.LookAtLH(Vector3.Zero, new Vector3(0, 0, 1), Vector3.UnitY);
            _view6 = Matrix.LookAtLH(Vector3.Zero, new Vector3(0, 0, -1), Vector3.UnitY);

            var from = new Vector3(0, 30, 70);
            var to = new Vector3(0, 0, 0);

            // Prepare matrices
//.........这里部分代码省略.........
开发者ID:modulexcite,项目名称:rasterizr,代码行数:101,代码来源:EnvironmentMappingSample.cs

示例8: AddVertexData


//.........这里部分代码省略.........
                        vertexElements[elementIndex++] = new InputElement("TEXCOORD", 0, Format.R32G32_Float, 0, vertexSize);
                        vertexSize += (short) Utilities.SizeOf<Vector2>();
                    }

                    //set the vertex elements and size
                    modelMesh.InputElements = vertexElements;
                    modelMesh.VertexSize = vertexSize;

                    //get pointers to vertex data
                    Vector3D[] positions = mesh.Vertices;
                    Vector3D[] texCoords = mesh.GetTextureCoords(0);
                    Vector3D[] normals = mesh.Normals;
                    Vector3D[] tangents = mesh.Tangents;
                    Vector3D[] biTangents = mesh.BiTangents;
                    Color4D[] colours = mesh.GetVertexColors(0);

                    //also determine primitive type
                    switch (mesh.PrimitiveType)
                    {
                        case PrimitiveType.Point:
                            modelMesh.PrimitiveTopology = PrimitiveTopology.PointList;
                            break;
                        case PrimitiveType.Line:
                            modelMesh.PrimitiveTopology = PrimitiveTopology.LineList;
                            break;
                        case PrimitiveType.Triangle:
                            modelMesh.PrimitiveTopology = PrimitiveTopology.TriangleList;
                            break;
                        default:
                            throw new Exception("ModelLoader::AddVertexData(): Unknown primitive type");
                    }

                    // Create new vertex buffer.
                    var vertexBuffer = device.CreateBuffer(
                        new BufferDescription
                        {
                            BindFlags = BindFlags.VertexBuffer,
                            SizeInBytes = mesh.VertexCount * vertexSize
                        });

                    int byteOffset = 0;
                    for (int i = 0; i < mesh.VertexCount; i++)
                    {
                        {
                            // Add position, after transforming it with accumulated node transform.
                            Vector4 tempResult;
                            Vector3 pos = positions[i].ToVector3();
                            Vector3.Transform(ref pos, ref transform, out tempResult);
                            var result = new Vector3(tempResult.X, tempResult.Y, tempResult.Z);
                            device.ImmediateContext.SetBufferData(vertexBuffer, ref result, byteOffset);
                            byteOffset += Vector3.SizeInBytes;
                        }

                        if (hasColors)
                        {
                            var vertColor = colours[i].ToColor();
                            device.ImmediateContext.SetBufferData(vertexBuffer, ref vertColor, byteOffset);
                            byteOffset += 4;
                        }
                        if (hasNormals)
                        {
                            var normal = normals[i].ToVector3();
                            Vector4 tempResult;
                            Vector3.Transform(ref normal, ref invTranspose, out tempResult);
                            var result = new Vector3(tempResult.X, tempResult.Y, tempResult.Z);
                            device.ImmediateContext.SetBufferData(vertexBuffer, ref result, byteOffset);
开发者ID:modulexcite,项目名称:rasterizr,代码行数:67,代码来源:ModelLoader.cs

示例9: Initialize

        public override WriteableBitmap Initialize(Device device)
		{
			const int width = 400;
			const int height = 300;

			// Create device and swap chain.
            var swapChainPresenter = new WpfSwapChainPresenter();
            _swapChain = device.CreateSwapChain(width, height, swapChainPresenter);
			_deviceContext = device.ImmediateContext;

			// Create RenderTargetView from the backbuffer.
			var backBuffer = Texture2D.FromSwapChain(_swapChain, 0);
			_renderTargetView = device.CreateRenderTargetView(backBuffer);

			// Create the depth buffer
			var depthBuffer = device.CreateTexture2D(new Texture2DDescription
			{
				ArraySize = 1,
				MipLevels = 1,
				Width = width,
				Height = height,
				BindFlags = BindFlags.DepthStencil
			});

			// Create the depth buffer view
			_depthView = device.CreateDepthStencilView(depthBuffer);

			// Compile Vertex and Pixel shaders
            var vertexShaderByteCode = ShaderCompiler.CompileFromFile("Modules/SampleBrowser/Samples/MiniCube/MiniCube.fx", "VS", "vs_4_0");
			var vertexShader = device.CreateVertexShader(vertexShaderByteCode);

            var pixelShaderByteCode = ShaderCompiler.CompileFromFile("Modules/SampleBrowser/Samples/MiniCube/MiniCube.fx", "PS", "ps_4_0");
			var pixelShader = device.CreatePixelShader(pixelShaderByteCode);

			// Layout from VertexShader input signature
			var layout = device.CreateInputLayout(
				new[]
				{
					new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0),
					new InputElement("COLOR", 0, Format.R32G32B32A32_Float, 0)
				}, vertexShaderByteCode);

			// Instantiate Vertex buffer from vertex data
			var vertices = device.CreateBuffer(new BufferDescription(BindFlags.VertexBuffer), new[]
			{
				new Vector4(-1.0f, -1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f), // Front
				new Vector4(-1.0f, 1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f),
				new Vector4(1.0f, 1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f),
				new Vector4(-1.0f, -1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f),
				new Vector4(1.0f, 1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f),
				new Vector4(1.0f, -1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f),

				new Vector4(-1.0f, -1.0f, 1.0f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f), // BACK
				new Vector4(1.0f, 1.0f, 1.0f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f),
				new Vector4(-1.0f, 1.0f, 1.0f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f),
				new Vector4(-1.0f, -1.0f, 1.0f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f),
				new Vector4(1.0f, -1.0f, 1.0f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f),
				new Vector4(1.0f, 1.0f, 1.0f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f),

				new Vector4(-1.0f, 1.0f, -1.0f, 1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f), // Top
				new Vector4(-1.0f, 1.0f, 1.0f, 1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f),
				new Vector4(1.0f, 1.0f, 1.0f, 1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f),
				new Vector4(-1.0f, 1.0f, -1.0f, 1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f),
				new Vector4(1.0f, 1.0f, 1.0f, 1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f),
				new Vector4(1.0f, 1.0f, -1.0f, 1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f),

				new Vector4(-1.0f, -1.0f, -1.0f, 1.0f), new Vector4(1.0f, 1.0f, 0.0f, 1.0f), // Bottom
				new Vector4(1.0f, -1.0f, 1.0f, 1.0f), new Vector4(1.0f, 1.0f, 0.0f, 1.0f),
				new Vector4(-1.0f, -1.0f, 1.0f, 1.0f), new Vector4(1.0f, 1.0f, 0.0f, 1.0f),
				new Vector4(-1.0f, -1.0f, -1.0f, 1.0f), new Vector4(1.0f, 1.0f, 0.0f, 1.0f),
				new Vector4(1.0f, -1.0f, -1.0f, 1.0f), new Vector4(1.0f, 1.0f, 0.0f, 1.0f),
				new Vector4(1.0f, -1.0f, 1.0f, 1.0f), new Vector4(1.0f, 1.0f, 0.0f, 1.0f),

				new Vector4(-1.0f, -1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 1.0f, 1.0f), // Left
				new Vector4(-1.0f, -1.0f, 1.0f, 1.0f), new Vector4(1.0f, 0.0f, 1.0f, 1.0f),
				new Vector4(-1.0f, 1.0f, 1.0f, 1.0f), new Vector4(1.0f, 0.0f, 1.0f, 1.0f),
				new Vector4(-1.0f, -1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 1.0f, 1.0f),
				new Vector4(-1.0f, 1.0f, 1.0f, 1.0f), new Vector4(1.0f, 0.0f, 1.0f, 1.0f),
				new Vector4(-1.0f, 1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 1.0f, 1.0f),

				new Vector4(1.0f, -1.0f, -1.0f, 1.0f), new Vector4(0.0f, 1.0f, 1.0f, 1.0f), // Right
				new Vector4(1.0f, 1.0f, 1.0f, 1.0f), new Vector4(0.0f, 1.0f, 1.0f, 1.0f),
				new Vector4(1.0f, -1.0f, 1.0f, 1.0f), new Vector4(0.0f, 1.0f, 1.0f, 1.0f),
				new Vector4(1.0f, -1.0f, -1.0f, 1.0f), new Vector4(0.0f, 1.0f, 1.0f, 1.0f),
				new Vector4(1.0f, 1.0f, -1.0f, 1.0f), new Vector4(0.0f, 1.0f, 1.0f, 1.0f),
				new Vector4(1.0f, 1.0f, 1.0f, 1.0f), new Vector4(0.0f, 1.0f, 1.0f, 1.0f)
			});

			// Create Constant Buffer
			_constantBuffer = device.CreateBuffer(new BufferDescription
			{
				SizeInBytes = Utilities.SizeOf<Matrix>(),
				BindFlags = BindFlags.ConstantBuffer
			});

			// Prepare all the stages
			_deviceContext.InputAssembler.InputLayout = layout;
			_deviceContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
			_deviceContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(vertices, 0, Utilities.SizeOf<Vector4>() * 2));
			_deviceContext.VertexShader.SetConstantBuffers(0, _constantBuffer);
//.........这里部分代码省略.........
开发者ID:modulexcite,项目名称:rasterizr,代码行数:101,代码来源:MiniCubeSample.cs

示例10: CanGetVertexStreamForInstancedLineList

		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[]
//.........这里部分代码省略.........
开发者ID:modulexcite,项目名称:rasterizr,代码行数:101,代码来源:InputAssemblerStageTests.cs

示例11: CanGetVertexStreamForIndexedLineList

		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)
				}));
		}
开发者ID:modulexcite,项目名称:rasterizr,代码行数:48,代码来源:InputAssemblerStageTests.cs

示例12: CanGetVertexStreamForLineListWithMultipleVertexBuffers

		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)
				}));
		}
开发者ID:modulexcite,项目名称:rasterizr,代码行数:53,代码来源:InputAssemblerStageTests.cs


注:本文中的Device.CreateBuffer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。