217 lines
5.8 KiB
C#
217 lines
5.8 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 int id;
|
|
private IglFunc GL;
|
|
|
|
internal unsafe Uniform(
|
|
uint shaderID, string name, IglFunc gL)
|
|
{
|
|
byte[] namearray = Encoding.ASCII.GetBytes(name);
|
|
GL = gL;
|
|
fixed (byte* ptr = namearray)
|
|
{
|
|
id = GL.GetUniformLocation(shaderID, 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(
|
|
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(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(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
|
|
{
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
unsafe void IglFunc.SetValue(Uniform<float> uniform, float v0)
|
|
{
|
|
api->glUniform1f(uniform.id, v0);
|
|
}
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
unsafe void IglFunc.SetValue(Uniform<int> uniform, int i0)
|
|
{
|
|
api->glUniform1i(uniform.id, i0);
|
|
}
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
unsafe void IglFunc.SetValue(Uniform<float, float> uniform, float v0, float v1)
|
|
{
|
|
api->glUniform2f(uniform.id, v0, v1);
|
|
}
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
unsafe void IglFunc.SetValue(Uniform<float, float, float> uniform, float v0, float v1, float v2)
|
|
{
|
|
api->glUniform3f(uniform.id, 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, v0, v1, v2, v3);
|
|
}
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public unsafe void SetValue(Uniform<float, float, float, float> uniform, Vec4d vec)
|
|
{
|
|
api->glUniform1fv(uniform.id, 4, &vec);
|
|
}
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public unsafe void SetValue(Uniform<Vec4d> uniform, Vec4d vec)
|
|
{
|
|
api->glUniform1fv(uniform.id, 4, &vec);
|
|
}
|
|
}
|
|
|
|
internal partial class GLonUpdate
|
|
{
|
|
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);
|
|
}
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|