2012-09-15 13:43:31 +00:00
|
|
|
#region Using Statements
|
2011-10-31 05:36:24 +00:00
|
|
|
using System;
|
2012-10-16 05:49:00 +00:00
|
|
|
using ANX.Framework.NonXNA.RenderSystem;
|
2011-10-31 05:36:24 +00:00
|
|
|
using Microsoft.Xna.Framework.Content.Pipeline;
|
2012-08-09 09:45:04 +00:00
|
|
|
using ANX.RenderSystem.Windows.DX10;
|
2012-09-15 13:43:31 +00:00
|
|
|
|
|
|
|
#endregion
|
2011-10-31 05:36:24 +00:00
|
|
|
|
2012-08-09 09:45:04 +00:00
|
|
|
// 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
|
2011-10-31 05:36:24 +00:00
|
|
|
|
|
|
|
using TInput = Microsoft.Xna.Framework.Content.Pipeline.Graphics.EffectContent;
|
|
|
|
using TOutput = Microsoft.Xna.Framework.Content.Pipeline.Processors.CompiledEffectContent;
|
|
|
|
|
|
|
|
namespace ANX.Framework.ContentPipeline
|
|
|
|
{
|
|
|
|
[ContentProcessor(DisplayName = "DX10 Effect - ANX Framework")]
|
|
|
|
public class DX10_EffectProcessor : ContentProcessor<TInput, TOutput>
|
|
|
|
{
|
|
|
|
public override TOutput Process(TInput input, ContentProcessorContext context)
|
|
|
|
{
|
2012-09-15 13:43:31 +00:00
|
|
|
byte[] effectByteCode = EffectDX.CompileFXShader(input.EffectCode);
|
2011-10-31 05:36:24 +00:00
|
|
|
|
|
|
|
Byte[] byteCode = new Byte[3 + 2 + 1 + 4 + effectByteCode.Length];
|
|
|
|
|
|
|
|
StringToByteArray("ANX").CopyTo(byteCode, 0); // Magic Number to recognize format
|
|
|
|
byteCode[3] = 0; // Major Version
|
|
|
|
byteCode[4] = 2; // Minor Version
|
|
|
|
byteCode[5] = (byte)EffectProcessorOutputFormat.DX10_HLSL; // Format of byte array
|
|
|
|
|
|
|
|
int dataStart = 6;
|
|
|
|
|
|
|
|
BitConverter.GetBytes(effectByteCode.Length).CopyTo(byteCode, dataStart); // length of vertexShaderByteCode
|
|
|
|
Array.Copy(effectByteCode, 0, byteCode, dataStart + 4, effectByteCode.Length);
|
|
|
|
|
|
|
|
return new TOutput(byteCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
private byte[] StringToByteArray(string str)
|
|
|
|
{
|
2012-09-09 14:31:03 +00:00
|
|
|
return System.Text.Encoding.ASCII.GetBytes(str);
|
2011-10-31 05:36:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private string ByteArrayToString(byte[] arr)
|
|
|
|
{
|
2012-09-09 14:31:03 +00:00
|
|
|
return System.Text.Encoding.ASCII.GetString(arr);
|
2011-10-31 05:36:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|