Files
stgsharp/源代码/StgSharp/Graphics/GL/ShaderEdit/Uniform.cs
T

234 lines
7.1 KiB
C#

using StgSharp.Math;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
namespace StgSharp.Graphics
{
public class Uniform<T> where T : struct
{
internal int id;
private IglFunc GL;
internal unsafe Uniform(
Form.Shader program, string name, IglFunc gL)
{
byte[] namearray = Encoding.ASCII.GetBytes(name);
GL = gL;
fixed (byte* ptr = namearray)
{
id = GL.GetUniformLocation(program.programID, ptr);
}
}
internal unsafe Uniform(int id)
{
this.id = id;
}
}
public class Uniform<T, U>
where T : struct
where U : struct
{
internal int id;
private IglFunc GL;
internal unsafe Uniform(
Form.Shader program, string name, IglFunc glFunc)
{
byte[] namearray = Encoding.ASCII.GetBytes(name);
GL = glFunc;
fixed (byte* ptr = namearray)
{
id = GL.GetUniformLocation(program.programID, ptr);
}
}
internal unsafe Uniform(int id)
{
this.id = id;
}
}
public class Uniform<T, U, V>
where T : struct
where U : struct
where V : struct
{
internal int id;
private IglFunc GL;
public unsafe Uniform(Form.Shader program, string name, IglFunc glFunc)
{
byte[] namearray = Encoding.ASCII.GetBytes(name);
GL = glFunc;
fixed (byte* ptr = namearray)
{
id = GL.GetUniformLocation(program.programID, ptr);
}
}
internal unsafe Uniform(int id)
{
this.id = id;
}
}
public class Uniform<T, U, V, W>
where T : struct
where U : struct
where V : struct
where W : struct
{
internal int id;
private IglFunc GL;
internal unsafe Uniform(Form.Shader program, string name, IglFunc glFunc)
{
byte[] namearray = Encoding.ASCII.GetBytes(name);
fixed (byte* ptr = namearray)
{
id = GL.GetUniformLocation(program.programID, ptr);
}
GL = glFunc;
}
internal unsafe Uniform(int id)
{
this.id = id;
}
}
internal partial class GLonRender : IglFunc
{
/// <summary>
/// Set data value to a float <see cref="Uniform{T}"/>,
/// all types of parameters are float.
/// </summary>
/// <param name="uniform">The <see cref="Uniform{T}"/> target</param>
/// <param name="v0">The value to be set</param>
void IglFunc.SetValue(Uniform<float> uniform, float v0)
{
api.Uniform1f(uniform.id, v0);
}
/// <summary>
/// Set data value to a int <see cref="Uniform{T}"/>,
/// all types of parameters are int.
/// </summary>
/// <param name="uniform">The <see cref="Uniform{T}"/> target</param>
/// <param name="i0">The value to be set</param>
void IglFunc.SetValue(Uniform<int> uniform, int i0)
{
api.Uniform1i(uniform.id, i0);
}
/// <summary>
/// Set data value to a float <see cref="Uniform{T,U}"/>,
/// all types of parameters are float.
/// </summary>
/// <param name="uniform">The <see cref="Uniform{T,U}"/> target</param>
/// <param name="v0">The first value to be set</param>
/// <param name="v1">The second value to be set</param>
void IglFunc.SetValue(Uniform<float, float> uniform, float v0, float v1)
{
api.Uniform2f(uniform.id, v0, v1);
}
/// <summary>
/// Set data value to a float <see cref="Uniform{T,U,V}"/>,
/// all types of parameters are float.
/// </summary>
/// <param name="uniform">The <see cref="Uniform{T,U,V}"/> target</param>
/// <param name="v0">The first value to be set</param>
/// <param name="v1">The second value to be set</param>
/// <param name="v2">The third value to be set</param>
void IglFunc.SetValue(Uniform<float, float, float> uniform, float v0, float v1, float v2)
{
api.Uniform3f(uniform.id, v0, v1, v2);
}
/// <summary>
/// Set data value to a float <see cref="Uniform{T,U,V,W}"/>,
/// all types of parameters are float.
/// </summary>
/// <param name="uniform">The <see cref="Uniform{T,U,V,W}"/> target</param>
/// <param name="v0">The first value to be set</param>
/// <param name="v1">The second value to be set</param>
/// <param name="v2">The third value to be set</param>
/// <param name="v3">The forth value to be set</param>
void IglFunc.SetValue(Uniform<float, float, float, float> uniform, float v0, float v1, float v2, float v3)
{
api.Uniform4f(uniform.id, v0, v1, v2, v3);
}
/// <summary>
/// Set data value to a float <see cref="Uniform{T,U,V,W}"/>,
/// all types of parameters are float.
/// </summary>
/// <param name="uniform">The <see cref="Uniform{T,U,V,W}"/> target</param>
/// <param name="vec">A <see cref="Vec4d"/> packing four parameters of the uniform </param>
public unsafe void SetValue(Uniform<float, float, float, float> uniform, Vec4d vec)
{
api.Uniform1fv(uniform.id, 4, &vec.fvec);
}
/// <summary>
/// Set data value to a float <see cref="Uniform{T}"/>,
/// all types of parameters are <see cref="Vec4d"/>.
/// </summary>
/// <param name="uniform">The <see cref="Uniform{T}"/> target</param>
/// <param name="vec">A <see cref="Vec4d"/> value of the uniform </param>
public unsafe void SetValue(Uniform<Vec4d> uniform, Vec4d vec)
{
api.Uniform1fv(uniform.id, 4, &vec.fvec);
}
}
internal partial class GLonUpdate
{
void IglFunc.SetValue(Uniform<float, float, float> uniform, float v0, float v1, float v2)
{
throw new NotImplementedException();
}
void IglFunc.SetValue(Uniform<float, float> uniform, float v0, float v1)
{
throw new NotImplementedException();
}
void IglFunc.SetValue(Uniform<float, float, float, float> uniform, float v0, float v1, float v2, float v3)
{
throw new NotImplementedException();
}
void IglFunc.SetValue(Uniform<float, float, float, float> uniform, Vec4d vec)
{
throw new NotImplementedException();
}
void IglFunc.SetValue(Uniform<float> uniform, float v0)
{
throw new NotImplementedException();
}
void IglFunc.SetValue(Uniform<int> uniform, int i0)
{
throw new NotImplementedException();
}
void IglFunc.SetValue(Uniform<Vec4d> uniform, Vec4d vec)
{
throw new NotImplementedException();
}
}
}