示例#1
0
        protected override void CompileInternal(ShaderStage shaderStage, string filePath, VertexType vertexType)
        {
            var macros = Macros.Select(macro => new ShaderMacro(macro.Key, macro.Value)).ToArray();

            using var includeHandler = new IncludeHandler(null);

            _shaderBytecode = LoadBytecode(shaderStage, filePath, includeHandler, macros);

            if (shaderStage == ShaderStage.Vertex && vertexType != VertexType.Unknown)
            {
                InputLayout = _graphicsFactory.CreateInputLayout(vertexType, _shaderBytecode);
            }

            switch (shaderStage)
            {
            case ShaderStage.Vertex:
                _shaderObject = new VertexShader(_graphicsDevice, _shaderBytecode);
                break;

            case ShaderStage.Pixel:
                _shaderObject = new PixelShader(_graphicsDevice, _shaderBytecode);
                break;

            case ShaderStage.Compute:
                _shaderObject = new ComputeShader(_graphicsDevice, _shaderBytecode);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(shaderStage), shaderStage, null);
            }
        }
示例#2
0
        private DeviceChild CreateShader(ShaderStage shaderStage, VertexType vertexType)
        {
            if (shaderStage == ShaderStage.Vertex && vertexType != VertexType.Unknown)
            {
                InputLayout = _graphicsFactory.CreateInputLayout(vertexType, _shaderBytecode);
            }

            return(shaderStage switch
            {
                ShaderStage.Vertex => new VertexShader(_graphicsDevice, _shaderBytecode),
                ShaderStage.Pixel => new PixelShader(_graphicsDevice, _shaderBytecode),
                ShaderStage.Compute => new ComputeShader(_graphicsDevice, _shaderBytecode),
                _ => throw new ArgumentOutOfRangeException(nameof(shaderStage), shaderStage, null)
            });