protected override Effect ReadContent(IContentManager readerManager, GraphicsDevice device, string assetName, Stream stream, object options) { var effectData = EffectData.Load(stream); if (effectData == null) { return(null); } return(new Effect(device, effectData)); }
protected override Effect ReadContent(IContentManager readerManager, GraphicsDevice device, ref ContentReaderParameters parameters) { var effectData = EffectData.Load(parameters.Stream); if (effectData == null) { return(null); } if (parameters.AssetType == typeof(Effect)) { return(new Effect(device, effectData)); } // Else, create a specific instance of effect using a constructor (GraphicsDevice, EffectData) return((Effect)Activator.CreateInstance(parameters.AssetType, device, effectData)); }
void Run(string[] args) { var assemblyUri = new Uri(Assembly.GetEntryAssembly().CodeBase); var assemblyPath = Path.GetDirectoryName(assemblyUri.LocalPath); var newPath = Path.GetFullPath(Path.Combine(assemblyPath, @"..\Redist\D3D\" + (IntPtr.Size == 4 ? "x86" : "x64"))) + ";" + Environment.GetEnvironmentVariable("PATH"); Environment.SetEnvironmentVariable("PATH", newPath); // Print the exe header PrintHeader(); // Parse the command line if (!ParseCommandLine(args)) { Environment.Exit(-1); } var options = this; // ---------------------------------------------------------------- // Process macros // ---------------------------------------------------------------- var macros = new List <EffectData.ShaderMacro>(); foreach (var define in options.Defines) { var nameValue = define.Split('='); string name = nameValue[0]; string value = null; if (nameValue.Length > 1) { value = nameValue[1]; } macros.Add(new EffectData.ShaderMacro(name, value)); } // ---------------------------------------------------------------- // Setup compiler flags // ---------------------------------------------------------------- var flags = EffectCompilerFlags.None; if (options.Debug) { flags |= EffectCompilerFlags.Debug; } switch (options.OptimizationLevel) { case 0: flags |= EffectCompilerFlags.OptimizationLevel0; break; case 1: flags |= EffectCompilerFlags.OptimizationLevel1; break; case 2: flags |= EffectCompilerFlags.OptimizationLevel2; break; case 3: flags |= EffectCompilerFlags.OptimizationLevel3; break; } if (options.PackRowMajor) { flags |= EffectCompilerFlags.PackMatrixRowMajor; } if (options.PackColumnMajor) { flags |= EffectCompilerFlags.PackMatrixColumnMajor; } if (options.AvoidFlowControl) { flags |= EffectCompilerFlags.AvoidFlowControl; } if (options.PreferFlowControl) { flags |= EffectCompilerFlags.PreferFlowControl; } if (options.EnableStrictness) { flags |= EffectCompilerFlags.EnableStrictness; } if (options.EnableBackwardsCompatibility) { flags |= EffectCompilerFlags.EnableBackwardsCompatibility; } if (options.IeeeStrictness) { flags |= EffectCompilerFlags.IeeeStrictness; } hasErrors = false; // ---------------------------------------------------------------- // Process each fx files / tkfxo files // ---------------------------------------------------------------- var fxFile = options.FxFile; var filePath = Path.Combine(Environment.CurrentDirectory, fxFile); // Check that input file exists if (!File.Exists(filePath)) { ErrorColor(); Console.Error.WriteLine("File [{0}] does not exist", fxFile); ResetColor(); Abort(); } // ---------------------------------------------------------------- // Pre check files // ---------------------------------------------------------------- if (options.OutputClassFile == null && options.OutputFile == null) { options.OutputFile = Path.GetFileNameWithoutExtension(options.FxFile) + ".tkb"; } // Check for output files bool outputFileExist = options.OutputClassFile != null && File.Exists(options.OutputClassFile); if (options.OutputFile != null && !File.Exists(options.OutputFile)) { outputFileExist = false; } // New Compiler var compiler = new EffectCompiler(); string outputDependencyDirPath = Path.Combine(Environment.CurrentDirectory, OutputDependencyDirectory); string outputDependencyFilePath = Path.Combine(outputDependencyDirPath, compiler.GetDependencyFileNameFromSourcePath(options.FxFile)); if (AllowDynamicCompiling) { CompileOnlyIfNewer = true; } if (CompileOnlyIfNewer) { if (!compiler.CheckForChanges(outputDependencyFilePath) && outputFileExist) { Console.Error.WriteLine("Nothing to compile. Output file [{0}] is up-to-date", options.OutputFile); Environment.Exit(0); } } var viewOnly = false; // Try to load this file as a precompiled file var effectData = EffectData.Load(fxFile); EffectCompilerResult compilerResult = null; if (effectData != null) { Console.WriteLine("Load Compiled File [{0}]", fxFile); viewOnly = true; } else { // Compile the fx file Console.WriteLine("Compile Effect File [{0}]", filePath); compilerResult = compiler.Compile(File.ReadAllText(filePath), filePath, flags, macros, options.IncludeDirs, AllowDynamicCompiling, CompileOnlyIfNewer ? outputDependencyFilePath : null); // If there is any warning, errors, turn Error color on if (compilerResult.Logger.Messages.Count > 0) { ErrorColor(); } // Show a message error for the current file if (compilerResult.HasErrors) { Console.Error.WriteLine("Error when compiling file [{0}]:", fxFile); hasErrors = true; } // Print all messages (warning and errors) foreach (var logMessage in compilerResult.Logger.Messages) { Console.WriteLine(logMessage); } // If we have some messages, reset the color back if (compilerResult.Logger.Messages.Count > 0) { ResetColor(); } effectData = compilerResult.EffectData; } if (!NoDisassembly && effectData != null) { DumpBytecode(compiler, effectData); } if (hasErrors) { Abort(); } if (!viewOnly) { Console.WriteLine(); if (CompileOnlyIfNewer && compilerResult.DependencyFilePath != null) { // Dependency file save to Console.WriteLine("Save dependency list to [{0}]", outputDependencyFilePath); } if (OutputClassFile != null) { var codeWriter = new EffectDataCodeWriter { Namespace = OutputNamespace, ClassName = OutputClassname ?? Path.GetFileNameWithoutExtension(OutputClassFile), FieldName = OutputFieldName, }; Console.WriteLine("Save C# code output to [{0}]", OutputClassFile); using (var stream = new NativeFileStream(OutputClassFile, NativeFileMode.Create, NativeFileAccess.Write, NativeFileShare.Write)) codeWriter.Write(effectData, new StreamWriter(stream, Encoding.UTF8)); } if (options.OutputFile != null) { Console.WriteLine("Save binary output to [{0}]", options.OutputFile); // Save the result effectData.Save(options.OutputFile); } } }
/// <summary> /// Initializes a new instance of the <see cref="Effect"/> class with the specified bytecode effect. See remarks. /// </summary> /// <param name="device">The device.</param> /// <param name="bytecode">The bytecode to add to <see cref="GraphicsDevice.DefaultEffectPool"/>. This bytecode must contain only one effect.</param> /// <exception cref="ArgumentException">If the bytecode doesn't contain a single effect.</exception> /// <remarks> /// The effect bytecode must contain only a single effect and will be registered into the <see cref="GraphicsDevice.DefaultEffectPool"/>. /// </remarks> public Effect(GraphicsDevice device, byte[] bytecode) : this(device, EffectData.Load(bytecode)) { }
public object ReadContent(IContentManager readerManager, ref ContentReaderParameters parameters) { parameters.KeepStreamOpen = false; return(EffectData.Load(parameters.Stream)); }
public object ReadContent(IContentManager readerManager, string assetName, Stream stream, out bool keepStreamOpen, object options) { keepStreamOpen = false; return(EffectData.Load(stream)); }