forked from kniEngine/kni
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
74 lines (60 loc) · 2.75 KB
/
Program.cs
File metadata and controls
74 lines (60 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// MonoGame - Copyright (C) The MonoGame Team
// This file is subject to the terms and conditions defined in
// file 'LICENSE.txt', which is part of this source code package.
// Copyright (C)2022 Nick Kastellanos
using System;
using System.IO;
using Microsoft.Xna.Framework.Content.Pipeline;
using Microsoft.Xna.Framework.Content.Pipeline.EffectCompiler;
using Microsoft.Xna.Framework.Content.Pipeline.Graphics;
using Microsoft.Xna.Framework.Content.Pipeline.Processors;
namespace EffectCompiler
{
public static class Program
{
public static int Main(string[] args)
{
Options options = new Options();
CommandLineParser parser = new CommandLineParser(options);
parser.Title = "knifxc - The KNI Effect compiler.";
if (!parser.ParseCommandLine(args))
return 1;
// Validate the input file exits.
if (!File.Exists(options.SourceFile))
{
Console.Error.WriteLine("The input file '{0}' was not found!", options.SourceFile);
return 1;
}
try
{
ContentBuildLogger logger = new BuildLogger();
ContentImporter<EffectContent> importer = new EffectImporter();
ContentImporterContext importerContext = new ImporterContext(logger);
EffectContent content = importer.Import(options.SourceFile, importerContext);
EffectProcessor processor = new EffectProcessor();
processor.Defines = options.Defines;
if (options.Platform == (TargetPlatform)(-1))
{
if (options.Backend.Count == 0)
throw new InvalidOperationException("Missing argument 'Platform' or 'Backend'");
else
options.Platform = TargetPlatform.Windows;
}
ContentProcessorContext processorContext = new ProcessorContext(logger, options.Platform, options.Profile, options.OutputFile, options.Config);
if (options.Backend.Count > 0)
processorContext.Parameters.Add("_GraphicsBackendList", options.Backend);
CompiledEffectContent output = processor.Process(content, processorContext);
byte[] effectCode = output.GetEffectCode();
File.WriteAllBytes(options.OutputFile, effectCode);
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
return 1;
}
// We finished succesfully.
Console.WriteLine("Compiled '{0}' to '{1}'.", options.SourceFile, options.OutputFile);
return 0;
}
}
}