- prepared ContentPipeline to load EffectFiles for the different TargetProfile's. Currently HLSL_FX is working fine and GLSL_FX is prepared (needs testing).

- ContentPipeline effects now have a EffectSourceLanguage parameter
This commit is contained in:
Glatzemann 2012-08-27 18:42:54 +00:00
parent 778b3c1ee2
commit 7eb3e5241e
20 changed files with 210 additions and 60 deletions

View File

@ -57,9 +57,9 @@
<Compile Include="ContentProcessor.cs" />
<Compile Include="ContentProcessorAttribute.cs" />
<Compile Include="ContentProcessorContext.cs" />
<Compile Include="EffectImporter.cs" />
<Compile Include="Importer\EffectImporter.cs" />
<Compile Include="ExternalReference.cs" />
<Compile Include="FbxImporter.cs" />
<Compile Include="Importer\FbxImporter.cs" />
<Compile Include="Graphics\AnimationChannel.cs" />
<Compile Include="Graphics\AnimationChannelDictionary.cs" />
<Compile Include="Graphics\AnimationContent.cs" />
@ -104,6 +104,7 @@
<Compile Include="IContentImporter.cs" />
<Compile Include="IContentProcessor.cs" />
<Compile Include="Importer\TextureImporter.cs" />
<Compile Include="InvalidContentException.cs" />
<Compile Include="NamedValueDictionary.cs" />
<Compile Include="OpaqueDataDictionary.cs" />
<Compile Include="Processors\CompiledEffectContent.cs" />
@ -184,6 +185,10 @@
<Project>{6899F0C9-70B9-4EB0-9DD3-E598D4BE3E35}</Project>
<Name>ANX.Framework</Name>
</ProjectReference>
<ProjectReference Include="..\RenderSystems\ANX.Framework.Windows.GL3\ANX.RenderSystem.Windows.GL3.csproj">
<Project>{EB8258E0-6741-4DB9-B756-1EBDF67B1ED6}</Project>
<Name>ANX.RenderSystem.Windows.GL3</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

View File

@ -1,34 +0,0 @@
#region Using Statements
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ANX.Framework.Content.Pipeline.Graphics;
#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
{
[ContentImporter(new string[] { ".fx", ".fxg" })]
public class EffectImporter : ContentImporter<EffectContent>
{
public EffectImporter()
{
}
public override EffectContent Import(string filename, ContentImporterContext context)
{
EffectContent content = new EffectContent()
{
EffectCode = System.IO.File.ReadAllText(filename),
Identity = new ContentIdentity(filename, null, null),
};
return content;
}
}
}

View File

