示例#1
0
        public void Setup(D3D11Device device)
        {
            if (m_vsCompiled == null)
            {
                return;
            }

            // Prepare All the stages
            device.Context.InputAssembler.InputLayout = m_layout;

            if (m_vs == null)
            {
                m_vs = new VertexShader(device.Device, m_vsCompiled);
            }
            device.Context.VertexShader.Set(m_vs);

            if (m_ps == null)
            {
                m_ps = new PixelShader(device.Device, m_psCompiled);
            }
            device.Context.PixelShader.Set(m_ps);

            if (m_layout == null)
            {
                // Layout from VertexShader input signature
                m_layout = new InputLayout(
                    device.Device,
                    ShaderSignature.GetInputSignature(m_vsCompiled),
                    InputElements.Value);
            }
            device.Context.InputAssembler.InputLayout = m_layout;
        }
示例#2
0
        public void Setup(D3D11Device device, Color4 clear)
        {
            device.Context.ClearRenderTargetView(_rtv, clear);
            device.Context.ClearDepthStencilView(_dsv,
                                                 DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil,
                                                 1.0f, 0);

            device.Context.OutputMerger.SetTargets(_dsv, _rtv);
        }
示例#3
0
 void Update(D3D11Device device, T value)
 {
     if (_buffer == null)
     {
         _buffer           = Buffer.Create(device.Device, BindFlags.ConstantBuffer, ref value);
         _buffer.DebugName = typeof(T).Name;
     }
     device.Context.UpdateSubresource(ref value, _buffer);
 }
示例#4
0
        public bool SetIndices(D3D11Device device)
        {
            var indexBuffer = GetIndexBuffer(device.Device);

            if (indexBuffer == null)
            {
                return(false);
            }
            device.Context.InputAssembler.SetIndexBuffer(indexBuffer,
                                                         SharpDX.DXGI.Format.R32_UInt, 0);
            return(true);
        }
示例#5
0
        public void Setup(D3D11Device device)
        {
            _constants.SetPSConstants(device, 0, Color);

            // shader
            Shader.Setup(device);

            // material
            device.Context.PixelShader.SetShaderResource(0, GetOrCreateSRV(device.Device));
            device.Context.PixelShader.SetSampler(0, GetOrCreateSamplerState(device.Device));
            device.Context.Rasterizer.State = GetRasterizerState(device.Device);
            device.Context.OutputMerger.SetDepthStencilState(GetOrCreateDepthStencilState(device.Device));
        }
示例#6
0
        public D3D11RenderTarget CreateRenderTarget(D3D11Device device)
        {
            // New RenderTargetView from the backbuffer
            var backBuffer = Texture2D.FromSwapChain <Texture2D>(m_swapChain, 0);

            backBuffer.DebugName = "backBuffer";
            var rt = new D3D11RenderTarget();

            rt.CreateFromTexture(backBuffer,
                                 m_swapChain.Description.SampleDescription.Count,
                                 m_swapChain.Description.SampleDescription.Quality);
            return(rt);
        }
示例#7
0
        public bool SetVertices(D3D11Device device, D3D11Shader shader)
        {
            var inputs = shader.InputElements.Value;

            if (inputs == null)
            {
                return(false);
            }
            if (!HasPositionAttribute)
            {
                return(false);
            }

            device.Context.InputAssembler.PrimitiveTopology = Topology;

            var vertices = GetVertexBuffer(device, inputs);

            device.Context.InputAssembler.SetVertexBuffers(0,
                                                           new VertexBufferBinding(vertices, Stride, 0));
            return(true);
        }
示例#8
0
        public void Create(D3D11Device device, int w, int h)
        {
            if (device.Device == null)
            {
                return;
            }

            var texture = new Texture2D(device.Device, new Texture2DDescription
            {
                Format            = SharpDX.DXGI.Format.B8G8R8A8_UNorm,
                ArraySize         = 1,
                MipLevels         = 1,
                Width             = w,
                Height            = h,
                SampleDescription = new SharpDX.DXGI.SampleDescription
                {
                    Count   = 1,
                    Quality = 0
                },
                BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource
            });

            CreateFromTexture(texture, 1, 0);
        }
示例#9
0
 public void SetPSConstants(D3D11Device device, int slot, T value)
 {
     Update(device, value);
     device.Context.PixelShader.SetConstantBuffer(slot, _buffer);
 }
示例#10
0
 public void Draw(D3D11Device device, int offset, int count)
 {
     device.Context.Draw(count, offset);
 }
示例#11
0
 public void DrawIndexed(D3D11Device device, int offset, int count)
 {
     device.Context.DrawIndexed(count, offset, 0);
 }
示例#12
0
        SharpDX.Direct3D11.Buffer GetVertexBuffer(D3D11Device device,
                                                  InputElement[] inputs)
        {
            if (inputs != _inputs)
            {
                Dispose();
                _inputs = inputs;
            }

            if (m_vertexBuffer == null)
            {
                Stride = inputs.Sum(y => GetSize(y));
                var pos = m_attributes[Semantics.POSITION];

                // fill buffer
                _buffer = new InterleavedBuffer(Stride, VertexCount);
                int offset = 0;
                foreach (var input in inputs)
                {
                    VertexAttribute attr;
                    var             semantics = (Semantics)Enum.Parse(typeof(Semantics), input.SemanticName, true);
                    if (m_attributes.TryGetValue(semantics, out attr))
                    {
                        _buffer.Set(attr.Value, attr.ElementSize, offset);
                    }
                    offset += GetSize(input);
                }

                var desc = new BufferDescription
                {
                    Usage          = ResourceUsage.Dynamic,
                    BindFlags      = BindFlags.VertexBuffer,
                    CpuAccessFlags = CpuAccessFlags.Write,
                    SizeInBytes    = _buffer.Buffer.Length,
                };
                m_vertexBuffer           = SharpDX.Direct3D11.Buffer.Create(device.Device, _buffer.Buffer, desc);
                m_vertexBuffer.DebugName = "VertexBuffer";
            }

            if (_skinnedPosition != null)
            {
                //
                // skinning
                //
                var box = device.Context.MapSubresource(m_vertexBuffer, 0, MapMode.WriteDiscard, SharpDX.Direct3D11.MapFlags.None);

                int offset = 0;
                foreach (var input in inputs)
                {
                    // search position sematntics
                    VertexAttribute attr;
                    var             semantics = (Semantics)Enum.Parse(typeof(Semantics), input.SemanticName, true);
                    if (semantics == Semantics.POSITION)
                    {
                        if (m_attributes.TryGetValue(semantics, out attr))
                        {
                            _buffer.Set(_skinnedPosition, offset);
                        }
                        break;
                    }
                    offset += GetSize(input);
                }

                Marshal.Copy(_buffer.Buffer, 0, box.DataPointer, _buffer.Buffer.Length);

                device.Context.UnmapSubresource(m_vertexBuffer, 0);
            }

            return(m_vertexBuffer);
        }