Going through TODOs in OpenGL render system, and implemented

most of the EffectParameter.SetData overloads.
This commit is contained in:
SND\AstrorEnales_cp 2011-12-27 11:03:03 +00:00
parent 746582483d
commit ad4fc131de
7 changed files with 294 additions and 131 deletions

View File

@ -190,32 +190,32 @@ namespace ANX.Framework.Windows.GL3
{ {
IsBound = true; IsBound = true;
GL.Enable(EnableCap.Blend); GL.Enable(EnableCap.Blend);
GL.BlendEquationSeparate( GL.BlendEquationSeparate(
TranslateBlendFunction(ColorBlendFunction), TranslateBlendFunction(ColorBlendFunction),
TranslateBlendFunction(AlphaBlendFunction)); TranslateBlendFunction(AlphaBlendFunction));
ErrorHelper.Check("BlendEquationSeparate"); ErrorHelper.Check("BlendEquationSeparate");
GL.BlendFuncSeparate( GL.BlendFuncSeparate(
TranslateBlendSrc(ColorSourceBlend), TranslateBlendSrc(ColorSourceBlend),
TranslateBlendDest(ColorDestinationBlend), TranslateBlendDest(ColorDestinationBlend),
TranslateBlendSrc(AlphaSourceBlend), TranslateBlendSrc(AlphaSourceBlend),
TranslateBlendDest(AlphaDestinationBlend)); TranslateBlendDest(AlphaDestinationBlend));
ErrorHelper.Check("BlendFuncSeparate"); ErrorHelper.Check("BlendFuncSeparate");
SetColorWriteChannel(0, ColorWriteChannels); SetColorWriteChannel(0, ColorWriteChannels);
SetColorWriteChannel(1, ColorWriteChannels1); SetColorWriteChannel(1, ColorWriteChannels1);
SetColorWriteChannel(2, ColorWriteChannels2); SetColorWriteChannel(2, ColorWriteChannels2);
SetColorWriteChannel(3, ColorWriteChannels3); SetColorWriteChannel(3, ColorWriteChannels3);
GL.BlendColor(BlendFactor.R * DatatypesMapping.ColorMultiplier, GL.BlendColor(BlendFactor.R * DatatypesMapping.ColorMultiplier,
BlendFactor.G * DatatypesMapping.ColorMultiplier, BlendFactor.G * DatatypesMapping.ColorMultiplier,
BlendFactor.B * DatatypesMapping.ColorMultiplier, BlendFactor.B * DatatypesMapping.ColorMultiplier,
BlendFactor.A * DatatypesMapping.ColorMultiplier); BlendFactor.A * DatatypesMapping.ColorMultiplier);
ErrorHelper.Check("BlendColor"); ErrorHelper.Check("BlendColor");
// TODO: multi sample mask // TODO: multi sample mask
} }
#endregion #endregion
@ -356,25 +356,25 @@ namespace ANX.Framework.Windows.GL3
/// <returns>OpenGL Blend Equation Mode.</returns> /// <returns>OpenGL Blend Equation Mode.</returns>
private BlendEquationMode TranslateBlendFunction(BlendFunction func) private BlendEquationMode TranslateBlendFunction(BlendFunction func)
{ {
switch (func) switch (func)
{ {
case BlendFunction.Add: case BlendFunction.Add:
return BlendEquationMode.FuncAdd; return BlendEquationMode.FuncAdd;
case BlendFunction.Subtract: case BlendFunction.Subtract:
return BlendEquationMode.FuncSubtract; return BlendEquationMode.FuncSubtract;
case BlendFunction.ReverseSubtract: case BlendFunction.ReverseSubtract:
return BlendEquationMode.FuncReverseSubtract; return BlendEquationMode.FuncReverseSubtract;
case BlendFunction.Min: case BlendFunction.Min:
return BlendEquationMode.Min; return BlendEquationMode.Min;
case BlendFunction.Max: case BlendFunction.Max:
return BlendEquationMode.Max; return BlendEquationMode.Max;
} }
throw new ArgumentException("don't know how to translate BlendFunction '" + func.ToString() + "' to BlendEquationMode"); throw new ArgumentException("don't know how to translate BlendFunction '" + func.ToString() + "' to BlendEquationMode");
} }
#endregion #endregion
} }

View File

