daily update on 20240209 by nitload youmu
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user