daily update on 20240305 by nitload youmu

This commit is contained in:
YoumuLiu
2024-03-05 10:17:02 +08:00
parent 1f2fca4c8f
commit 6a0cccae79
156 changed files with 23040 additions and 1385 deletions
@@ -1,4 +1,5 @@
using StgSharp;
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
@@ -19,9 +20,10 @@ namespace StgSharp.Graphics
return new ShaderProgram(GL);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected Shader CreateShader(ShaderType type, int count)
{
return new Shader(this.gl, new glHandleSet(count), type);
return new Shader(this.gl, gl.CreateShaderSet(count, type), type);
}
}
@@ -38,18 +40,20 @@ namespace StgSharp.Graphics
type = usage;
}
/// <summary>
/// Compile the vertex shader to be attached to this shader.
/// </summary>
/// <param name="code">GLSL code of vertex shader.</param>
public unsafe void Compile(params string[] code)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe void Compile(int index, string code)
{
glHandleSet.Copy(GL.CompileShader(type, code), handle);
if (code == null)
{
throw new ArgumentNullException("Must provide enough code");
}
GL.LoadShaderSource(handle[index], code + '\0');
GL.CompileShader(handle[index]);
}
//TODO:写链接着色器的文档注释
/// <summary>
///
///
/// </summary>
/// <param name="target"></param>
/// <param name="index"></param>
@@ -103,8 +107,8 @@ namespace StgSharp.Graphics
}
/// <summary>
/// Get a uniform form current shader,
/// the value type of the uniform should be provided.
/// Get a uniform form current shader,
/// the value type of the uniform should be provided.
/// </summary>
/// <param name="name">Name of the Uniform in shader code</param>
/// <returns></returns>
@@ -113,9 +117,10 @@ namespace StgSharp.Graphics
{
return new Uniform<T>(this, name, GL);
}
/// <summary>
/// Get a uniform form current shader,
/// the value type of the uniform should be provided.
/// Get a uniform form current shader,
/// the value type of the uniform should be provided.
/// </summary>
/// <param name="name">Name of the Uniform in shader code</param>
/// <returns></returns>
@@ -125,9 +130,10 @@ namespace StgSharp.Graphics
{
return new Uniform<T, U>(this, name, GL);
}
/// <summary>
/// Get a uniform form current shader,
/// the value type of the uniform should be provided.
/// Get a uniform form current shader,
/// the value type of the uniform should be provided.
/// </summary>
/// <param name="name">Name of the Uniform in shader code</param>
/// <returns></returns>
@@ -148,4 +154,4 @@ namespace StgSharp.Graphics
GL.UseProgram(handle);
}
}
}
}
@@ -0,0 +1,108 @@
using StgSharp.Graphics;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
namespace StgSharpDebug.Graphics.GL.ShaderEdit
{
public class ShaderGenerator
{
private List<string> codeList;
private List<ShaderFunction> usedShaderFunctions;
public Uniform<T> DefineUniform<T>() where T : struct
{
throw new NotImplementedException();
}
}
public class ShaderFunction
{
private string name;
private List<string> codeList;
private List<ShaderParameter> inputList;
private ShaderParameter outPut;
public int ParameterCount
{
get { return inputList.Count; }
}
public void EmitCall(ShaderFunction function, ShaderParameter outPut, params ShaderParameter[] inputParams)
{
if (inputParams.Length != function.ParameterCount)
{
throw new ArgumentException("Provided parameters does not match function's parameter list.");
}
if (!ShaderParameter.IsSameType(outPut, function.outPut))
{
throw new Exception("Provided parameters does not match function's parameter list.");
}
for (int i = 0; i < inputParams.Length; i++)
{
if (!ShaderParameter.IsSameType(function.inputList[i], inputParams[i]))
{
throw new Exception("Provided parameters does not match function's parameter list.");
}
}
string codeLine = "";
if (outPut != ShaderParameter.Void)
{
codeLine += $"{outPut.name} = ";
}
codeLine += $"{function.name}(";
foreach (ShaderParameter inputParam in inputParams)
{
codeLine += inputParam.name;
}
codeLine += ");\n";
codeList.Add(codeLine);
}
}
public class ShaderParameter
{
internal readonly InternalShaderType type;
internal readonly string name;
internal readonly bool isReadOnly;
public ShaderParameter(string name, InternalShaderType type)
{
this.name = name;
this.type = type;
isReadOnly = false;
}
public static readonly ShaderParameter Void = new ShaderParameter("", InternalShaderType.Void);
public static bool IsSameType(ShaderParameter param1, ShaderParameter param2)
{
if (param1.type != InternalShaderType.Struct)
{
return param1.type == param2.type;
}
else
{
throw new Exception("Struct is currently not supported.");
}
}
}
public enum InternalShaderType
{
#pragma warning disable CS1591
Struct, Void,
Int, UInt,
Float, Double,
Vector2, Vector3, Vector4,
VectorD2, VectorD3, VectorD4,
Matrix2x2, Matrix2x3, Matrix2x4,
Matrix3x2, Matrix3x3, Matrix3x4,
Matrix4x2, Matrix4x3, Matrix4x4,
#pragma warning restore CS1591
}
}
@@ -1,4 +1,5 @@
using StgSharp.Math;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -8,7 +9,6 @@ using System.Text;
namespace StgSharp.Graphics
{
public class Uniform<T> where T : struct
{
internal glSHandle id;
@@ -25,10 +25,8 @@ namespace StgSharp.Graphics
{
this.id = id;
}
}
public class Uniform<T, U>
where T : struct
where U : struct
@@ -88,12 +86,10 @@ namespace StgSharp.Graphics
{
this.id = id;
}
}
internal partial class GLonRender : IglFunc
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
unsafe void IglFunc.SetValue(Uniform<float> uniform, float v0)
{
@@ -156,8 +152,9 @@ namespace StgSharp.Graphics
unsafe void IglFunc.SetValue(Uniform<float, float> uniform, float f0, float f1)
{
M128 m = default;
m.UInt64[0] = (ulong)uniform.id.valuePtr;
m.Single[2] = f0; m.Single[3] = f1;
m.Write<ulong>(0, (ulong)uniform.id.valuePtr);
m.Write<float>(2, f0);
m.Write<float>(3, f1);
paramQueue.Enqueue(m);
glActionQueue.Enqueue(UniformVal2fPtr);
}
@@ -179,8 +176,8 @@ namespace StgSharp.Graphics
unsafe void IglFunc.SetValue(Uniform<float> uniform, float f0)
{
M128 m = default;
m.UInt64[0] = (ulong)uniform.id.valuePtr;
m.Single[2] = f0;
m.Write<ulong>(0, (ulong)uniform.id.valuePtr);
m.Write<float>(2, f0);
paramQueue.Enqueue(m);
glActionQueue.Enqueue(UniformVal1fPtr);
}
@@ -188,8 +185,8 @@ namespace StgSharp.Graphics
unsafe void IglFunc.SetValue(Uniform<int> uniform, int i0)
{
M128 m = default;
m.UInt64[0] = (ulong)uniform.id.valuePtr;
m.Int32[2] = i0;
m.Write<ulong>(0, (ulong)uniform.id.valuePtr);
m.Write<int>(2, i0);
paramQueue.Enqueue(m);
glActionQueue.Enqueue(UniformVal1fPtr);
}
@@ -205,28 +202,28 @@ namespace StgSharp.Graphics
{
M128 m = default;
paramQueue.TryDequeue(out m);
paramQueue.context->glUniform1f(*(int*)m.UInt64[0], m.Single[2]);
paramQueue.context->glUniform1f(*(int*)m.Read<uint>(0), m.Read<uint>(2));
}
private static unsafe void UniformVal1fv()
{
M128 m = default;
paramQueue.TryDequeue(out m);
paramQueue.context->glUniform1fv(*(int*)m.UInt64[0], 4, (Vec4d*)m.UInt64[0]);
paramQueue.context->glUniform1fv(*(int*)m.Read<ulong>(0), 4, (Vec4d*)&m.vec);
}
private static void UniformVal1i()
{
M128 m = default;
paramQueue.TryDequeue(out m);
paramQueue.context->glUniform1i(*(int*)m.UInt64[0], m.Int32[2]);
paramQueue.context->glUniform1i(*(int*)m.Read<uint>(0), m.Read<int>(2));
}
private static void UniformVal2f()
{
M128 m = default;
paramQueue.TryDequeue(out m);
paramQueue.context->glUniform2f(*(int*)m.UInt64[0], m.Single[2], m.Single[3]);
paramQueue.context->glUniform2f(*(int*)m.Read<uint>(0), m.Read<float>(2), m.Read<float>(3));
}
private static void UniformVal3f()
@@ -235,16 +232,16 @@ namespace StgSharp.Graphics
M128 m = default;
paramQueue.TryDequeue(out handle);
paramQueue.TryDequeue(out m);
paramQueue.context->glUniform3f(*(int*)handle, m.Single[0], m.Single[1], m.Single[2]);
paramQueue.context->glUniform3f(*(int*)handle, m.Read<float>(0), m.Read<float>(1), m.Read<float>(2));
}
private static void UniformVal4f()
{
IntPtr handle = IntPtr.Zero;
M128 m = default;
paramQueue.TryDequeue(out handle);
paramQueue.TryDequeue(out m);
paramQueue.context->glUniform4f(*(int*)handle, m.Single[0], m.Single[1], m.Single[2], m.Single[2]);
paramQueue.context->glUniform4f(*(int*)handle, m.Read<float>(0), m.Read<float>(1), m.Read<float>(2), m.Read<float>(3));
}
}
}
}