@ -3,6 +3,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ANX.Framework.NonXNA;
#endregion
@ -14,11 +15,13 @@ namespace ANX.Framework.Content.Pipeline.Graphics
{
public class EffectContent : ContentItem
{
public EffectContent()
public string EffectCode
{
get;
set;
}
public string EffectCode
public EffectSourceLanguage SourceLanguage
{
get;
set;

View File

@ -0,0 +1,54 @@
#region Using Statements
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ANX.Framework.Content.Pipeline.Graphics;
using System.IO;
using ANX.Framework.NonXNA;
#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
{
[ContentImporter(new string[] { ".fx", ".fxg", ".hlsl", ".glsl" })]
public class EffectImporter : ContentImporter<EffectContent>
{
public override EffectContent Import(string filename, ContentImporterContext context)
{
string fileExtension = Path.GetExtension(filename).ToLowerInvariant();
EffectSourceLanguage sourceLanguage = EffectSourceLanguage.HLSL_FX;
switch (fileExtension)
{
case ".fx":
sourceLanguage = EffectSourceLanguage.HLSL_FX;
break;
case ".fxg":
sourceLanguage = EffectSourceLanguage.GLSL_FX;
break;
case ".hlsl":
sourceLanguage = EffectSourceLanguage.HLSL;
break;
case ".glsl":
sourceLanguage = EffectSourceLanguage.GLSL;
break;
default:
throw new InvalidContentException("The EffectImporter is not able to import a file with extension '" + fileExtension + "'");
}
EffectContent content = new EffectContent()
{
EffectCode = System.IO.File.ReadAllText(filename),
Identity = new ContentIdentity(filename, null, null),
SourceLanguage = sourceLanguage,
};
return content;
}
}
}

View File

@ -0,0 +1,20 @@
#region Using Statements
using System;
#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
{
public class InvalidContentException : Exception
{
public InvalidContentException(string message)
: base(message)
{
}
}
}

View File

@ -3,6 +3,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ANX.Framework.NonXNA;
#endregion
@ -25,5 +26,11 @@ namespace ANX.Framework.Content.Pipeline.Processors
{
return effectCode;
}
public EffectSourceLanguage SourceLanguage
{
get;
set;
}
}
}

View File

@ -6,6 +6,7 @@ using System.Text;
using ANX.Framework.Content.Pipeline.Graphics;
using System.IO;
using System.ComponentModel;
using ANX.RenderSystem.Windows.GL3;
#endregion
@ -48,15 +49,31 @@ namespace ANX.Framework.Content.Pipeline.Processors
public override CompiledEffectContent Process(EffectContent input, ContentProcessorContext context)
{
HLSLCompiler compiler = hlslCompilerFactory.Compilers.Last<HLSLCompiler>();
byte[] effectCompiledCode = null;
byte[] effectCompiledCode = compiler.Compile(input.EffectCode, DebugMode, TargetProfile);
if (input.SourceLanguage == NonXNA.EffectSourceLanguage.HLSL_FX)
{
HLSLCompiler compiler = hlslCompilerFactory.Compilers.Last<HLSLCompiler>();
effectCompiledCode = compiler.Compile(input.EffectCode, DebugMode, TargetProfile);
}
else if (input.SourceLanguage == 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.
effectCompiledCode = ShaderHelper.SaveShaderCode(input.EffectCode);
}
else
{
throw new InvalidContentException("EffectProcessor is unable to process content with format '" + input.SourceLanguage.ToString() + "'");
}
return new CompiledEffectContent(effectCompiledCode)
{
Identity = input.Identity,
Name = input.Name,
OpaqueData = input.OpaqueData
OpaqueData = input.OpaqueData,
SourceLanguage = input.SourceLanguage,
};
}

View File

@ -34,6 +34,7 @@ namespace ANX.Framework.Content.Pipeline.Serialization.Compiler
}
byte[] effectCode = value.GetEffectCode();
output.Write((byte)value.SourceLanguage); // ANX Extensions !!!
output.Write(effectCode.Length);
output.Write(effectCode);
}

View File

@ -414,6 +414,7 @@
<Compile Include="NonXNA\AddInType.cs" />
<Compile Include="NonXNA\Development\TestStateAttribute.cs" />
<Compile Include="NonXNA\Development\PercentageCompleteAttribute.cs" />
<Compile Include="NonXNA\EffectSourceLanguage.cs" />
<Compile Include="NonXNA\InputDeviceFactory.cs" />
<Compile Include="NonXNA\InputSystem\IGamePadCreator.cs" />
<Compile Include="NonXNA\InputSystem\IKeyboard.cs" />

View File

@ -124,7 +124,7 @@ namespace ANX.Framework.Content
if (magicVA != 'A' || magicVN != 'N' || magicVX != 'X')
{
throw new ContentLoadException("Not an ANX.Framework version 1.0 XNB file.");
throw new ContentLoadException("Not an ANX.Framework version 1.0 XNB file or this is an unsupported past XNA 4.0 XNB file.");
}
anxExtensions = true;

View File

