コード例 #1
0
        protected override void OnShown(EventArgs e)
        {
            base.OnShown(e);

            // device creation
            device        = D3DDevice.CreateDeviceAndSwapChain(Handle);
            swapChain     = device.SwapChain;
            deviceContext = device.ImmediateContext;

            SetViews();

            // Open precompiled vertex shader
            // This file was compiled using: fxc Render.hlsl /T vs_4_0 /EVertShader /FoRender.vs
            using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Microsoft.WindowsAPICodePack.Samples.Direct3D11.Render.vs"))
            {
                vertexShader = device.CreateVertexShader(stream);
            }

            deviceContext.VS.SetShader(vertexShader, null);

            // input layout is for the vert shader
            InputElementDescription inputElementDescription = new InputElementDescription();

            inputElementDescription.SemanticName         = "POSITION";
            inputElementDescription.SemanticIndex        = 0;
            inputElementDescription.Format               = Format.R32G32B32Float;
            inputElementDescription.InputSlot            = 0;
            inputElementDescription.AlignedByteOffset    = 0;
            inputElementDescription.InputSlotClass       = InputClassification.PerVertexData;
            inputElementDescription.InstanceDataStepRate = 0;

            InputLayout inputLayout;

            using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Microsoft.WindowsAPICodePack.Samples.Direct3D11.Render.vs"))
            {
                inputLayout = device.CreateInputLayout(new InputElementDescription[] { inputElementDescription }, stream);
            }
            deviceContext.IA.InputLayout = inputLayout;

            // Open precompiled vertex shader
            // This file was compiled using: fxc Render.hlsl /T ps_4_0 /EPixShader /FoRender.ps
            using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Microsoft.WindowsAPICodePack.Samples.Direct3D11.Render.ps"))
            {
                pixelShader = device.CreatePixelShader(stream);
            }
            deviceContext.PS.SetShader(pixelShader, null);


            // create some geometry to draw (1 triangle)
            SimpleVertexArray vertex = new SimpleVertexArray();

            // put the vertices into a vertex buffer

            BufferDescription bufferDescription = new BufferDescription();

            bufferDescription.Usage          = Usage.Default;
            bufferDescription.ByteWidth      = (uint)Marshal.SizeOf(vertex);
            bufferDescription.BindingOptions = BindingOptions.VertexBuffer;

            SubresourceData subresourceData = new SubresourceData();

            IntPtr vertexData = Marshal.AllocCoTaskMem(Marshal.SizeOf(vertex));

            Marshal.StructureToPtr(vertex, vertexData, false);

            subresourceData.SystemMemory = vertexData;
            vertexBuffer = device.CreateBuffer(bufferDescription, subresourceData);


            deviceContext.IA.SetVertexBuffers(0, new D3DBuffer[] { vertexBuffer }, new uint[] { 12 }, new uint[] { 0 });
            deviceContext.IA.PrimitiveTopology = PrimitiveTopology.TriangleList;

            Marshal.FreeCoTaskMem(vertexData);
        }
コード例 #2
0
ファイル: Window1.xaml.cs プロジェクト: QuocHuy7a10/Arianrhod
        /// <summary>
        /// Init device and required resources
        /// </summary>
        private void InitDevice()
        {
            // device creation
            device = D3DDevice.CreateDeviceAndSwapChain(host.Handle);
            swapChain = device.SwapChain;
            deviceContext = device.ImmediateContext;

            SetViews();

            // vertex shader & layout            
            // Open precompiled vertex shader
            // This file was compiled using: fxc Render.hlsl /T vs_4_0 /EVertShader /FoRender.vs
            using (Stream stream = Application.ResourceAssembly.GetManifestResourceStream("Microsoft.WindowsAPICodePack.Samples.Direct3D11.Render.vs"))
            {
                vertexShader = device.CreateVertexShader(stream);
                deviceContext.VS.Shader = vertexShader;

                // input layout is for the vert shader
                InputElementDescription inputElementDescription = new InputElementDescription();
                inputElementDescription.SemanticName = "POSITION";
                inputElementDescription.SemanticIndex = 0;
                inputElementDescription.Format = Format.R32G32B32Float;
                inputElementDescription.InputSlot = 0;
                inputElementDescription.AlignedByteOffset = 0;
                inputElementDescription.InputSlotClass = InputClassification.PerVertexData;
                inputElementDescription.InstanceDataStepRate = 0;
                stream.Position = 0;
                InputLayout inputLayout = device.CreateInputLayout(
                    new InputElementDescription[] { inputElementDescription },
                    stream);
                deviceContext.IA.InputLayout = inputLayout;
            }

            // Open precompiled vertex shader
            // This file was compiled using: fxc Render.hlsl /T ps_4_0 /EPixShader /FoRender.ps
            using (Stream stream = Application.ResourceAssembly.GetManifestResourceStream("Microsoft.WindowsAPICodePack.Samples.Direct3D11.Render.ps"))
            {
                pixelShader = device.CreatePixelShader(stream);
            }
            deviceContext.PS.SetShader(pixelShader, null);

            // create some geometry to draw (1 triangle)
            SimpleVertexArray vertex = new SimpleVertexArray();

            // put the vertices into a vertex buffer

            BufferDescription bufferDescription = new BufferDescription();
            bufferDescription.Usage = Usage.Default;
            bufferDescription.ByteWidth = (uint)Marshal.SizeOf(vertex);
            bufferDescription.BindingOptions = BindingOptions.VertexBuffer;

            SubresourceData subresourceData = new SubresourceData();

            IntPtr vertexData = Marshal.AllocCoTaskMem(Marshal.SizeOf(vertex));
            Marshal.StructureToPtr(vertex, vertexData, false);

            subresourceData.SystemMemory = vertexData;
            vertexBuffer = device.CreateBuffer(bufferDescription, subresourceData);


            deviceContext.IA.SetVertexBuffers(0, new D3DBuffer[] { vertexBuffer }, new uint[] { 12 }, new uint[] { 0 });
            deviceContext.IA.PrimitiveTopology = PrimitiveTopology.TriangleList;

            Marshal.FreeCoTaskMem(vertexData);
        }
