daily update on 20240407 by nitload youmu
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Graphics.ShaderEdit
|
||||
{
|
||||
public interface IglConvertable
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void SetAllUniforms();
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void GainAllUniforms(ShaderProgram source, params string[] uniformName);
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void DisplayGLtypeDefinition();
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public ShaderStruct GetConvertedGLtype();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -40,7 +40,6 @@ namespace StgSharp.Graphics
|
||||
{
|
||||
public partial class Form
|
||||
{
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
protected Shader CreateShader(ShaderType type, int count)
|
||||
{
|
||||
@@ -55,17 +54,16 @@ namespace StgSharp.Graphics
|
||||
{
|
||||
return new ShaderProgram(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class Shader
|
||||
{
|
||||
|
||||
private readonly IntPtr context;
|
||||
internal readonly GLhandle handle;
|
||||
internal readonly glHandleSet handle;
|
||||
public readonly ShaderType type;
|
||||
|
||||
internal unsafe Shader(uint[] handle, ShaderType usage)
|
||||
internal unsafe Shader(glHandleSet handle, ShaderType usage)
|
||||
{
|
||||
this.handle = handle;
|
||||
context = (IntPtr)GL.api;
|
||||
@@ -108,7 +106,7 @@ namespace StgSharp.Graphics
|
||||
internal readonly glHandle handle;
|
||||
|
||||
/// <summary>
|
||||
/// Inti a shader with no program attached.
|
||||
/// Init a program with no shader attached.
|
||||
/// </summary>
|
||||
internal unsafe ShaderProgram(Form binding)
|
||||
{
|
||||
@@ -201,5 +199,10 @@ namespace StgSharp.Graphics
|
||||
GL.UseProgram(handle);
|
||||
}
|
||||
|
||||
~ShaderProgram()
|
||||
{
|
||||
//handle.Dispose();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -144,7 +144,7 @@ namespace StgSharp.Graphics.ShaderEdit
|
||||
}
|
||||
switch (typeof(T).Name)
|
||||
{
|
||||
case "Vec4d":
|
||||
case "vec4d":
|
||||
return InternalShaderType.Vector4;
|
||||
case "Matrix2x2":
|
||||
return InternalShaderType.Matrix2x2;
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Graphics.ShaderEdit
|
||||
{
|
||||
public class ShaderStructMember
|
||||
{
|
||||
internal InternalShaderType type;
|
||||
internal object value;
|
||||
}
|
||||
|
||||
public class ShaderStruct
|
||||
{
|
||||
internal Dictionary<glSHandle, ShaderStructMember> uniformPair;
|
||||
|
||||
public ShaderStruct(params (glSHandle, ShaderStructMember)[] UniformPais)
|
||||
{
|
||||
uniformPair = new Dictionary<glSHandle, ShaderStructMember>();
|
||||
if (UniformPais.Length == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var item in UniformPais)
|
||||
{
|
||||
uniformPair.Add(item.Item1,item.Item2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
internal ShaderStruct() { }
|
||||
|
||||
|
||||
public unsafe void SetAllUniforms()
|
||||
{
|
||||
GLcontext* gl = GL.api;
|
||||
foreach (var uniform in uniformPair)
|
||||
{
|
||||
int id = uniform.Key.Value;
|
||||
ShaderStructMember s = uniform.Value;
|
||||
switch (s.type)
|
||||
{
|
||||
case InternalShaderType.Struct: throw new ArgumentException(
|
||||
"Incorrect type \"Struct\" defined in this self define type");
|
||||
case InternalShaderType.Void:throw new ArgumentException(
|
||||
"Incorrect type \"Void\" defined in this self define type");
|
||||
case InternalShaderType.Float:
|
||||
gl->glUniform1f(id, (float)s.value);
|
||||
break;
|
||||
case InternalShaderType.Int:
|
||||
gl->glUniform1f(id, (int)s.value);
|
||||
break;
|
||||
default:
|
||||
throw new NotImplementedException();
|
||||
throw new ArgumentException(
|
||||
"Incorrect type \"Unknown\" defined in this self define type");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -28,6 +28,7 @@
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Graphic;
|
||||
using StgSharp.Math;
|
||||
|
||||
using System;
|
||||
@@ -39,12 +40,22 @@ using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
public class Uniform<T> where T : struct
|
||||
public class Uniform
|
||||
{
|
||||
|
||||
private IntPtr binding;
|
||||
protected IntPtr binding;
|
||||
internal glSHandle id;
|
||||
|
||||
|
||||
public glSHandle Handle
|
||||
{
|
||||
get => id;
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class Uniform<T> : Uniform
|
||||
where T : struct
|
||||
{
|
||||
|
||||
internal unsafe Uniform(glSHandle id)
|
||||
{
|
||||
this.id = id;
|
||||
@@ -56,6 +67,7 @@ namespace StgSharp.Graphics
|
||||
this.binding = binding.graphicContextID;
|
||||
id = GL.GetUniformLocation(program.handle, name);
|
||||
}
|
||||
|
||||
internal unsafe Uniform(
|
||||
ShaderProgram program, string name, IntPtr binding)
|
||||
{
|
||||
@@ -63,16 +75,23 @@ namespace StgSharp.Graphics
|
||||
id = GL.GetUniformLocation(program.handle, name);
|
||||
}
|
||||
|
||||
internal Uniform()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
internal static Uniform<T> FromHandle(glSHandle handle)
|
||||
{
|
||||
return new Uniform<T>() { id = handle };
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class Uniform<T, U>
|
||||
public sealed class Uniform<T, U>: Uniform
|
||||
where T : struct
|
||||
where U : struct
|
||||
{
|
||||
|
||||
private IntPtr binding;
|
||||
internal glSHandle id;
|
||||
|
||||
internal unsafe Uniform(glSHandle id)
|
||||
{
|
||||
this.id = id;
|
||||
@@ -92,17 +111,24 @@ namespace StgSharp.Graphics
|
||||
id = GL.GetUniformLocation(program.handle, name);
|
||||
}
|
||||
|
||||
internal Uniform()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
internal static Uniform<T,U> FromHandle(glSHandle handle)
|
||||
{
|
||||
return new Uniform<T, U>() { id = handle };
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class Uniform<T, U, V>
|
||||
public sealed class Uniform<T, U, V>:Uniform
|
||||
where T : struct
|
||||
where U : struct
|
||||
where V : struct
|
||||
{
|
||||
|
||||
private IntPtr binding;
|
||||
internal glSHandle id;
|
||||
|
||||
internal unsafe Uniform(glSHandle id)
|
||||
{
|
||||
this.id = id;
|
||||
@@ -121,17 +147,25 @@ namespace StgSharp.Graphics
|
||||
id = GL.GetUniformLocation(program.handle, name);
|
||||
}
|
||||
|
||||
internal Uniform()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
internal static Uniform<T,U,V> FromHandle(glSHandle handle)
|
||||
{
|
||||
return new Uniform<T, U, V>() { id = handle };
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class Uniform<T, U, V, W>
|
||||
public sealed class Uniform<T, U, V, W>:Uniform
|
||||
where T : struct
|
||||
where U : struct
|
||||
where V : struct
|
||||
where W : struct
|
||||
{
|
||||
|
||||
private IntPtr binding;
|
||||
internal glSHandle id;
|
||||
|
||||
internal unsafe Uniform(glSHandle id)
|
||||
{
|
||||
@@ -151,51 +185,69 @@ namespace StgSharp.Graphics
|
||||
id = GL.GetUniformLocation(program.handle, name);
|
||||
}
|
||||
|
||||
internal Uniform()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
internal static Uniform<T, U, V, W> FromHandle(glSHandle handle)
|
||||
{
|
||||
return new Uniform<T, U, V, W>() { id = handle };
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
internal static partial class GL
|
||||
{
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe static void SetValue(Uniform<float, float, float, float> uniform, Vec4d vec)
|
||||
public unsafe static void SetValue(Uniform<Matrix44> uniform, Matrix44 mat)
|
||||
{
|
||||
api->glUniform1fv(uniform.id.DirectValue , 4, &vec);
|
||||
Matrix44 temp = mat;
|
||||
api->glUniformMatrix4fv(uniform.Handle.Value, 16, false, (float*)&mat);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe static void SetValue(Uniform<Vec4d> uniform, Vec4d vec)
|
||||
public unsafe static void SetValue(Uniform<float, float, float, float> uniform, vec4d vec)
|
||||
{
|
||||
api->glUniform1fv(uniform.id.DirectValue , 4, &vec);
|
||||
vec4d temp = vec;
|
||||
api->glUniform1fv(uniform.id.Value , 4, &temp);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe static void SetValue(Uniform<vec4d> uniform, vec4d vec)
|
||||
{
|
||||
vec4d temp = vec;
|
||||
api->glUniform1fv(uniform.id.Value , 4, &temp);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void SetValue(Uniform<float> uniform, float v0)
|
||||
{
|
||||
api->glUniform1f(uniform.id.DirectValue , v0);
|
||||
api->glUniform1f(uniform.id.Value , v0);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void SetValue(Uniform<int> uniform, int i0)
|
||||
{
|
||||
api->glUniform1i(uniform.id.DirectValue , i0);
|
||||
api->glUniform1i(uniform.id.Value , i0);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void SetValue(Uniform<float, float> uniform, float v0, float v1)
|
||||
{
|
||||
api->glUniform2f(uniform.id.DirectValue , v0, v1);
|
||||
api->glUniform2f(uniform.id.Value , v0, v1);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
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.Value , v0, v1, v2);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
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.Value , v0, v1, v2, v3);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user