@ -18,6 +18,7 @@ namespace ANX.Framework.Content
protected internal override Effect Read(ContentReader input, Effect existingInstance)
{
IServiceProvider service = input.ContentManager.ServiceProvider;
EffectSourceLanguage sourceLanguageFormat = EffectSourceLanguage.HLSL_FX;
var rfc = service.GetService(typeof(IRenderSystemCreator)) as IRenderSystemCreator;
if (rfc == null)
@ -31,6 +32,11 @@ namespace ANX.Framework.Content
throw new ContentLoadException("Service not found IGraphicsDeviceService");
}
if (input.AnxExtensions)
{
sourceLanguageFormat = (EffectSourceLanguage)input.ReadByte();
}
int totalLength = input.ReadInt32();
byte magicA = input.ReadByte();
@ -47,7 +53,7 @@ namespace ANX.Framework.Content
var memStream = new MemoryStream(effectCode);
// the XNA Way
return new Effect(gds.GraphicsDevice, effectCode);
return new Effect(gds.GraphicsDevice, effectCode, sourceLanguageFormat);
// the ANX Way
//return rfc.CreateEffect(gds.GraphicsDevice, memStream);
@ -72,7 +78,7 @@ namespace ANX.Framework.Content
case EffectProcessorOutputFormat.OPEN_GL3_GLSL:
//return rfc.CreateEffect(gds.GraphicsDevice, new MemoryStream(vertexShaderByteCode, false), new MemoryStream(pixelShaderByteCode, false));
//return rfc.CreateEffect(gds.GraphicsDevice, new MemoryStream(effectByteCode, false));
return new Effect(gds.GraphicsDevice, effectByteCode);
return new Effect(gds.GraphicsDevice, effectByteCode, sourceLanguageFormat);
default:
throw new NotImplementedException("loading of ANX-Effect format with type '" + format.ToString() + "' not yet implemented.");
}

View File

@ -23,6 +23,7 @@ namespace ANX.Framework.Graphics
private EffectTechnique currentTechnique;
private EffectParameterCollection parameterCollection;
private byte[] byteCode;
private EffectSourceLanguage sourceLanguage;
#endregion // Private Members
@ -32,6 +33,11 @@ namespace ANX.Framework.Graphics
}
public Effect(GraphicsDevice graphicsDevice, byte[] byteCode)
: this(graphicsDevice, byteCode, EffectSourceLanguage.HLSL_FX)
{
}
public Effect(GraphicsDevice graphicsDevice, byte[] byteCode, EffectSourceLanguage sourceLanguage)
: base(graphicsDevice)
{
this.byteCode = new byte[byteCode.Length];
@ -40,9 +46,11 @@ namespace ANX.Framework.Graphics
base.GraphicsDevice.ResourceCreated += GraphicsDevice_ResourceCreated;
base.GraphicsDevice.ResourceDestroyed += GraphicsDevice_ResourceDestroyed;
CreateNativeEffect();
CreateNativeEffect(sourceLanguage);
this.currentTechnique = this.techniqueCollection[0];
this.sourceLanguage = sourceLanguage;
}
~Effect()
@ -60,7 +68,7 @@ namespace ANX.Framework.Graphics
nativeEffect = null;
}
CreateNativeEffect();
CreateNativeEffect(this.sourceLanguage);
}
private void GraphicsDevice_ResourceDestroyed(object sender, ResourceDestroyedEventArgs e)
@ -83,7 +91,7 @@ namespace ANX.Framework.Graphics
{
if (nativeEffect == null)
{
CreateNativeEffect();
CreateNativeEffect(this.sourceLanguage);
}
return this.nativeEffect;
@ -132,12 +140,21 @@ namespace ANX.Framework.Graphics
throw new NotImplementedException();
}
private void CreateNativeEffect()
private void CreateNativeEffect(EffectSourceLanguage sourceLanguage)
{
this.nativeEffect = AddInSystemFactory.Instance.GetDefaultCreator<IRenderSystemCreator>().CreateEffect(GraphicsDevice, this, new MemoryStream(this.byteCode, false));
IRenderSystemCreator creator = AddInSystemFactory.Instance.GetDefaultCreator<IRenderSystemCreator>();
this.techniqueCollection = new EffectTechniqueCollection(this, this.nativeEffect);
this.parameterCollection = new EffectParameterCollection(this, this.nativeEffect);
if (creator.IsLanguageSupported(sourceLanguage))
{
this.nativeEffect = creator.CreateEffect(GraphicsDevice, this, new MemoryStream(this.byteCode, false));
this.techniqueCollection = new EffectTechniqueCollection(this, this.nativeEffect);
this.parameterCollection = new EffectParameterCollection(this, this.nativeEffect);
}
else
{
throw new InvalidOperationException("couldn't create " + sourceLanguage.ToString() + " native effect using RenderSystem " + creator.Name);
}
}
}
}

