daily update on 20240528 by nitload youmu

This commit is contained in:
Nitload
2024-05-28 17:45:54 +08:00
parent de399e22c2
commit 70890e3e33
88 changed files with 10678 additions and 5761 deletions
@@ -39,15 +39,15 @@ using System.Runtime.InteropServices;
using System.Text;
using System.Xml.Linq;
namespace StgSharp.Graphics
namespace StgSharp.Graphics.GL
{
public partial class glRenderStream
public abstract partial class glRenderStream : RenderStream
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected sealed override Shader CreateShaderSegment(ShaderType type, int count)
{
return new Shader( GL.CreateShaderSet(count, type), type);
return new Shader( glFunc.CreateShaderSet(count, type), type);
}
/// <summary>
/// Create an instance of <see cref="Shader"/> program
@@ -72,7 +72,7 @@ namespace StgSharp.Graphics
internal unsafe Shader(glHandleSet handle, ShaderType usage)
{
this.handle = handle;
context = GL.CurrentContextHandle;
context = glFunc.CurrentContextHandle;
type = usage;
}
@@ -84,31 +84,43 @@ namespace StgSharp.Graphics
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void AttachTo(int index, ShaderProgram target)
{
GL.AttachShader(target.handle, handle[index]);
glFunc.AttachShader(target.handle, handle[index]);
}
public static string FromCodeFile(string fileRoute)
public static byte[] FromCodeFile(string fileRoute)
{
string str = File.ReadAllText(fileRoute);
if (str == "")
if (string.IsNullOrEmpty(str))
{
throw new Exception($"Cannot load and GLSL code from {fileRoute}");
throw new InvalidOperationException($"Cannot load and GLSL code from {fileRoute}");
}
return str;
return Encoding.UTF8.GetBytes(str);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe void Compile(int index, string code)
public unsafe void Compile(int index, byte[] codeStream)
{
if (code == null)
if (codeStream == null)
{
throw new ArgumentNullException("Must provide enough code");
throw new ArgumentNullException(nameof(codeStream));
}
GL.LoadShaderSource(handle[index], $"{code}\0");
GL.CompileShader(handle[index]);
glFunc.LoadShaderSource(handle[index], codeStream);
glFunc.CompileShader(handle[index]);
CheckStatus(index,ShaderStatus.CompileStatus);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe void Compile(int index, string codeStream)
{
if (codeStream == null)
{
throw new ArgumentNullException(nameof(codeStream));
}
glFunc.LoadShaderSource(handle[index],Encoding.ASCII.GetBytes( codeStream));
glFunc.CompileShader(handle[index]);
CheckStatus(index, ShaderStatus.CompileStatus);
}
public override string ToString()
{
return $"This is a {type} shader, its shader handles are {handle.ToString()}.";
@@ -122,7 +134,7 @@ namespace StgSharp.Graphics
public void CheckStatus(int index, ShaderStatus status)
{
string log = GL.GetShaderStatus(this,index, (int)status);
string log = glFunc.GetShaderStatus(this,index, (int)status);
if (log != "")
{
throw new Exception($"Shader Error\n{status}\n" + log);
@@ -147,7 +159,6 @@ namespace StgSharp.Graphics
public class ShaderProgram
{
private readonly IntPtr binding;
internal readonly glHandle handle;
@@ -157,7 +168,7 @@ namespace StgSharp.Graphics
internal unsafe ShaderProgram(glRenderStream binding)
{
this.binding = binding.ContextHandle;
handle = GL.CreateProgram();
handle = glFunc.CreateProgram();
}
/// <summary>
@@ -242,7 +253,7 @@ namespace StgSharp.Graphics
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe void Use()
{
GL.UseProgram(handle);
glFunc.UseProgram(handle);
}
~ShaderProgram()