working on GL Effect and added CurveKey.cs and CurveKeyCollection.cs

This commit is contained in:
SND\AstrorEnales_cp 2011-11-15 21:37:26 +00:00
parent 4cbf5d9c21
commit a36695b15b
4 changed files with 432 additions and 42 deletions

View File

@ -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
/// </summary>
public class EffectGL3 : INativeEffect
{
#region Constants
private const string FragmentSeparator = "##!fragment!##";
#endregion
#region Private
/// <summary>
/// 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<EffectTechnique> Techniques
{
get
{
List<EffectTechnique> techniques = new List<EffectTechnique>();
// TODO: dummy, fill with actual data.
techniques.Add(new EffectTechnique());
return techniques;
}
}
#endregion
#region Parameters (TODO)
public IEnumerable<EffectParameter> Parameters
{
get
{
List<EffectParameter> parameters = new List<EffectParameter>();
// TODO: dummy, fill with actual data.
parameters.Add(new EffectParameter());
return parameters;
}
}
#endregion
#endregion
#region Constructor
/// <summary>
/// Create a new effect instance of separate streams.
/// </summary>
@ -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));
}
/// <summary>
@ -84,7 +130,14 @@ namespace ANX.Framework.Windows.GL3
/// <param name="byteCode">The byte code of the shader.</param>
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<EffectTechnique> Techniques
{
get
{
List<EffectTechnique> techniques = new List<EffectTechnique>();
// TODO: dummy, fill with actual data.
techniques.Add(new EffectTechnique());
return techniques;
}
}
public IEnumerable<EffectParameter> Parameters
{
get
{
List<EffectParameter> parameters = new List<EffectParameter>();
// 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
}
}
}

View File

@ -126,6 +126,8 @@
<Compile Include="Content\SystemTypeReaders\TimeSpanReader.cs" />
<Compile Include="Content\MathTypeReaders\ColorReader.cs" />
<Compile Include="CurveContinuity.cs" />
<Compile Include="CurveKey.cs" />
<Compile Include="CurveKeyCollection.cs" />
<Compile Include="CurveLoopType.cs" />
<Compile Include="CurveTangent.cs" />
<Compile Include="DisplayOrientation.cs" />

192
ANX.Framework/CurveKey.cs Normal file
View File

@ -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<CurveKey>, IComparable<CurveKey>
{
#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
}
}

View File

@ -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<CurveKey>,
IEnumerable<CurveKey>, IEnumerable
{
#region Private
private List<CurveKey> 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<CurveKey>();
}
#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<CurveKey>(keys),
};
}
#endregion
#region GetEnumerator
public IEnumerator<CurveKey> GetEnumerator()
{
return keys.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return ((IEnumerable)keys).GetEnumerator();
}
#endregion
}
}