daily update on 20240203 by nitloadd youmu. New glhandle setup.

This commit is contained in:
Nitload
2024-02-03 23:20:50 +08:00
parent 8148c10acd
commit 5d778e0f2f
258 changed files with 10025 additions and 1220 deletions
@@ -20,23 +20,24 @@ namespace StgSharp.Graphics
}
}
public class Shader
{
/// <summary>
/// A <see cref="uint"/> value represent this shader.
/// </summary>
public readonly uint programID;
internal uint vertexShaderID;
internal uint fragmentShaderID;
internal readonly glHandle Handle;
public readonly ShaderType type;
private IglFunc GL;
/// <summary>
/// Inti a shader with no program attached.
/// </summary>
internal unsafe Shader(IglFunc gl)
internal unsafe Shader(IglFunc gl, ShaderType t, int count)
{
GL = gl;
programID = GL.CreateProgram();
type = t;
if (type == ShaderType.Program)
{
Handle = GL.CreateProgram();
}
}
internal void ChangeEnvironment(IglFunc gl)
@@ -48,10 +49,10 @@ 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 CompileVertexShader(string shaderCode)
public unsafe void CompileShader(string shaderCode)
{
vertexShaderID = GL.CompileShader(shaderCode, ShaderType.VERTEX);
GL.AttachShader(programID, vertexShaderID);
vertexHandle = GL.CompileShader(shaderCode, type);
GL.AttachShader(programHandle, vertexHandle);
}
/// <summary>
@@ -60,8 +61,8 @@ namespace StgSharp.Graphics
/// <param name="shaderCode">GLSL code of fragment shader.</param>
public unsafe void CompileFragmentShader(string shaderCode)
{
fragmentShaderID = GL.CompileShader(shaderCode, ShaderType.FRAGMENT);
GL.AttachShader(programID, fragmentShaderID);
fragmentHandle = GL.CompileShader(shaderCode, ShaderType.FRAGMENT);
GL.AttachShader(programHandle, fragmentHandle);
}
/// <summary>
@@ -69,7 +70,7 @@ namespace StgSharp.Graphics
/// </summary>
public void Link()
{
if (InternalIO.InternalLinkShaderProgram(programID) == 0)
if (InternalIO.InternalLinkShaderProgram(programHandle) == 0)
{
IntPtr logPtr = InternalIO.InternalReadLog();
try
@@ -99,7 +100,7 @@ namespace StgSharp.Graphics
int uniform;
fixed (byte* ptr = bytes)
{
uniform = GL.GetUniformLocation(programID, ptr);
uniform = GL.GetUniformLocation(programHandle, ptr);
}
if (uniform != -1)
{
@@ -107,7 +108,7 @@ namespace StgSharp.Graphics
}
else
{
throw new Exception($"Cannot find the uniform {name} in shader {programID}");
throw new Exception($"Cannot find the uniform {name} in shader {programHandle}");
}
}
/// <summary>
@@ -124,7 +125,7 @@ namespace StgSharp.Graphics
int uniform;
fixed (byte* ptr = bytes)
{
uniform = GL.GetUniformLocation(programID, ptr);
uniform = GL.GetUniformLocation(programHandle, ptr);
}
if (uniform != -1)
{
@@ -132,7 +133,7 @@ namespace StgSharp.Graphics
}
else
{
throw new Exception($"Cannot find the uniform {name} in shader {programID}");
throw new Exception($"Cannot find the uniform {name} in shader {programHandle}");
}
}
/// <summary>
@@ -150,7 +151,7 @@ namespace StgSharp.Graphics
int uniform;
fixed (byte* ptr = bytes)
{
uniform = GL.GetUniformLocation(programID, ptr);
uniform = GL.GetUniformLocation(programHandle, ptr);
}
if (uniform != -1)
{
@@ -158,7 +159,7 @@ namespace StgSharp.Graphics
}
else
{
throw new Exception($"Cannot find the uniform {name} in shader {programID}");
throw new Exception($"Cannot find the uniform {name} in shader {programHandle}");
}
}
@@ -168,7 +169,7 @@ namespace StgSharp.Graphics
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe void Use()
{
GL.UseProgram(programID);
GL.UseProgram(programHandle);
}
}