2012-08-17 14:16:58 +00:00
|
|
|
|
#region Using Statements
|
|
|
|
|
using System;
|
2012-11-04 08:46:52 +00:00
|
|
|
|
using System.ComponentModel;
|
2012-08-17 14:16:58 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using ANX.Framework.Content.Pipeline.Graphics;
|
2012-11-04 08:46:52 +00:00
|
|
|
|
using ANX.Framework.Content.Pipeline.Helpers.GL3;
|
2012-08-17 14:16:58 +00:00
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
// This file is part of the ANX.Framework created by the
|
|
|
|
|
// "ANX.Framework developer group" and released under the Ms-PL license.
|
|
|
|
|
// For details see: http://anxframework.codeplex.com/license
|
|
|
|
|
|
|
|
|
|
namespace ANX.Framework.Content.Pipeline.Processors
|
|
|
|
|
{
|
2015-04-08 14:50:03 +02:00
|
|
|
|
[ContentProcessor(DisplayName = "EffectProcessor - ANX Framework")]
|
2012-08-17 14:16:58 +00:00
|
|
|
|
public class EffectProcessor : ContentProcessor<EffectContent, CompiledEffectContent>
|
|
|
|
|
{
|
2012-08-22 10:34:39 +00:00
|
|
|
|
HLSLCompilerFactory hlslCompilerFactory = new HLSLCompilerFactory();
|
|
|
|
|
private string targetProfile = "fx_4_0";
|
|
|
|
|
|
2015-04-08 14:50:03 +02:00
|
|
|
|
[DefaultValue(EffectProcessorDebugMode.Auto)]
|
2012-08-17 14:16:58 +00:00
|
|
|
|
public virtual EffectProcessorDebugMode DebugMode
|
|
|
|
|
{
|
|
|
|
|
get;
|
|
|
|
|
set;
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-08 14:50:03 +02:00
|
|
|
|
[DefaultValue(null)]
|
2012-08-17 14:16:58 +00:00
|
|
|
|
public virtual string Defines
|
|
|
|
|
{
|
|
|
|
|
get;
|
|
|
|
|
set;
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-22 10:34:39 +00:00
|
|
|
|
[DefaultValue("fx_4_0")]
|
|
|
|
|
public virtual string TargetProfile
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return targetProfile;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
targetProfile = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-08 14:50:03 +02:00
|
|
|
|
public EffectProcessor()
|
|
|
|
|
{
|
|
|
|
|
DebugMode = EffectProcessorDebugMode.Auto;
|
|
|
|
|
Defines = null;
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-17 14:16:58 +00:00
|
|
|
|
public override CompiledEffectContent Process(EffectContent input, ContentProcessorContext context)
|
|
|
|
|
{
|
2012-08-27 18:42:54 +00:00
|
|
|
|
byte[] effectCompiledCode = null;
|
2012-08-22 10:34:39 +00:00
|
|
|
|
|
2012-11-13 10:56:53 +00:00
|
|
|
|
switch (input.SourceLanguage)
|
2012-08-27 18:42:54 +00:00
|
|
|
|
{
|
2012-11-13 10:56:53 +00:00
|
|
|
|
case NonXNA.EffectSourceLanguage.HLSL_FX:
|
|
|
|
|
HLSLCompiler compiler = hlslCompilerFactory.Compilers.Last<HLSLCompiler>();
|
|
|
|
|
effectCompiledCode = compiler.Compile(input.EffectCode, DebugMode, TargetProfile);
|
|
|
|
|
break;
|
|
|
|
|
case NonXNA.EffectSourceLanguage.GLSL_FX:
|
|
|
|
|
//TODO: parse and split the effect code and save two effect globs
|
|
|
|
|
// if we do it this way, we don't need to parse the glsl source at runtime when loading it.
|
2012-08-27 18:42:54 +00:00
|
|
|
|
|
2012-11-13 10:56:53 +00:00
|
|
|
|
effectCompiledCode = ShaderHelper.SaveShaderCode(input.EffectCode);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
throw new InvalidContentException("EffectProcessor is unable to process content with format '" + input.SourceLanguage.ToString() + "'");
|
2012-08-27 18:42:54 +00:00
|
|
|
|
}
|
2012-08-21 12:10:40 +00:00
|
|
|
|
|
2015-04-08 14:50:03 +02:00
|
|
|
|
var result = new CompiledEffectContent(effectCompiledCode)
|
2012-08-21 12:10:40 +00:00
|
|
|
|
{
|
|
|
|
|
Identity = input.Identity,
|
|
|
|
|
Name = input.Name,
|
2012-08-27 18:42:54 +00:00
|
|
|
|
SourceLanguage = input.SourceLanguage,
|
2012-08-21 12:10:40 +00:00
|
|
|
|
};
|
2015-04-08 14:50:03 +02:00
|
|
|
|
|
|
|
|
|
result.OpaqueData.AddRange(input.OpaqueData);
|
|
|
|
|
|
|
|
|
|
return result;
|
2012-08-17 14:16:58 +00:00
|
|
|
|
}
|
2012-08-22 10:34:39 +00:00
|
|
|
|
|
|
|
|
|
|
2012-08-17 14:16:58 +00:00
|
|
|
|
}
|
|
|
|
|
}
|