View File

@ -0,0 +1,19 @@
#region Using Statements
using System;
#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.NonXNA
{
public enum EffectSourceLanguage
{
HLSL,
HLSL_FX,
GLSL,
GLSL_FX,
}
}

View File

@ -35,6 +35,8 @@ namespace ANX.Framework.NonXNA
INativeEffect CreateEffect(GraphicsDevice graphics, Effect managedEffect,
Stream vertexShaderByteCode, Stream pixelShaderByteCode);
bool IsLanguageSupported(EffectSourceLanguage sourceLanguage);
INativeBlendState CreateBlendState();
INativeRasterizerState CreateRasterizerState();
INativeDepthStencilState CreateDepthStencilState();

View File

@ -222,5 +222,10 @@ namespace ANX.RenderSystem.Windows.DX10
AddInSystemFactory.Instance.PreventSystemChange(AddInType.RenderSystem);
}
#endregion
}
public bool IsLanguageSupported(EffectSourceLanguage sourceLanguage)
{
return sourceLanguage == EffectSourceLanguage.HLSL_FX || sourceLanguage == EffectSourceLanguage.HLSL;
}
}
}

View File

@ -302,5 +302,11 @@ namespace ANX.RenderSystem.Windows.GL3
preferredDepthFormat, preferredMultiSampleCount, usage);
}
#endregion
}
public bool IsLanguageSupported(EffectSourceLanguage sourceLanguage)
{
return sourceLanguage == EffectSourceLanguage.GLSL_FX || sourceLanguage == EffectSourceLanguage.GLSL;
}
}
}

View File

@ -136,5 +136,12 @@ namespace ANX.RenderSystem.PsVita
{
throw new NotImplementedException();
}
public bool IsLanguageSupported(EffectSourceLanguage sourceLanguage)
{
//TODO: implement supported sourceLanguages
return false;
}
}
}

View File

@ -218,5 +218,11 @@ namespace ANX.RenderSystem.Windows.DX11
return new RenderTarget2D_DX11(graphics, width, height, mipMap, preferredFormat, preferredDepthFormat, preferredMultiSampleCount, usage);
}
public bool IsLanguageSupported(EffectSourceLanguage sourceLanguage)
{
return sourceLanguage == EffectSourceLanguage.HLSL_FX || sourceLanguage == EffectSourceLanguage.HLSL;
}
}
}

View File

@ -5,6 +5,7 @@ using System.Linq;
using System.Text;
using ANX.Framework.Content.Pipeline.Tasks;
using ANX.Framework.Content.Pipeline;
using System.IO;
#endregion
@ -29,14 +30,21 @@ namespace ContentBuilder
{
if (!arg.StartsWith("/") && !arg.StartsWith("-"))
{
BuildItem buildItem = new BuildItem();
buildItem.ImporterName = ImporterManager.GuessImporterByFileExtension(arg);
//TODO: set configured processor name
buildItem.SourceFilename = arg;
buildItem.AssetName = System.IO.Path.GetFileNameWithoutExtension(arg);
buildItem.OutputFilename = String.Format("{0}.xnb", buildItem.AssetName);
if (File.Exists(arg))
{
BuildItem buildItem = new BuildItem();
buildItem.ImporterName = ImporterManager.GuessImporterByFileExtension(arg);
//TODO: set configured processor name
buildItem.SourceFilename = arg;
buildItem.AssetName = System.IO.Path.GetFileNameWithoutExtension(arg);
buildItem.OutputFilename = String.Format("{0}.xnb", buildItem.AssetName);
itemsToBuild.Add(buildItem);
itemsToBuild.Add(buildItem);
}
else
{
buildContentTask.BuildLogger.LogMessage("could not find file '{0}' to import. skipping.", arg);
}
}
else
{