Ejemplo n.º 1
0
 public void SetInputLayout(Device device, ShaderSignature inputSignature)
 {
     foreach (ModelMesh mesh in m_meshes)
     {
         mesh.SetInputLayout(device, inputSignature);
     }
     m_inputLayoutSet = true;
 }
Ejemplo n.º 2
0
        private void InitializeShaders()
        {
            var assembly = Assembly.GetExecutingAssembly();

            using (var vxShaderStream = assembly.GetManifestResourceStream("D3D11Shaders.PostProcessingQuad.cso"))
                using (var psShaderStream = assembly.GetManifestResourceStream("D3D11Shaders.PostProcessingColor.cso"))
                {
                    using (var vbc = D3DCompiler.ShaderBytecode.FromStream(vxShaderStream))
                        using (var pbcTm = D3DCompiler.ShaderBytecode.FromStream(psShaderStream))
                        {
                            psToneMapping        = new D3D11.PixelShader(d3dDevice, pbcTm);
                            vsQuad               = new D3D11.VertexShader(d3dDevice, vbc);
                            shaderInputSigVsQuad = D3DCompiler.ShaderSignature.GetInputSignature(vbc);
                        }
                }
        }
Ejemplo n.º 3
0
    void InitializeShaders()
    {
        using (var vertexShaderByteCode = D3DCompiler.ShaderBytecode.CompileFromFile("../../src/vertexShader.hlsl", "main", "vs_4_0", D3DCompiler.ShaderFlags.Debug))
        {
            m_inputSignature = D3DCompiler.ShaderSignature.GetInputOutputSignature(vertexShaderByteCode);
            m_vertexShader   = new D3D11.VertexShader(m_d3d11Device, vertexShaderByteCode);
        }
        using (var pixelShaderByteCode = D3DCompiler.ShaderBytecode.CompileFromFile("../../src/pixelShader.hlsl", "main", "ps_4_0", D3DCompiler.ShaderFlags.Debug))
        {
            m_pixelShader = new D3D11.PixelShader(m_d3d11Device, pixelShaderByteCode);
        }

        m_d3d11DeviceContext.VertexShader.Set(m_vertexShader);
        m_d3d11DeviceContext.PixelShader.Set(m_pixelShader);

        m_d3d11DeviceContext.InputAssembler.PrimitiveTopology = SharpDX.Direct3D.PrimitiveTopology.TriangleList;

        m_inputLayout = new D3D11.InputLayout(m_d3d11Device, m_inputSignature, m_inputElments);
        m_d3d11DeviceContext.InputAssembler.InputLayout = m_inputLayout;
    }
Ejemplo n.º 4
0
        private void InitializeShaders()
        {
            // Compile the vertex shader code
            using(var vertexShaderByteCode = ShaderBytecode.CompileFromFile("vertexShader.hlsl", "main", "vs_4_0", ShaderFlags.Debug))
            {
                // Read input signature from shader code
                inputSignature = ShaderSignature.GetInputSignature(vertexShaderByteCode);

                vertexShader = new D3D11.VertexShader(d3dDevice, vertexShaderByteCode);
            }

            // Compile the pixel shader code
            using(var pixelShaderByteCode = ShaderBytecode.CompileFromFile("pixelShader.hlsl", "main", "ps_4_0", ShaderFlags.Debug))
            {
                pixelShader = new D3D11.PixelShader(d3dDevice, pixelShaderByteCode);
            }

            // Set as current vertex and pixel shaders
            d3dDeviceContext.VertexShader.Set(vertexShader);
            d3dDeviceContext.PixelShader.Set(pixelShader);

            d3dDeviceContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;

            // Create the input layout from the input signature and the input elements
            inputLayout = new D3D11.InputLayout(d3dDevice, inputSignature, inputElements);

            // Set input layout to use
            d3dDeviceContext.InputAssembler.InputLayout = inputLayout;
        }
Ejemplo n.º 5
0
        public static InputLayout CreateInputLayoutFromXml(Device dxDevice, ShaderSignature signature, XmlNode layoutNode)
        {
            InputElement[] elements = new InputElement[layoutNode.ChildNodes.Count];

            int offset = 0;
            XmlNode elemNode = layoutNode.FirstChild;
            for(int i = 0; i < elements.Length; ++i)
            {
                var type = ParseTypeFromXml(elemNode);
                int size;
                var element = CreateInputElement(type, out size);
                element.AlignedByteOffset = offset;
                elements[i] = element;
                offset += size;
                elemNode = elemNode.NextSibling;
            }

            return new InputLayout(dxDevice, signature, elements);
        }
Ejemplo n.º 6
0
        public static InputLayout CreateInputLayout(Device dxDevice, ShaderSignature signature,
            LayoutElementType[] elementTypes)
        {
            InputElement[] elements = new InputElement[elementTypes.Length];

            int offset = 0;
            for(int i = 0; i < elements.Length; ++i)
            {
                var type = elementTypes[i];
                int size;
                var element = CreateInputElement(type, out size);
                element.AlignedByteOffset = offset;
                elements[i] = element;
                offset += size;
            }

            return new InputLayout(dxDevice, signature, elements);
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Sets the input layout and make sure it matches the vertex format from the shader
 /// </summary>
 /// <param name="device"></param>
 /// <param name="inputSignature"></param>
 public void SetInputLayout(Device device, ShaderSignature inputSignature)
 {
     m_inputLayout = new InputLayout(device, inputSignature, m_inputElements);
     if (m_inputLayout == null)
     {
         throw new Exception("mesh and vertex shader input layouts do not match!");
     }
 }