@ -108,7 +108,7 @@ namespace ANX.Framework.Windows.GL3
} }
#endregion #endregion
#region Parameters (TODO) #region Parameters
public IEnumerable<EffectParameter> Parameters public IEnumerable<EffectParameter> Parameters
{ {
get get

View File

@ -80,7 +80,7 @@ namespace ANX.Framework.Windows.GL3
private set; private set;
} }
#endregion #endregion
#region Constructor #region Constructor
/// <summary> /// <summary>
/// Create a ne effect parameter object. /// Create a ne effect parameter object.
@ -115,6 +115,62 @@ namespace ANX.Framework.Windows.GL3
} }
#endregion #endregion
#region SetValue (Matrix[])
/// <summary>
/// Set a Matrix array value to the effect parameter.
/// </summary>
/// <param name="value">Value for the parameter</param>
public void SetValue(Matrix[] value)
{
GL.UseProgram(parentEffect.programHandle);
ErrorHelper.Check("UseProgram");
float[] array = new float[value.Length * 16];
for (int index = 0; index < value.Length; index++)
{
array[(index * 16)] = value[index].M11;
array[(index * 16) + 1] = value[index].M12;
array[(index * 16) + 2] = value[index].M13;
array[(index * 16) + 3] = value[index].M14;
array[(index * 16) + 4] = value[index].M21;
array[(index * 16) + 5] = value[index].M22;
array[(index * 16) + 6] = value[index].M23;
array[(index * 16) + 7] = value[index].M24;
array[(index * 16) + 8] = value[index].M31;
array[(index * 16) + 9] = value[index].M32;
array[(index * 16) + 10] = value[index].M33;
array[(index * 16) + 11] = value[index].M34;
array[(index * 16) + 12] = value[index].M41;
array[(index * 16) + 13] = value[index].M42;
array[(index * 16) + 14] = value[index].M43;
array[(index * 16) + 15] = value[index].M44;
}
GL.UniformMatrix4(UniformIndex, array.Length, false, array);
ErrorHelper.Check("UniformMatrix4v");
}
#endregion
#region SetValue (Quaternion) (TODO)
/// <summary>
/// Set a Quaternion value to the effect parameter.
/// </summary>
/// <param name="value">Value for the parameter</param>
public void SetValue(Quaternion value)
{
throw new NotImplementedException();
}
#endregion
#region SetValue (Quaternion[]) (TODO)
/// <summary>
/// Set a Quaternion array value to the effect parameter.
/// </summary>
/// <param name="value">Value for the parameter</param>
public void SetValue(Quaternion[] value)
{
throw new NotImplementedException();
}
#endregion
#region SetValue (Texture) #region SetValue (Texture)
private Texture textureCache = null; private Texture textureCache = null;
/// <summary> /// <summary>
@ -130,8 +186,6 @@ namespace ANX.Framework.Windows.GL3
{ {
// TODO: multiple texture units // TODO: multiple texture units
TextureUnit textureUnit = TextureUnit.Texture0; TextureUnit textureUnit = TextureUnit.Texture0;
GL.Enable(EnableCap.Texture2D);
ErrorHelper.Check("Enable");
GL.ActiveTexture(textureUnit); GL.ActiveTexture(textureUnit);
ErrorHelper.Check("ActiveTexture"); ErrorHelper.Check("ActiveTexture");
int handle = (value.NativeTexture as Texture2DGL3).NativeHandle; int handle = (value.NativeTexture as Texture2DGL3).NativeHandle;
@ -144,80 +198,187 @@ namespace ANX.Framework.Windows.GL3
} }
#endregion #endregion
#region SetValue (bool) (TODO)
/// <summary>
/// Set a bool value to the effect parameter.
/// </summary>
/// <param name="value">Value for the parameter</param>
public void SetValue(bool value)
{
throw new NotImplementedException();
}
#endregion
public void SetValue(bool value) #region SetValue (bool[]) (TODO)
{ /// <summary>
throw new NotImplementedException(); /// Set a bool array value to the effect parameter.
} /// </summary>
/// <param name="value">Value for the parameter</param>
public void SetValue(bool[] value)
{
throw new NotImplementedException();
}
#endregion
public void SetValue(bool[] value) #region SetValue (int)
{ /// <summary>
throw new NotImplementedException(); /// Set an int value to the effect parameter.
} /// </summary>
/// <param name="value">Value for the parameter</param>
public void SetValue(int value)
{
GL.UseProgram(parentEffect.programHandle);
ErrorHelper.Check("UseProgram");
GL.Uniform1(UniformIndex, value);
ErrorHelper.Check("Uniform1i");
}
#endregion
public void SetValue(int value) #region SetValue (int[])
{ /// <summary>
throw new NotImplementedException(); /// Set an int array value to the effect parameter.
} /// </summary>
/// <param name="value">Value for the parameter</param>
public void SetValue(int[] value)
{
GL.UseProgram(parentEffect.programHandle);
ErrorHelper.Check("UseProgram");
GL.Uniform1(UniformIndex, value.Length, value);
ErrorHelper.Check("Uniform1iv");
}
#endregion
#region SetValue (float)
/// <summary>
/// Set a float value to the effect parameter.
/// </summary>
/// <param name="value">Value for the parameter</param>
public void SetValue(float value)
{
GL.UseProgram(parentEffect.programHandle);
ErrorHelper.Check("UseProgram");
GL.Uniform1(UniformIndex, value);
ErrorHelper.Check("Uniform1f");
}
#endregion
public void SetValue(int[] value) #region SetValue (float[])
{ /// <summary>
throw new NotImplementedException(); /// Set a float array value to the effect parameter.
} /// </summary>
/// <param name="value">Value for the parameter</param>
public void SetValue(float[] value)
{
GL.UseProgram(parentEffect.programHandle);
ErrorHelper.Check("UseProgram");
GL.Uniform1(UniformIndex, value.Length, value);
ErrorHelper.Check("Uniform1fv");
}
#endregion
public void SetValue(Matrix[] value) #region SetValue (Vector2)
{ /// <summary>
throw new NotImplementedException(); /// Set a Vector2 value to the effect parameter.
} /// </summary>
/// <param name="value">Value for the parameter</param>
public void SetValue(Vector2 value)
{
GL.UseProgram(parentEffect.programHandle);
ErrorHelper.Check("UseProgram");
GL.Uniform2(UniformIndex, value.X, value.Y);
ErrorHelper.Check("Uniform2f");
}
#endregion
public void SetValue(Quaternion value) #region SetValue (Vector2[])
{ /// <summary>
throw new NotImplementedException(); /// Set a Vector2 array value to the effect parameter.
} /// </summary>
/// <param name="value">Value for the parameter</param>
public void SetValue(Vector2[] value)
{
GL.UseProgram(parentEffect.programHandle);
ErrorHelper.Check("UseProgram");
float[] array = new float[value.Length * 2];
for(int index = 0; index < value.Length; index++)
{
array[(index * 2)] = value[index].X;
array[(index * 2) + 1] = value[index].Y;
}
GL.Uniform2(UniformIndex, array.Length, array);
ErrorHelper.Check("Uniform2fv");
}
#endregion
public void SetValue(Quaternion[] value) #region SetValue (Vector3)
{ /// <summary>
throw new NotImplementedException(); /// Set a Vector3 value to the effect parameter.
} /// </summary>
/// <param name="value">Value for the parameter</param>
public void SetValue(Vector3 value)
{
GL.UseProgram(parentEffect.programHandle);
ErrorHelper.Check("UseProgram");
GL.Uniform3(UniformIndex, value.X, value.Y, value.Z);
ErrorHelper.Check("Uniform3f");
}
#endregion
public void SetValue(float value) #region SetValue (Vector3[])
{ /// <summary>
throw new NotImplementedException(); /// Set a Vector3 array value to the effect parameter.
} /// </summary>
/// <param name="value">Value for the parameter</param>
public void SetValue(Vector3[] value)
{
GL.UseProgram(parentEffect.programHandle);
ErrorHelper.Check("UseProgram");
float[] array = new float[value.Length * 3];
for (int index = 0; index < value.Length; index++)
{
array[(index * 3)] = value[index].X;
array[(index * 3) + 1] = value[index].Y;
array[(index * 3) + 2] = value[index].Z;
}
GL.Uniform3(UniformIndex, array.Length, array);
ErrorHelper.Check("Uniform3fv");
}
#endregion
public void SetValue(float[] value) #region SetValue (Vector4)
{ /// <summary>
throw new NotImplementedException(); /// Set a Vector4 value to the effect parameter.
} /// </summary>
/// <param name="value">Value for the parameter</param>
public void SetValue(Vector4 value)
{
GL.UseProgram(parentEffect.programHandle);
ErrorHelper.Check("UseProgram");
GL.Uniform4(UniformIndex, value.X, value.Y, value.Z, value.W);
ErrorHelper.Check("Uniform4f");
}
#endregion
public void SetValue(Vector2 value) #region SetValue (Vector4[])
{ /// <summary>
throw new NotImplementedException(); /// Set a Vector4 array value to the effect parameter.
} /// </summary>
/// <param name="value">Value for the parameter</param>
public void SetValue(Vector2[] value) public void SetValue(Vector4[] value)
{ {
throw new NotImplementedException(); GL.UseProgram(parentEffect.programHandle);
} ErrorHelper.Check("UseProgram");
float[] array = new float[value.Length * 4];
public void SetValue(Vector3 value) for (int index = 0; index < value.Length; index++)
{ {
throw new NotImplementedException(); array[(index * 4)] = value[index].X;
} array[(index * 4) + 1] = value[index].Y;
array[(index * 4) + 2] = value[index].Z;
public void SetValue(Vector3[] value) array[(index * 4) + 3] = value[index].W;
{ }
throw new NotImplementedException(); GL.Uniform4(UniformIndex, array.Length, array);
} ErrorHelper.Check("Uniform4fv");
}
public void SetValue(Vector4 value) #endregion
{ }
throw new NotImplementedException();
}
public void SetValue(Vector4[] value)
{
throw new NotImplementedException();
}
}
} }

