247 lines
7.7 KiB
C#
247 lines
7.7 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 UniformVal1fPtr = (IntPtr)(delegate*<void>)&UniformVal1f;
|
|
private IntPtr UniformVal1fvPtr = (IntPtr)(delegate*<void>)&UniformVal1fv;
|
|
private IntPtr UniformVal1iPtr = (IntPtr)(delegate*<void>)&UniformVal1i;
|
|
private IntPtr UniformVal2fPtr = (IntPtr)(delegate*<void>)&UniformVal2f;
|
|
private IntPtr UniformVal3fPtr = (IntPtr)(delegate*<void>)&UniformVal3f;
|
|
private IntPtr UniformVal4fPtr = (IntPtr)(delegate*<void>)&UniformVal4f;
|
|
|
|
unsafe void IglFunc.SetValue(Uniform<float, float, float> uniform, float f0, float f1, float f2)
|
|
{
|
|
paramQueue.Enqueue((IntPtr)uniform.id.valuePtr);
|
|
paramQueue.Enqueue(f0, f1, f2);
|
|
glActionQueue.Enqueue(UniformVal3fPtr);
|
|
}
|
|
|
|
unsafe void IglFunc.SetValue(Uniform<float, float> uniform, float f0, float f1)
|
|
{
|
|
M128 m = default;
|
|
m.Write<ulong>(0, (ulong)uniform.id.valuePtr);
|
|
m.Write<float>(2, f0);
|
|
m.Write<float>(3, f1);
|
|
paramQueue.Enqueue(m);
|
|
glActionQueue.Enqueue(UniformVal2fPtr);
|
|
}
|
|
|
|
unsafe void IglFunc.SetValue(Uniform<float, float, float, float> uniform, float f0, float f1, float f2, float f3)
|
|
{
|
|
paramQueue.Enqueue((IntPtr)uniform.id.valuePtr);
|
|
paramQueue.Enqueue(f0, f1, f2, f3);
|
|
glActionQueue.Enqueue(UniformVal4fPtr);
|
|
}
|
|
|
|
unsafe void IglFunc.SetValue(Uniform<float, float, float, float> uniform, Vec4d vec)
|
|
{
|
|
Vec4d m = vec;
|
|
paramQueue.Enqueue((IntPtr)uniform.id.valuePtr, (IntPtr)(Vec4d*)&m);
|
|
glActionQueue.Enqueue(UniformVal1fvPtr);
|
|
}
|
|
|
|
unsafe void IglFunc.SetValue(Uniform<float> uniform, float f0)
|
|
{
|
|
M128 m = default;
|
|
m.Write<ulong>(0, (ulong)uniform.id.valuePtr);
|
|
m.Write<float>(2, f0);
|
|
paramQueue.Enqueue(m);
|
|
glActionQueue.Enqueue(UniformVal1fPtr);
|
|
}
|
|
|
|
unsafe void IglFunc.SetValue(Uniform<int> uniform, int i0)
|
|
{
|
|
M128 m = default;
|
|
m.Write<ulong>(0, (ulong)uniform.id.valuePtr);
|
|
m.Write<int>(2, i0);
|
|
paramQueue.Enqueue(m);
|
|
glActionQueue.Enqueue(UniformVal1fPtr);
|
|
}
|
|
|
|
unsafe void IglFunc.SetValue(Uniform<Vec4d> uniform, Vec4d vec)
|
|
{
|
|
Vec4d m = vec;
|
|
paramQueue.Enqueue((IntPtr)uniform.id.valuePtr, (IntPtr)(Vec4d*)&m);
|
|
glActionQueue.Enqueue(UniformVal1fvPtr);
|
|
}
|
|
|
|
private static void UniformVal1f()
|
|
{
|
|
M128 m = default;
|
|
paramQueue.TryDequeue(out m);
|
|
paramQueue.context->glUniform1f(*(int*)m.Read<ulong>(0), m.Read<uint>(2));
|
|
}
|
|
|
|
private static unsafe void UniformVal1fv()
|
|
{
|
|
M128 m = default;
|
|
paramQueue.TryDequeue(out m);
|
|
paramQueue.context->glUniform1fv(*(int*)m.Read<ulong>(0), 4, (Vec4d*)&m.vec);
|
|
}
|
|
|
|
private static void UniformVal1i()
|
|
{
|
|
M128 m = default;
|
|
paramQueue.TryDequeue(out m);
|
|
paramQueue.context->glUniform1i(*(int*)m.Read<ulong>(0), m.Read<int>(2));
|
|
}
|
|
|
|
private static void UniformVal2f()
|
|
{
|
|
M128 m = default;
|
|
paramQueue.TryDequeue(out m);
|
|
paramQueue.context->glUniform2f(*(int*)m.Read<ulong>(0), m.Read<float>(2), m.Read<float>(3));
|
|
}
|
|
|
|
private static void UniformVal3f()
|
|
{
|
|
IntPtr handle = IntPtr.Zero;
|
|
M128 m = default;
|
|
paramQueue.TryDequeue(out handle);
|
|
paramQueue.TryDequeue(out m);
|
|
paramQueue.context->glUniform3f(*(int*)handle, m.Read<float>(0), m.Read<float>(1), m.Read<float>(2));
|
|
}
|
|
|
|
private static void UniformVal4f()
|
|
{
|
|
IntPtr handle = IntPtr.Zero;
|
|
M128 m = default;
|
|
paramQueue.TryDequeue(out handle);
|
|
paramQueue.TryDequeue(out m);
|
|
paramQueue.context->glUniform4f(*(int*)handle, m.Read<float>(0), m.Read<float>(1), m.Read<float>(2), m.Read<float>(3));
|
|
}
|
|
}
|
|
} |