forked from MonoGame/MonoGame
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor ShaderProfile to allow for pipeline extensibility (MonoGame#…
…4992) * Refactored the ShaderProfile enum into extensible class. * Added Enumeration<T> for easier creation of enumeration types. Refactored shader creation into a single function call. * Helper for deleting files without exceptions. * Missed in previous commit. * Added XB1 and Vita to platforms. * Added new LoadedTypeCollection<T> helper. Refactor ShaderProfile to not try to mimic an Enum.
- Loading branch information
1 parent
c21c33d
commit 65a4a74
Showing
22 changed files
with
433 additions
and
179 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
MonoGame.Framework.Content.Pipeline/LoadedTypeCollection.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// 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. | ||
|
||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reflection; | ||
|
||
|
||
namespace Microsoft.Xna.Framework.Content.Pipeline | ||
{ | ||
/// <summary> | ||
/// A helper for collecting instances of a particular type | ||
/// by scanning the types in loaded assemblies. | ||
/// </summary> | ||
public class LoadedTypeCollection<T> : IEnumerable<T> | ||
{ | ||
private static List<T> _all; | ||
|
||
public LoadedTypeCollection() | ||
{ | ||
// Hook into assembly loading events to gather any new | ||
// enumeration types that are found. | ||
AppDomain.CurrentDomain.AssemblyLoad += (sender, args) => ScanAssembly(args.LoadedAssembly); | ||
} | ||
|
||
private static void ScanAssembly(Assembly ass) | ||
{ | ||
// Initialize the list on first use. | ||
if (_all == null) | ||
_all = new List<T>(24); | ||
|
||
var thisAss = typeof(T).Assembly; | ||
|
||
// If the assembly doesn't reference our assembly then it | ||
// cannot contain this type... so skip scanning it. | ||
var refAss = ass.GetReferencedAssemblies(); | ||
if (thisAss.FullName != ass.FullName && refAss.All(r => r.FullName != thisAss.FullName)) | ||
return; | ||
|
||
var definedTypes = ass.DefinedTypes; | ||
|
||
foreach (var type in definedTypes) | ||
{ | ||
if (!type.IsSubclassOf(typeof(T)) || type.IsAbstract) | ||
continue; | ||
|
||
// Create an instance of the type and add it to our list. | ||
var ttype = (T)Activator.CreateInstance(type); | ||
_all.Add(ttype); | ||
} | ||
} | ||
|
||
public IEnumerator<T> GetEnumerator() | ||
{ | ||
if (_all == null) | ||
{ | ||
var assemblies = AppDomain.CurrentDomain.GetAssemblies(); | ||
foreach (var ass in assemblies) | ||
ScanAssembly(ass); | ||
} | ||
|
||
return _all.GetEnumerator(); | ||
} | ||
|
||
IEnumerator IEnumerable.GetEnumerator() | ||
{ | ||
return GetEnumerator(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,24 @@ | ||
namespace TwoMGFX | ||
// 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. | ||
|
||
namespace TwoMGFX | ||
{ | ||
public class Options | ||
{ | ||
[Utilities.CommandLineParser.Required] | ||
[CommandLineParser.Required] | ||
public string SourceFile; | ||
|
||
[Utilities.CommandLineParser.Required] | ||
[CommandLineParser.Required] | ||
public string OutputFile = string.Empty; | ||
|
||
[Utilities.CommandLineParser.Name("Profile", "\t - Must be either DirectX_11, OpenGL, or PlayStation4")] | ||
[CommandLineParser.ProfileName] | ||
public ShaderProfile Profile = ShaderProfile.OpenGL; | ||
|
||
[Utilities.CommandLineParser.Name("DEBUG")] | ||
[CommandLineParser.Name("Debug", "\t\t - Include extra debug information in the compiled effect.")] | ||
public bool Debug; | ||
|
||
[Utilities.CommandLineParser.Name("Defines", "\t - Semicolon-delimited define assignments")] | ||
[CommandLineParser.Name("Defines", "\t - Semicolon-delimited define assignments")] | ||
public string Defines; | ||
} | ||
} |
Oops, something went wrong.