daily update on 20240206 by nitload youmu
This commit is contained in:
@@ -14,34 +14,23 @@ namespace StgSharp.Graphics
|
||||
/// </summary>
|
||||
/// <returns>New instance of <see cref="Shader"/> instance. </returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
protected Shader CreateShader()
|
||||
protected ShaderProgram CreateShaderProgram(ShaderType shaderType)
|
||||
{
|
||||
return new Shader(GL);
|
||||
return new ShaderProgram(GL, 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class Shader
|
||||
{
|
||||
internal readonly glHandle Handle;
|
||||
internal readonly glHandle handle;
|
||||
public readonly ShaderType type;
|
||||
private IglFunc GL;
|
||||
private readonly IglFunc GL;
|
||||
|
||||
/// <summary>
|
||||
/// Inti a shader with no program attached.
|
||||
/// </summary>
|
||||
internal unsafe Shader(IglFunc gl, ShaderType t, int count)
|
||||
{
|
||||
GL = gl;
|
||||
type = t;
|
||||
if (type == ShaderType.Program)
|
||||
{
|
||||
Handle = GL.CreateProgram();
|
||||
}
|
||||
}
|
||||
|
||||
internal void ChangeEnvironment(IglFunc gl)
|
||||
|
||||
internal Shader(IglFunc gl, glHandle handle)
|
||||
{
|
||||
this.handle = handle;
|
||||
GL = gl;
|
||||
}
|
||||
|
||||
@@ -49,20 +38,46 @@ namespace StgSharp.Graphics
|
||||
/// Compile the vertex shader to be attached to this shader.
|
||||
/// </summary>
|
||||
/// <param name="shaderCode">GLSL code of vertex shader.</param>
|
||||
public unsafe void CompileShader(string shaderCode)
|
||||
public unsafe void Compile(string shaderCode, ShaderType usage, int index)
|
||||
{
|
||||
vertexHandle = GL.CompileShader(shaderCode, type);
|
||||
GL.AttachShader(programHandle, vertexHandle);
|
||||
handle.handle[index] = GL.CompileShader(shaderCode, type).handle;
|
||||
}
|
||||
|
||||
//TODO:写链接着色器的文档注释
|
||||
/// <summary>
|
||||
/// Compile the fragment shader to be attached to this shader.
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="shaderCode">GLSL code of fragment shader.</param>
|
||||
public unsafe void CompileFragmentShader(string shaderCode)
|
||||
/// <param name="target"></param>
|
||||
/// <param name="usage"></param>
|
||||
public void AttachTo(ShaderProgram target, ShaderType usage)
|
||||
{
|
||||
fragmentHandle = GL.CompileShader(shaderCode, ShaderType.FRAGMENT);
|
||||
GL.AttachShader(programHandle, fragmentHandle);
|
||||
switch (usage)
|
||||
{
|
||||
case ShaderType.Fragment:
|
||||
|
||||
break;
|
||||
case ShaderType.Vertex:
|
||||
GL.AttachShader(target.handle,)
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentException();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class ShaderProgram
|
||||
{
|
||||
internal readonly glHandle handle;
|
||||
private readonly IglFunc GL;
|
||||
|
||||
/// <summary>
|
||||
/// Inti a shader with no program attached.
|
||||
/// </summary>
|
||||
internal unsafe ShaderProgram(IglFunc gl, int count)
|
||||
{
|
||||
GL = gl;
|
||||
handle = GL.CreateProgram();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -70,7 +85,7 @@ namespace StgSharp.Graphics
|
||||
/// </summary>
|
||||
public void Link()
|
||||
{
|
||||
if (InternalIO.InternalLinkShaderProgram(programHandle) == 0)
|
||||
if (InternalIO.InternalLinkShaderProgram(handle[0]) == 0)
|
||||
{
|
||||
IntPtr logPtr = InternalIO.InternalReadLog();
|
||||
try
|
||||
@@ -100,7 +115,7 @@ namespace StgSharp.Graphics
|
||||
int uniform;
|
||||
fixed (byte* ptr = bytes)
|
||||
{
|
||||
uniform = GL.GetUniformLocation(programHandle, ptr);
|
||||
uniform = GL.GetUniformLocation(handle[0], ptr);
|
||||
}
|
||||
if (uniform != -1)
|
||||
{
|
||||
@@ -108,7 +123,7 @@ namespace StgSharp.Graphics
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception($"Cannot find the uniform {name} in shader {programHandle}");
|
||||
throw new Exception($"Cannot find the uniform {name} in shader {handle[0]}");
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
@@ -125,7 +140,7 @@ namespace StgSharp.Graphics
|
||||
int uniform;
|
||||
fixed (byte* ptr = bytes)
|
||||
{
|
||||
uniform = GL.GetUniformLocation(programHandle, ptr);
|
||||
uniform = GL.GetUniformLocation(handle[0], ptr);
|
||||
}
|
||||
if (uniform != -1)
|
||||
{
|
||||
@@ -133,7 +148,7 @@ namespace StgSharp.Graphics
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception($"Cannot find the uniform {name} in shader {programHandle}");
|
||||
throw new Exception($"Cannot find the uniform {name} in shader {handle[0]}");
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
@@ -142,7 +157,7 @@ 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>(string name)
|
||||
public unsafe Uniform<T, U, V> GetUniform<T, U, V>(int index, string name)
|
||||
where T : struct
|
||||
where U : struct
|
||||
where V : struct
|
||||
@@ -151,7 +166,7 @@ namespace StgSharp.Graphics
|
||||
int uniform;
|
||||
fixed (byte* ptr = bytes)
|
||||
{
|
||||
uniform = GL.GetUniformLocation(programHandle, ptr);
|
||||
uniform = GL.GetUniformLocation(handle[index], ptr);
|
||||
}
|
||||
if (uniform != -1)
|
||||
{
|
||||
@@ -159,7 +174,7 @@ namespace StgSharp.Graphics
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception($"Cannot find the uniform {name} in shader {programHandle}");
|
||||
throw new Exception($"Cannot find the uniform {name} in shader {handle[index]}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -167,9 +182,9 @@ namespace StgSharp.Graphics
|
||||
/// Let the current context use this shader.
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe void Use()
|
||||
public unsafe void Use(int index)
|
||||
{
|
||||
GL.UseProgram(programHandle);
|
||||
GL.UseProgram(handle[index]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user