daily update on 20240209 by nitload youmu

This commit is contained in:
Nitload
2024-02-09 23:31:33 +08:00
parent 6fe6b3b3cf
commit 8391569482
159 changed files with 948 additions and 2431 deletions
@@ -14,33 +14,37 @@ namespace StgSharp.Graphics
/// </summary>
/// <returns>New instance of <see cref="Shader"/> instance. </returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected ShaderProgram CreateShaderProgram(ShaderType shaderType)
protected ShaderProgram CreateShaderProgram()
{
return new ShaderProgram(GL, 1);
return new ShaderProgram(GL);
}
protected Shader CreateShader(ShaderType type, int count)
{
return new Shader(this.gl, new glHandleSet(count), type);
}
}
public class Shader
{
internal readonly glHandle handle;
internal readonly glHandleSet handle;
public readonly ShaderType type;
private readonly IglFunc GL;
internal Shader(IglFunc gl, glHandle handle)
internal Shader(IglFunc gl, glHandleSet handle, ShaderType usage)
{
this.handle = handle;
GL = gl;
type = usage;
}
/// <summary>
/// Compile the vertex shader to be attached to this shader.
/// </summary>
/// <param name="shaderCode">GLSL code of vertex shader.</param>
public unsafe void Compile(string shaderCode, ShaderType usage, int index)
public unsafe void Compile(ShaderType usage, params string[] code)
{
handle.handle[index] = GL.CompileShader(shaderCode, type).handle;
glHandleSet.Copy(GL.CompileShader(usage, code), handle);
}
//TODO:写链接着色器的文档注释
@@ -48,20 +52,11 @@ namespace StgSharp.Graphics
///
/// </summary>
/// <param name="target"></param>
/// <param name="usage"></param>
public void AttachTo(ShaderProgram target, ShaderType usage)
/// <param name="index"></param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void AttachTo(int index, ShaderProgram target)
{
switch (usage)
{
case ShaderType.Fragment:
break;
case ShaderType.Vertex:
GL.AttachShader(target.handle,)
break;
default:
throw new ArgumentException();
}
GL.AttachShader(target.handle, handle[index]);
}
}
@@ -74,7 +69,7 @@ namespace StgSharp.Graphics
/// <summary>
/// Inti a shader with no program attached.
/// </summary>
internal unsafe ShaderProgram(IglFunc gl, int count)
internal unsafe ShaderProgram(IglFunc gl)
{
GL = gl;
handle = GL.CreateProgram();
@@ -85,7 +80,7 @@ namespace StgSharp.Graphics
/// </summary>
public void Link()
{
if (InternalIO.InternalLinkShaderProgram(handle[0]) == 0)
if (InternalIO.InternalLinkShaderProgram(handle.Value) == 0)
{
IntPtr logPtr = InternalIO.InternalReadLog();
try
@@ -109,22 +104,10 @@ namespace StgSharp.Graphics
/// </summary>
/// <param name="name">Name of the Uniform in shader code</param>
/// <returns></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe Uniform<T> GetUniform<T>(string name) where T : struct
{
byte[] bytes = Encoding.ASCII.GetBytes(name);
int uniform;
fixed (byte* ptr = bytes)
{
uniform = GL.GetUniformLocation(handle[0], ptr);
}
if (uniform != -1)
{
return new Uniform<T>(uniform);
}
else
{
throw new Exception($"Cannot find the uniform {name} in shader {handle[0]}");
}
return new Uniform<T>(this, name, GL);
}
/// <summary>
/// Get a uniform form current shader,
@@ -136,20 +119,7 @@ namespace StgSharp.Graphics
where T : struct
where U : struct
{
byte[] bytes = Encoding.ASCII.GetBytes(name);
int uniform;
fixed (byte* ptr = bytes)
{
uniform = GL.GetUniformLocation(handle[0], ptr);
}
if (uniform != -1)
{
return new Uniform<T, U>(uniform);
}
else
{
throw new Exception($"Cannot find the uniform {name} in shader {handle[0]}");
}
return new Uniform<T, U>(this, name, GL);
}
/// <summary>
/// Get a uniform form current shader,
@@ -157,34 +127,21 @@ namespace StgSharp.Graphics
/// </summary>
/// <param name="name">Name of the Uniform in shader code</param>
/// <returns></returns>
public unsafe Uniform<T, U, V> GetUniform<T, U, V>(int index, string name)
public unsafe Uniform<T, U, V> GetUniform<T, U, V>(string name)
where T : struct
where U : struct
where V : struct
{
byte[] bytes = Encoding.ASCII.GetBytes(name);
int uniform;
fixed (byte* ptr = bytes)
{
uniform = GL.GetUniformLocation(handle[index], ptr);
}
if (uniform != -1)
{
return new Uniform<T, U, V>(uniform);
}
else
{
throw new Exception($"Cannot find the uniform {name} in shader {handle[index]}");
}
return new Uniform<T, U, V>(this, name, GL);
}
/// <summary>
/// Let the current context use this shader.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe void Use(int index)
public unsafe void Use()
{
GL.UseProgram(handle[index]);
GL.UseProgram(handle);
}
}
@@ -11,21 +11,17 @@ namespace StgSharp.Graphics
public class Uniform<T> where T : struct
{
internal int id;
internal glSHandle id;
private IglFunc GL;
internal unsafe Uniform(
uint shaderID, string name, IglFunc gL)
ShaderProgram program, string name, IglFunc gl)
{
byte[] namearray = Encoding.ASCII.GetBytes(name);
GL = gL;
fixed (byte* ptr = namearray)
{
id = GL.GetUniformLocation(shaderID, ptr);
}
GL = gl;
id = GL.GetUniformLocation(program.handle, name);
}
internal unsafe Uniform(int id)
internal unsafe Uniform(glSHandle id)
{
this.id = id;
}
@@ -37,21 +33,17 @@ namespace StgSharp.Graphics
where T : struct
where U : struct
{
internal int id;
internal glSHandle id;
private IglFunc GL;
internal unsafe Uniform(
Shader program, string name, IglFunc glFunc)
ShaderProgram program, string name, IglFunc gl)
{
byte[] namearray = Encoding.ASCII.GetBytes(name);
GL = glFunc;
fixed (byte* ptr = namearray)
{
id = GL.GetUniformLocation(program.programID, ptr);
}
GL = gl;
id = GL.GetUniformLocation(program.handle, name);
}
internal unsafe Uniform(int id)
internal unsafe Uniform(glSHandle id)
{
this.id = id;
}
@@ -62,20 +54,16 @@ namespace StgSharp.Graphics
where U : struct
where V : struct
{
internal int id;
internal glSHandle id;
private IglFunc GL;
public unsafe Uniform(Shader program, string name, IglFunc glFunc)
public unsafe Uniform(ShaderProgram program, string name, IglFunc gl)
{
byte[] namearray = Encoding.ASCII.GetBytes(name);
GL = glFunc;
fixed (byte* ptr = namearray)
{
id = GL.GetUniformLocation(program.programID, ptr);
}
GL = gl;
id = GL.GetUniformLocation(program.handle, name);
}
internal unsafe Uniform(int id)
internal unsafe Uniform(glSHandle id)
{
this.id = id;
}
@@ -87,20 +75,16 @@ namespace StgSharp.Graphics
where V : struct
where W : struct
{
internal int id;
internal glSHandle id;
private IglFunc GL;
internal unsafe Uniform(Shader program, string name, IglFunc glFunc)
internal unsafe Uniform(ShaderProgram program, string name, IglFunc gl)
{
byte[] namearray = Encoding.ASCII.GetBytes(name);
fixed (byte* ptr = namearray)
{
id = GL.GetUniformLocation(program.programID, ptr);
}
GL = glFunc;
GL = gl;
id = GL.GetUniformLocation(program.handle, name);
}
internal unsafe Uniform(int id)
internal unsafe Uniform(glSHandle id)
{
this.id = id;
}
@@ -113,48 +97,56 @@ namespace StgSharp.Graphics
[MethodImpl(MethodImplOptions.AggressiveInlining)]
unsafe void IglFunc.SetValue(Uniform<float> uniform, float v0)
{
api->glUniform1f(uniform.id, v0);
api->glUniform1f(uniform.id.DirectValue, v0);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
unsafe void IglFunc.SetValue(Uniform<int> uniform, int i0)
{
api->glUniform1i(uniform.id, 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, v0, 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, v0, v1, 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, v0, v1, v2, 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, 4, &vec);
api->glUniform1fv(uniform.id.DirectValue, 4, &vec);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe void SetValue(Uniform<Vec4d> uniform, Vec4d vec)
{
api->glUniform1fv(uniform.id, 4, &vec);
api->glUniform1fv(uniform.id.DirectValue, 4, &vec);
}
}
internal partial class GLonUpdate
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(