コード例 #3
0
ファイル: Form1.cs プロジェクト: Prashant-Jonny/phever
        private void InitDevice()
        {
            // device creation
            //device = D3DDevice.CreateDeviceAndSwapChain(
            //    null,
            //    DriverType.Hardware,
            //    null,
            //    CreateDeviceFlag.Default,
            //    new []{FeatureLevel.FeatureLevel_10_1},
            //    new SwapChainDescription {
            //        BufferCount = 1
            //    },
            //    out swapChain);
            device = D3DDevice.CreateDeviceAndSwapChain(directControl.Handle, out swapChain);
            deviceContext = device.GetImmediateContext();

            SetViews();

            // Open precompiled vertex shader
            // This file was compiled using: fxc Render.hlsl /T vs_4_0 /EVertShader /FoRender.vs
            using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Microsoft.WindowsAPICodePack.Samples.Direct3D11.Render.vs"))
            {
                vertexShader = device.CreateVertexShader(stream);
            }

            deviceContext.VS.SetShader(vertexShader, null);

            // input layout is for the vert shader
            InputElementDescription inputElementDescription = new InputElementDescription();
            inputElementDescription.SemanticName = "POSITION";
            inputElementDescription.SemanticIndex = 0;
            inputElementDescription.Format = Format.R32G32B32_FLOAT;
            inputElementDescription.InputSlot = 0;
            inputElementDescription.AlignedByteOffset = 0;
            inputElementDescription.InputSlotClass = InputClassification.PerVertexData;
            inputElementDescription.InstanceDataStepRate = 0;

            InputLayout inputLayout;
            using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Microsoft.WindowsAPICodePack.Samples.Direct3D11.Render.vs"))
            {
                inputLayout = device.CreateInputLayout(new [] { inputElementDescription }, stream);
            }
            deviceContext.IA.SetInputLayout(inputLayout);

            // Open precompiled pixel shader
            // This file was compiled using: fxc Render.hlsl /T ps_4_0 /EPixShader /FoRender.ps
            using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Microsoft.WindowsAPICodePack.Samples.Direct3D11.Render.ps"))
            {
                pixelShader = device.CreatePixelShader(stream);
            }
            deviceContext.PS.SetShader(pixelShader, null);


            // create some geometry to draw (1 triangle)
            SimpleVertexArray vertex = new SimpleVertexArray();

            // put the vertices into a vertex buffer

            BufferDescription bufferDescription = new BufferDescription();
            bufferDescription.Usage = Usage.Default;
            bufferDescription.ByteWidth = (uint)Marshal.SizeOf(vertex);
            bufferDescription.BindFlags = BindFlag.VertexBuffer;

            SubresourceData subresourceData = new SubresourceData();

            IntPtr vertexData = Marshal.AllocCoTaskMem(Marshal.SizeOf(vertex));
            Marshal.StructureToPtr(vertex, vertexData, false);

            subresourceData.SysMem = vertexData;
            vertexBuffer = device.CreateBuffer(bufferDescription, subresourceData);


            deviceContext.IA.SetVertexBuffers(0, new [] { vertexBuffer }, new uint[] { 12 }, new uint[] { 0 });
            deviceContext.IA.SetPrimitiveTopology(PrimitiveTopology.TriangleList);

            Marshal.FreeCoTaskMem(vertexData);
        }