View File

@ -1,5 +1,7 @@
using System; using System;
using ANX.Framework.NonXNA; using ANX.Framework.NonXNA;
using System.Collections.Generic;
using ANX.Framework.Graphics;
#region License #region License
@ -64,8 +66,20 @@ namespace ANX.Framework.Windows.GL3
get; get;
private set; private set;
} }
/// <summary>
/// The passes of the technique.
/// </summary>
public IEnumerable<EffectPass> Passes
{
get
{
//TODO: implement
yield return null;
}
}
#endregion #endregion
#region Constructor #region Constructor
/// <summary> /// <summary>
/// Create a ne effect technique object. /// Create a ne effect technique object.
@ -74,15 +88,5 @@ namespace ANX.Framework.Windows.GL3
{ {
} }
#endregion #endregion
}
public System.Collections.Generic.IEnumerable<Graphics.EffectPass> Passes
{
get
{
//TODO: implement
yield return null;
}
}
}
} }

View File

@ -90,13 +90,12 @@ namespace ANX.Framework.Windows.GL3
elementSize = setElementSize; elementSize = setElementSize;
usage = setUsage; usage = setUsage;
// TODO: evaluate whats best // TODO: check if dynamic buffer
// StaticDraw: set once, use often bool isDynamicBuffer = false;
// DynamicDraw: set frequently, use repeatadly
// StreamDraw: set every tick, use once
// comment from glatzemann: I think static draw should be right HERE. DynamicDraw should be used for DynamicIndexbuffer. StreamDraw shouldn't be used I think. usageHint = isDynamicBuffer ?
usageHint = BufferUsageHint.DynamicDraw; BufferUsageHint.DynamicDraw :
BufferUsageHint.StaticDraw;
GL.GenBuffers(1, out bufferHandle); GL.GenBuffers(1, out bufferHandle);
ErrorHelper.Check("GenBuffers"); ErrorHelper.Check("GenBuffers");

