209 lines
5.6 KiB
C#
209 lines
5.6 KiB
C#
using StgSharp.Math;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Runtime.CompilerServices;
|
|
using System.Runtime.InteropServices;
|
|
using System.Text;
|
|
|
|
namespace StgSharp.Graphics
|
|
{
|
|
|
|
public class Uniform<T> where T : struct
|
|
{
|
|
internal glSHandle id;
|
|
private IglFunc GL;
|
|
|
|
internal unsafe Uniform(
|
|
ShaderProgram program, string name, IglFunc gl)
|
|
{
|
|
GL = gl;
|
|
id = GL.GetUniformLocation(program.handle, name);
|
|
}
|
|
|
|
internal unsafe Uniform(glSHandle id)
|
|
{
|
|
this.id = id;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
public class Uniform<T, U>
|
|
where T : struct
|
|
where U : struct
|
|
{
|
|
internal glSHandle id;
|
|
private IglFunc GL;
|
|
|
|
internal unsafe Uniform(
|
|
ShaderProgram program, string name, IglFunc gl)
|
|
{
|
|
GL = gl;
|
|
id = GL.GetUniformLocation(program.handle, name);
|
|
}
|
|
|
|
internal unsafe Uniform(glSHandle id)
|
|
{
|
|
this.id = id;
|
|
}
|
|
}
|
|
|
|
public class Uniform<T, U, V>
|
|
where T : struct
|
|
where U : struct
|
|
where V : struct
|
|
{
|
|
internal glSHandle id;
|
|
private IglFunc GL;
|
|
|
|
public unsafe Uniform(ShaderProgram program, string name, IglFunc gl)
|
|
{
|
|
GL = gl;
|
|
id = GL.GetUniformLocation(program.handle, name);
|
|
}
|
|
|
|
internal unsafe Uniform(glSHandle id)
|
|
{
|
|
this.id = id;
|
|
}
|
|
}
|
|
|
|
public class Uniform<T, U, V, W>
|
|
where T : struct
|
|
where U : struct
|
|
where V : struct
|
|
where W : struct
|
|
{
|
|
internal glSHandle id;
|
|
private IglFunc GL;
|
|
|
|
internal unsafe Uniform(ShaderProgram program, string name, IglFunc gl)
|
|
{
|
|
GL = gl;
|
|
id = GL.GetUniformLocation(program.handle, name);
|
|
}
|
|
|
|
internal unsafe Uniform(glSHandle id)
|
|
{
|
|
this.id = id;
|
|
}
|
|
|
|
}
|
|
|
|
internal partial class GLonRender : IglFunc
|
|
{
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
unsafe void IglFunc.SetValue(Uniform<float> uniform, float v0)
|
|
{
|
|
api->glUniform1f(uniform.id.DirectValue, v0);
|
|
}
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
unsafe void IglFunc.SetValue(Uniform<int> uniform, int i0)
|
|
{
|
|
api->glUniform1i(uniform.id.DirectValue, i0);
|
|
}
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
unsafe void IglFunc.SetValue(Uniform<float, float> uniform, float v0, float v1)
|
|
{
|
|
api->glUniform2f(uniform.id.DirectValue, v0, v1);
|
|
}
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
unsafe void IglFunc.SetValue(Uniform<float, float, float> uniform, float v0, float v1, float v2)
|
|
{
|
|
api->glUniform3f(uniform.id.DirectValue, v0, v1, v2);
|
|
}
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
unsafe void IglFunc.SetValue(Uniform<float, float, float, float> uniform, float v0, float v1, float v2, float v3)
|
|
{
|
|
api->glUniform4f(uniform.id.DirectValue, v0, v1, v2, v3);
|
|
}
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public unsafe void SetValue(Uniform<float, float, float, float> uniform, Vec4d vec)
|
|
{
|
|
api->glUniform1fv(uniform.id.DirectValue, 4, &vec);
|
|
}
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public unsafe void SetValue(Uniform<Vec4d> uniform, Vec4d vec)
|
|
{
|
|
api->glUniform1fv(uniform.id.DirectValue, 4, &vec);
|
|
}
|
|
}
|
|
|
|
internal unsafe partial class GLonUpdate
|
|
{
|
|
private IntPtr UniformVal3fPtr = (IntPtr)(delegate*<void>)&UniformVal3f;
|
|
//TODO xontinue here
|
|
private static void UniformVal3f()
|
|
{
|
|
|
|
paramQueue.
|
|
}
|
|
|
|
unsafe void IglFunc.SetValue(Uniform<float, float, float> uniform, float v0, float v1, float v2)
|
|
{
|
|
glActionQueue.Enqueue(
|
|
() => { api->glUniform3f(uniform.id, v0, v1, v2); }
|
|
);
|
|
}
|
|
|
|
unsafe void IglFunc.SetValue(Uniform<float, float> uniform, float v0, float v1)
|
|
{
|
|
glActionQueue.Enqueue(
|
|
() => { api->glUniform2f(uniform.id, v0, v1); }
|
|
);
|
|
}
|
|
|
|
unsafe void IglFunc.SetValue(Uniform<float, float, float, float> uniform, float v0, float v1, float v2, float v3)
|
|
{
|
|
glActionQueue.Enqueue(
|
|
() => { api->glUniform4f(uniform.id, v0, v1, v2, v3); }
|
|
);
|
|
}
|
|
|
|
unsafe void IglFunc.SetValue(Uniform<float, float, float, float> uniform, Vec4d vec)
|
|
{
|
|
glActionQueue.Enqueue(
|
|
() =>
|
|
{
|
|
Vec4d cache = vec;
|
|
api->glUniform1fv(uniform.id, 4, &cache);
|
|
}
|
|
);
|
|
}
|
|
|
|
unsafe void IglFunc.SetValue(Uniform<float> uniform, float v0)
|
|
{
|
|
glActionQueue.Enqueue(
|
|
() => { api->glUniform1f(uniform.id, v0); }
|
|
);
|
|
}
|
|
|
|
unsafe void IglFunc.SetValue(Uniform<int> uniform, int i0)
|
|
{
|
|
glActionQueue.Enqueue(
|
|
() => { api->glUniform1d(uniform.id, i0); }
|
|
);
|
|
}
|
|
|
|
unsafe void IglFunc.SetValue(Uniform<Vec4d> uniform, Vec4d vec)
|
|
{
|
|
glActionQueue.Enqueue(
|
|
() =>
|
|
{
|
|
Vec4d cache = vec;
|
|
api->glUniform1fv(uniform.id, 4, &cache);
|
|
}
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|