daily update on 20240403 by nitload youmu
This commit is contained in:
@@ -44,7 +44,7 @@ namespace StgSharp.Graphics
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
protected Shader CreateShader(ShaderType type, int count)
|
||||
{
|
||||
return new Shader(this.gl, gl.CreateShaderSet(count, type), type);
|
||||
return new Shader( GL.CreateShaderSet(count, type), type);
|
||||
}
|
||||
/// <summary>
|
||||
/// Create an instance of <see cref="Shader"/> program
|
||||
@@ -61,23 +61,22 @@ namespace StgSharp.Graphics
|
||||
public class Shader
|
||||
{
|
||||
|
||||
private readonly IglFunc GL;
|
||||
internal readonly glHandleSet handle;
|
||||
private readonly IntPtr context;
|
||||
internal readonly GLhandle handle;
|
||||
public readonly ShaderType type;
|
||||
|
||||
internal Shader(IglFunc gl, glHandleSet handle, ShaderType usage)
|
||||
internal unsafe Shader(uint[] handle, ShaderType usage)
|
||||
{
|
||||
this.handle = handle;
|
||||
GL = gl;
|
||||
context = (IntPtr)GL.api;
|
||||
type = usage;
|
||||
}
|
||||
|
||||
//TODO:写链接着色器的文档注释
|
||||
/// <summary>
|
||||
///
|
||||
/// Attach one shader code to a shader program.
|
||||
/// </summary>
|
||||
/// <param name="target"></param>
|
||||
/// <param name="index"></param>
|
||||
/// <param name="target">Shader program to attach</param>
|
||||
/// <param name="index">Index of shader code in current shader code set.</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void AttachTo(int index, ShaderProgram target)
|
||||
{
|
||||
@@ -105,7 +104,7 @@ namespace StgSharp.Graphics
|
||||
public class ShaderProgram
|
||||
{
|
||||
|
||||
private readonly Form binding;
|
||||
private readonly IntPtr binding;
|
||||
internal readonly glHandle handle;
|
||||
|
||||
/// <summary>
|
||||
@@ -113,8 +112,8 @@ namespace StgSharp.Graphics
|
||||
/// </summary>
|
||||
internal unsafe ShaderProgram(Form binding)
|
||||
{
|
||||
this.binding = binding;
|
||||
handle = binding.GL.CreateProgram();
|
||||
this.binding = binding.graphicContextID;
|
||||
handle = GL.CreateProgram();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -153,7 +152,21 @@ namespace StgSharp.Graphics
|
||||
where U : struct
|
||||
where V : struct
|
||||
{
|
||||
return new Uniform<T, U, V>(this, name, binding);
|
||||
return new Uniform<T, U, V>(this, name);
|
||||
}
|
||||
/// <summary>
|
||||
/// 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>
|
||||
public unsafe Uniform<T, U, V, W> GetUniform<T, U, V, W>(string name)
|
||||
where T : struct
|
||||
where U : struct
|
||||
where V : struct
|
||||
where W : struct
|
||||
{
|
||||
return new Uniform<T, U, V, W>(this, name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -161,7 +174,7 @@ namespace StgSharp.Graphics
|
||||
/// </summary>
|
||||
public unsafe void Link()
|
||||
{
|
||||
if (InternalIO.InternalLinkShaderProgram(binding.GL.Context, handle.Value) == 0)
|
||||
if (InternalIO.InternalLinkShaderProgram((GLcontext*)this.binding, handle.Value) == 0)
|
||||
{
|
||||
IntPtr logPtr = InternalIO.InternalReadSSCLog();
|
||||
try
|
||||
@@ -185,7 +198,7 @@ namespace StgSharp.Graphics
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe void Use()
|
||||
{
|
||||
binding.GL.UseProgram(handle);
|
||||
GL.UseProgram(handle);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Math;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -37,16 +38,19 @@ using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Graphics.GL.ShaderEdit
|
||||
namespace StgSharp.Graphics.ShaderEdit
|
||||
{
|
||||
public class ShaderGenerator
|
||||
{
|
||||
|
||||
private Dictionary<int,ShaderParameter> uniformDefine;
|
||||
private List<string> codeList;
|
||||
private List<ShaderFunction> usedShaderFunctions;
|
||||
|
||||
public Uniform<T> DefineUniform<T>() where T : struct
|
||||
public Uniform<T> DefineUniform<T>(string name, int index) where T : struct
|
||||
{
|
||||
ShaderParameter p = new ShaderParameter(name,ShaderParameter.TypeMarshal<T>());
|
||||
uniformDefine.Add(index,p);
|
||||
//return new Uniform<T>();
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@@ -54,7 +58,6 @@ namespace StgSharp.Graphics.GL.ShaderEdit
|
||||
|
||||
public class ShaderFunction
|
||||
{
|
||||
|
||||
private List<string> codeList;
|
||||
private List<ShaderParameter> inputList;
|
||||
private string name;
|
||||
@@ -100,7 +103,6 @@ namespace StgSharp.Graphics.GL.ShaderEdit
|
||||
|
||||
public class ShaderParameter
|
||||
{
|
||||
|
||||
public static readonly ShaderParameter Void = new ShaderParameter(string.Empty, InternalShaderType.Void);
|
||||
internal readonly bool isReadOnly;
|
||||
internal readonly string name;
|
||||
@@ -125,6 +127,48 @@ namespace StgSharp.Graphics.GL.ShaderEdit
|
||||
}
|
||||
}
|
||||
|
||||
public static InternalShaderType TypeMarshal<T>() where T : struct
|
||||
{
|
||||
switch (Type.GetTypeCode(typeof(T)))
|
||||
{
|
||||
case TypeCode.Single:
|
||||
return InternalShaderType.Float;
|
||||
case TypeCode.Double:
|
||||
return InternalShaderType.Double;
|
||||
case TypeCode.Int32:
|
||||
return InternalShaderType.Int;
|
||||
case TypeCode.UInt32:
|
||||
return InternalShaderType.UInt;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
switch (typeof(T).Name)
|
||||
{
|
||||
case "Vec4d":
|
||||
return InternalShaderType.Vector4;
|
||||
case "Matrix2x2":
|
||||
return InternalShaderType.Matrix2x2;
|
||||
case "Matrix2x3":
|
||||
return InternalShaderType.Matrix2x3;
|
||||
case "Matrix2x4":
|
||||
return InternalShaderType.Matrix2x4;
|
||||
case "Matrix3x2":
|
||||
return InternalShaderType.Matrix3x2;
|
||||
case "Matrix3x3":
|
||||
return InternalShaderType.Matrix3x3;
|
||||
case "Matrix3x4":
|
||||
return InternalShaderType.Matrix3x4;
|
||||
case "Matrix4x2":
|
||||
return InternalShaderType.Matrix4x2;
|
||||
case "Matrix4x3":
|
||||
return InternalShaderType.Matrix4x3;
|
||||
case "Matrix4x4":
|
||||
return InternalShaderType.Matrix4x4;
|
||||
default:
|
||||
throw new ArgumentException("Not supported shader data type.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public enum InternalShaderType
|
||||
|
||||
@@ -42,7 +42,7 @@ namespace StgSharp.Graphics
|
||||
public class Uniform<T> where T : struct
|
||||
{
|
||||
|
||||
private Form binding;
|
||||
private IntPtr binding;
|
||||
internal glSHandle id;
|
||||
|
||||
internal unsafe Uniform(glSHandle id)
|
||||
@@ -52,9 +52,15 @@ namespace StgSharp.Graphics
|
||||
|
||||
internal unsafe Uniform(
|
||||
ShaderProgram program, string name, Form binding)
|
||||
{
|
||||
this.binding = binding.graphicContextID;
|
||||
id = GL.GetUniformLocation(program.handle, name);
|
||||
}
|
||||
internal unsafe Uniform(
|
||||
ShaderProgram program, string name, IntPtr binding)
|
||||
{
|
||||
this.binding = binding;
|
||||
id = binding.GL.GetUniformLocation(program.handle, name);
|
||||
id = GL.GetUniformLocation(program.handle, name);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -64,7 +70,7 @@ namespace StgSharp.Graphics
|
||||
where U : struct
|
||||
{
|
||||
|
||||
private Form binding;
|
||||
private IntPtr binding;
|
||||
internal glSHandle id;
|
||||
|
||||
internal unsafe Uniform(glSHandle id)
|
||||
@@ -74,9 +80,16 @@ namespace StgSharp.Graphics
|
||||
|
||||
internal unsafe Uniform(
|
||||
ShaderProgram program, string name, Form binding)
|
||||
{
|
||||
this.binding = binding.graphicContextID;
|
||||
id = GL.GetUniformLocation(program.handle, name);
|
||||
}
|
||||
|
||||
internal unsafe Uniform(
|
||||
ShaderProgram program, string name, IntPtr binding)
|
||||
{
|
||||
this.binding = binding;
|
||||
id = binding.GL.GetUniformLocation(program.handle, name);
|
||||
id = GL.GetUniformLocation(program.handle, name);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -87,7 +100,7 @@ namespace StgSharp.Graphics
|
||||
where V : struct
|
||||
{
|
||||
|
||||
private Form binding;
|
||||
private IntPtr binding;
|
||||
internal glSHandle id;
|
||||
|
||||
internal unsafe Uniform(glSHandle id)
|
||||
@@ -95,10 +108,17 @@ namespace StgSharp.Graphics
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
internal unsafe Uniform(
|
||||
ShaderProgram program, string name)
|
||||
{
|
||||
this.binding = (IntPtr)GL.api;
|
||||
id = GL.GetUniformLocation(program.handle, name);
|
||||
}
|
||||
|
||||
public unsafe Uniform(ShaderProgram program, string name, Form binding)
|
||||
{
|
||||
this.binding = binding;
|
||||
id = binding.GL.GetUniformLocation(program.handle, name);
|
||||
this.binding = binding.graphicContextID;
|
||||
id = GL.GetUniformLocation(program.handle, name);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -110,7 +130,7 @@ namespace StgSharp.Graphics
|
||||
where W : struct
|
||||
{
|
||||
|
||||
private Form binding;
|
||||
private IntPtr binding;
|
||||
internal glSHandle id;
|
||||
|
||||
internal unsafe Uniform(glSHandle id)
|
||||
@@ -120,55 +140,62 @@ namespace StgSharp.Graphics
|
||||
|
||||
internal unsafe Uniform(ShaderProgram program, string name, Form binding)
|
||||
{
|
||||
this.binding = binding;
|
||||
id = binding.GL.GetUniformLocation(program.handle, name);
|
||||
this.binding = binding.graphicContextID;
|
||||
id = GL.GetUniformLocation(program.handle, name);
|
||||
}
|
||||
|
||||
internal unsafe Uniform(
|
||||
ShaderProgram program, string name)
|
||||
{
|
||||
this.binding = (IntPtr)GL.api;
|
||||
id = GL.GetUniformLocation(program.handle, name);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
internal partial class GLpack : IglFunc
|
||||
internal static partial class GL
|
||||
{
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe void SetValue(Uniform<float, float, float, float> uniform, Vec4d vec)
|
||||
public unsafe static void SetValue(Uniform<float, float, float, float> uniform, Vec4d vec)
|
||||
{
|
||||
api->glUniform1fv(uniform.id.DirectValue, 4, &vec);
|
||||
api->glUniform1fv(uniform.id.DirectValue , 4, &vec);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe void SetValue(Uniform<Vec4d> uniform, Vec4d vec)
|
||||
public unsafe static void SetValue(Uniform<Vec4d> uniform, Vec4d vec)
|
||||
{
|
||||
api->glUniform1fv(uniform.id.DirectValue, 4, &vec);
|
||||
api->glUniform1fv(uniform.id.DirectValue , 4, &vec);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
unsafe void IglFunc.SetValue(Uniform<float> uniform, float v0)
|
||||
public static unsafe void SetValue(Uniform<float> uniform, float v0)
|
||||
{
|
||||
api->glUniform1f(uniform.id.DirectValue, v0);
|
||||
api->glUniform1f(uniform.id.DirectValue , v0);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
unsafe void IglFunc.SetValue(Uniform<int> uniform, int i0)
|
||||
public static unsafe void SetValue(Uniform<int> uniform, int i0)
|
||||
{
|
||||
api->glUniform1i(uniform.id.DirectValue, i0);
|
||||
api->glUniform1i(uniform.id.DirectValue , i0);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
unsafe void IglFunc.SetValue(Uniform<float, float> uniform, float v0, float v1)
|
||||
public static unsafe void SetValue(Uniform<float, float> uniform, float v0, float v1)
|
||||
{
|
||||
api->glUniform2f(uniform.id.DirectValue, v0, v1);
|
||||
api->glUniform2f(uniform.id.DirectValue , v0, v1);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
unsafe void IglFunc.SetValue(Uniform<float, float, float> uniform, float v0, float v1, float v2)
|
||||
public static unsafe void SetValue(Uniform<float, float, float> uniform, float v0, float v1, float v2)
|
||||
{
|
||||
api->glUniform3f(uniform.id.DirectValue, v0, v1, v2);
|
||||
api->glUniform3f(uniform.id.DirectValue , v0, v1, v2);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
unsafe void IglFunc.SetValue(Uniform<float, float, float, float> uniform, float v0, float v1, float v2, float v3)
|
||||
public static unsafe void SetValue(Uniform<float, float, float, float> uniform, float v0, float v1, float v2, float v3)
|
||||
{
|
||||
api->glUniform4f(uniform.id.DirectValue, v0, v1, v2, v3);
|
||||
api->glUniform4f(uniform.id.DirectValue , v0, v1, v2, v3);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user