View File

@ -93,11 +93,12 @@ namespace ANX.Framework.Windows.GL3
usage = setUsage; usage = setUsage;
vertexCount = setVertexCount; vertexCount = setVertexCount;
// TODO: evaluate whats best // TODO: check if dynamic buffer
// StaticDraw: set once, use often bool isDynamicBuffer = false;
// DynamicDraw: set frequently, use repeatadly
// StreamDraw: set every tick, use once usageHint = isDynamicBuffer ?
usageHint = BufferUsageHint.DynamicDraw; BufferUsageHint.DynamicDraw :
BufferUsageHint.StaticDraw;
GL.GenBuffers(1, out bufferHandle); GL.GenBuffers(1, out bufferHandle);
ErrorHelper.Check("GenBuffers"); ErrorHelper.Check("GenBuffers");
@ -114,7 +115,7 @@ namespace ANX.Framework.Windows.GL3
if (setSize != size) if (setSize != size)
{ {
throw new Exception("Failed to set the vertexBuffer data. DataSize=" + throw new Exception("Failed to set the vertexBuffer data. DataSize=" +
size + " SetSize=" + setSize); size + " SetSize=" + setSize);
} }
} }
#endregion #endregion

View File

@ -66,8 +66,6 @@ void main( )
// Fragment Shader // Fragment Shader
// //
precission mediump float;
uniform sampler2D Texture; uniform sampler2D Texture;
varying vec4 diffuseColor; varying vec4 diffuseColor;