diff --git a/ANX.Framework.Windows.GL3/EffectGL3.cs b/ANX.Framework.Windows.GL3/EffectGL3.cs index 555bb0b4..dc4c4e34 100644 --- a/ANX.Framework.Windows.GL3/EffectGL3.cs +++ b/ANX.Framework.Windows.GL3/EffectGL3.cs @@ -4,6 +4,7 @@ using System.IO; using ANX.Framework.Graphics; using ANX.Framework.NonXNA; using OpenTK.Graphics.OpenGL; +using System.Text; #region License @@ -59,6 +60,10 @@ namespace ANX.Framework.Windows.GL3 /// public class EffectGL3 : INativeEffect { + #region Constants + private const string FragmentSeparator = "##!fragment!##"; + #endregion + #region Private /// /// The native shader handle. @@ -66,7 +71,39 @@ namespace ANX.Framework.Windows.GL3 private int programHandle; #endregion - #region Constructor (TODO) + #region Public + #region Techniques (TODO) + public IEnumerable Techniques + { + get + { + List techniques = new List(); + + // TODO: dummy, fill with actual data. + techniques.Add(new EffectTechnique()); + + return techniques; + } + } + #endregion + + #region Parameters (TODO) + public IEnumerable Parameters + { + get + { + List parameters = new List(); + + // TODO: dummy, fill with actual data. + parameters.Add(new EffectParameter()); + + return parameters; + } + } + #endregion + #endregion + + #region Constructor /// /// Create a new effect instance of separate streams. /// @@ -75,7 +112,16 @@ namespace ANX.Framework.Windows.GL3 public EffectGL3(Stream vertexShaderByteCode, Stream pixelShaderByteCode) { - CreateShader("", ""); + byte[] vertexBytes = new byte[vertexShaderByteCode.Length]; + vertexShaderByteCode.Read(vertexBytes, 0, + (int)vertexShaderByteCode.Length); + + byte[] fragmentBytes = new byte[pixelShaderByteCode.Length]; + pixelShaderByteCode.Read(fragmentBytes, 0, + (int)pixelShaderByteCode.Length); + + CreateShader(Encoding.ASCII.GetString(vertexBytes), + Encoding.ASCII.GetString(fragmentBytes)); } /// @@ -84,7 +130,14 @@ namespace ANX.Framework.Windows.GL3 /// The byte code of the shader. public EffectGL3(Stream byteCode) { - CreateShader("", ""); + byte[] byteData = new byte[byteCode.Length]; + byteCode.Read(byteData, 0, (int)byteCode.Length); + + string source = Encoding.ASCII.GetString(byteData); + string[] parts = source.Split(new string[] { FragmentSeparator }, + StringSplitOptions.RemoveEmptyEntries); + + CreateShader(parts[0], parts[1]); } #endregion @@ -129,7 +182,7 @@ namespace ANX.Framework.Windows.GL3 { GL.ShaderSource(shader, source); GL.CompileShader(shader); - + int result; GL.GetShader(shader, ShaderParameter.CompileStatus, out result); if (result == 0) @@ -144,50 +197,20 @@ namespace ANX.Framework.Windows.GL3 return null; } - - public static byte[] CompileShader(string effectCode) - { - //TODO: pre-compiled shaders are supported in GL 4.1 and newer only ?!? - //TODO: encode string somehow to protect shader source - System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding(); - return enc.GetBytes(effectCode); - } - #endregion - #region INativeEffect Member + #region CompileShader (for external) + public static byte[] CompileShader(string effectCode) + { + return Encoding.ASCII.GetBytes(effectCode); + } + #endregion + #region Apply (TODO) public void Apply(GraphicsDevice graphicsDevice) { throw new NotImplementedException(); } - - public IEnumerable Techniques - { - get - { - List techniques = new List(); - - // TODO: dummy, fill with actual data. - techniques.Add(new EffectTechnique()); - - return techniques; - } - } - - public IEnumerable Parameters - { - get - { - List parameters = new List(); - - // TODO: dummy, fill with actual data. - parameters.Add(new EffectParameter()); - - return parameters; - } - } - #endregion #region Dispose @@ -209,5 +232,5 @@ namespace ANX.Framework.Windows.GL3 } } #endregion - } + } } diff --git a/ANX.Framework/ANX.Framework.csproj b/ANX.Framework/ANX.Framework.csproj index 645acaf8..272cd6ec 100644 --- a/ANX.Framework/ANX.Framework.csproj +++ b/ANX.Framework/ANX.Framework.csproj @@ -126,6 +126,8 @@ + + diff --git a/ANX.Framework/CurveKey.cs b/ANX.Framework/CurveKey.cs new file mode 100644 index 00000000..3e3c47cf --- /dev/null +++ b/ANX.Framework/CurveKey.cs @@ -0,0 +1,192 @@ +using System; + +#region License + +// +// This file is part of the ANX.Framework created by the "ANX.Framework developer group". +// +// This file is released under the Ms-PL license. +// +// +// +// Microsoft Public License (Ms-PL) +// +// This license governs use of the accompanying software. If you use the software, you accept this license. +// If you do not accept the license, do not use the software. +// +// 1.Definitions +// The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning +// here as under U.S. copyright law. +// A "contribution" is the original software, or any additions or changes to the software. +// A "contributor" is any person that distributes its contribution under this license. +// "Licensed patents" are a contributor's patent claims that read directly on its contribution. +// +// 2.Grant of Rights +// (A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations +// in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to +// reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution +// or any derivative works that you create. +// (B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in +// section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed +// patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution +// in the software or derivative works of the contribution in the software. +// +// 3.Conditions and Limitations +// (A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks. +// (B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, your +// patent license from such contributor to the software ends automatically. +// (C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution +// notices that are present in the software. +// (D) If you distribute any portion of the software in source code form, you may do so only under this license by including +// a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or +// object code form, you may only do so under a license that complies with this license. +// (E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees, +// or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the +// extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a +// particular purpose and non-infringement. + +#endregion // License + +namespace ANX.Framework +{ + public class CurveKey : IEquatable, IComparable + { + #region Public + public float Position + { + get; + private set; + } + + public float Value + { + get; + set; + } + + public float TangentIn + { + get; + set; + } + + public float TangentOut + { + get; + set; + } + + public CurveContinuity Continuity + { + get; + set; + } + #endregion + + #region Constructor + public CurveKey(float position, float value) + : this(position, value, 0f, 0f, CurveContinuity.Smooth) + { + } + + public CurveKey(float position, float value, float tangentIn, + float tangentOut) + : this(position, value, tangentIn, tangentOut, CurveContinuity.Smooth) + { + } + + public CurveKey(float position, float value, float tangentIn, + float tangentOut, CurveContinuity continuity) + { + Position = position; + Value = value; + TangentIn = tangentIn; + TangentOut = tangentOut; + Continuity = continuity; + } + #endregion + + #region Clone + public CurveKey Clone() + { + return new CurveKey(Position, Value, TangentIn, TangentOut, Continuity); + } + #endregion + + #region Equals + public bool Equals(CurveKey other) + { + return other != null && + other.Position == Position && + other.Value == Value && + other.TangentIn == TangentIn && + other.TangentOut == TangentOut && + other.Continuity == Continuity; + } + + public override bool Equals(object obj) + { + if (obj is CurveKey) + { + return Equals(obj as CurveKey); + } + return false; + } + #endregion + + #region GetHashCode + public override int GetHashCode() + { + return Position.GetHashCode() + Value.GetHashCode() + + TangentIn.GetHashCode() + TangentOut.GetHashCode() + + Continuity.GetHashCode(); + } + #endregion + + #region Equality + public static bool operator ==(CurveKey a, CurveKey b) + { + if (a == null || + b == null) + { + return (a == null && b == null); + } + + return a.Equals(b); + } + #endregion + + #region Inequality + public static bool operator !=(CurveKey a, CurveKey b) + { + bool isAnull = a == null; + bool isBnull = b == null; + if (isAnull || + isBnull) + { + return isAnull != isBnull; + } + + return a.Position != b.Position || + a.Value != b.Value || + a.TangentIn != b.TangentIn || + a.TangentOut != b.TangentOut || + a.Continuity != b.Continuity; + } + #endregion + + #region CompareTo + public int CompareTo(CurveKey other) + { + if (Position == other.Position) + { + return 0; + } + + return Position >= other.Position ? + 1 : + -1; + } + #endregion + } +} diff --git a/ANX.Framework/CurveKeyCollection.cs b/ANX.Framework/CurveKeyCollection.cs new file mode 100644 index 00000000..c7e0af1f --- /dev/null +++ b/ANX.Framework/CurveKeyCollection.cs @@ -0,0 +1,173 @@ +using System; +using System.Collections; +using System.Collections.Generic; + +#region License + +// +// This file is part of the ANX.Framework created by the "ANX.Framework developer group". +// +// This file is released under the Ms-PL license. +// +// +// +// Microsoft Public License (Ms-PL) +// +// This license governs use of the accompanying software. If you use the software, you accept this license. +// If you do not accept the license, do not use the software. +// +// 1.Definitions +// The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning +// here as under U.S. copyright law. +// A "contribution" is the original software, or any additions or changes to the software. +// A "contributor" is any person that distributes its contribution under this license. +// "Licensed patents" are a contributor's patent claims that read directly on its contribution. +// +// 2.Grant of Rights +// (A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations +// in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to +// reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution +// or any derivative works that you create. +// (B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in +// section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed +// patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution +// in the software or derivative works of the contribution in the software. +// +// 3.Conditions and Limitations +// (A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks. +// (B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, your +// patent license from such contributor to the software ends automatically. +// (C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution +// notices that are present in the software. +// (D) If you distribute any portion of the software in source code form, you may do so only under this license by including +// a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or +// object code form, you may only do so under a license that complies with this license. +// (E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees, +// or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the +// extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a +// particular purpose and non-infringement. + +#endregion // License + +namespace ANX.Framework +{ + public class CurveKeyCollection : ICollection, + IEnumerable, IEnumerable + { + #region Private + private List keys; + #endregion + + #region Public + public int Count + { + get + { + return keys.Count; + } + } + + public bool IsReadOnly + { + get + { + return false; + } + } + + public CurveKey this[int index] + { + get + { + return keys[index]; + } + set + { + keys[index] = value; + } + } + #endregion + + #region Constructor + public CurveKeyCollection() + { + keys = new List(); + } + #endregion + + #region Add + public void Add(CurveKey item) + { + if (item == null) + { + throw new ArgumentNullException(); + } + keys.Add(item); + } + #endregion + + #region Clear + public void Clear() + { + keys.Clear(); + } + #endregion + + #region Contains + public bool Contains(CurveKey item) + { + return keys.Contains(item); + } + #endregion + + #region CopyTo + public void CopyTo(CurveKey[] array, int arrayIndex) + { + keys.CopyTo(array, arrayIndex); + } + #endregion + + #region Remove + public bool Remove(CurveKey item) + { + return keys.Remove(item); + } + #endregion + + #region RemoveAt + public void RemoveAt(int index) + { + keys.RemoveAt(index); + } + #endregion + + #region IndexOf + public int IndexOf(CurveKey item) + { + return keys.IndexOf(item); + } + #endregion + + #region Clone + public CurveKeyCollection Clone() + { + return new CurveKeyCollection + { + keys = new List(keys), + }; + } + #endregion + + #region GetEnumerator + public IEnumerator GetEnumerator() + { + return keys.GetEnumerator(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return ((IEnumerable)keys).GetEnumerator(); + } + #endregion + } +}