daily update on 20241002 by nitload youmu, intrinsic function rebuild, syntax style arrange

This commit is contained in:
Nitload
2024-10-03 04:03:06 +08:00
parent 0979123ac0
commit 6e2f93b053
265 changed files with 26732 additions and 19058 deletions
@@ -42,22 +42,25 @@ namespace StgSharp.Graphics.ShaderEdit
{
/// <summary>
///
///
/// </summary>
public void DisplayGLtypeDefinition();
/// <summary>
///
///
/// </summary>
public void GainAllUniforms(ShaderProgram source, params string[] uniformName);
public void GainAllUniforms(
ShaderProgram source,
params string[] uniformName );
/// <summary>
///
///
/// </summary>
/// <returns></returns>
public ShaderStruct GetConvertedGLtype();
/// <summary>
///
///
/// </summary>
public void SetAllUniforms();
@@ -45,19 +45,21 @@ namespace StgSharp.Graphics.OpenGL
{
/// <summary>
/// Create an instance of <see cref="Shader"/> program
/// Create an instance of <see cref="Shader" /> program
/// </summary>
/// <returns>New instance of <see cref="Shader"/> instance. </returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
/// <returns> New instance of <see cref="Shader" /> instance. </returns>
[MethodImpl( MethodImplOptions.AggressiveInlining )]
protected override sealed ShaderProgram CreateShaderProgram()
{
return new ShaderProgram(this);
return new ShaderProgram( this );
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected override sealed Shader CreateShaderSegment(ShaderType type, int count)
[MethodImpl( MethodImplOptions.AggressiveInlining )]
protected override sealed Shader CreateShaderSegment(
ShaderType type,
int count )
{
return new Shader(GL.CreateShaderSet(count, type), type, this);
return new Shader( GL.CreateShaderSet( count, type ), type, this );
}
}
@@ -69,7 +71,10 @@ namespace StgSharp.Graphics.OpenGL
internal readonly GlHandle[] handle;
public readonly ShaderType type;
internal unsafe Shader(GlHandle[] handle, ShaderType usage, glRender stream)
internal unsafe Shader(
GlHandle[] handle,
ShaderType usage,
glRender stream )
{
this.handle = handle;
GL = stream.GL;
@@ -81,60 +86,58 @@ namespace StgSharp.Graphics.OpenGL
/// <summary>
/// Attach one shader code to a shader program.
/// </summary>
/// <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)
/// <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 )
{
GL.AttachShader(target.handle, handle[index]);
GL.AttachShader( target.handle, handle[ index ] );
}
public void CheckStatus(int index, ShaderStatus status)
public void CheckStatus( int index, ShaderStatus status )
{
string log = GL.GetShaderStatus(this, index, (int)status);
if (!string.IsNullOrEmpty(log))
{
throw new Exception($"{$"Shader Error \t{status}\n"}{log}");
string log = GL.GetShaderStatus( this, index, ( int )status );
if( !string.IsNullOrEmpty( log ) ) {
throw new Exception( $"{$"Shader Error \t{status}\n"}{log}" );
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe void Compile(int index, byte[] codeStream)
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public unsafe void Compile( int index, byte[] codeStream )
{
if (codeStream == null)
{
throw new ArgumentNullException(nameof(codeStream));
if( codeStream == null ) {
throw new ArgumentNullException( nameof( codeStream ) );
}
GL.LoadShaderSource(handle[index], codeStream);
GL.CompileShader(handle[index]);
CheckStatus(index, ShaderStatus.CompileStatus);
GL.LoadShaderSource( handle[ index ], codeStream );
GL.CompileShader( handle[ index ] );
CheckStatus( index, ShaderStatus.CompileStatus );
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe void Compile(int index, string codeStream)
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public unsafe void Compile( int index, string codeStream )
{
if (codeStream == null)
{
throw new ArgumentNullException(nameof(codeStream));
if( codeStream == null ) {
throw new ArgumentNullException( nameof( codeStream ) );
}
GL.LoadShaderSource(handle[index], Encoding.ASCII.GetBytes(codeStream));
GL.CompileShader(handle[index]);
CheckStatus(index, ShaderStatus.CompileStatus);
GL.LoadShaderSource(
handle[ index ], Encoding.ASCII.GetBytes( codeStream ) );
GL.CompileShader( handle[ index ] );
CheckStatus( index, ShaderStatus.CompileStatus );
}
public void FromBytes(byte[] stream)
public void FromBytes( byte[] stream )
{
throw new NotImplementedException();
}
public static byte[] FromCodeFile(string fileRoute)
public static byte[] FromCodeFile( string fileRoute )
{
string str = File.ReadAllText(fileRoute);
if (string.IsNullOrEmpty(str))
{
throw new InvalidOperationException($"Cannot load and GLSL code from {fileRoute}");
string str = File.ReadAllText( fileRoute );
if( string.IsNullOrEmpty( str ) ) {
throw new InvalidOperationException(
$"Cannot load and GLSL code from {fileRoute}" );
}
return Encoding.UTF8.GetBytes(str);
return Encoding.UTF8.GetBytes( str );
}
public byte[] GetBytes()
@@ -142,7 +145,7 @@ namespace StgSharp.Graphics.OpenGL
return Array.Empty<byte>();
}
public byte[] GetBytes(out int length)
public byte[] GetBytes( out int length )
{
throw new NotImplementedException();
}
@@ -156,7 +159,9 @@ namespace StgSharp.Graphics.OpenGL
public enum ShaderStatus : int
{
CompileStatus = GLconst.COMPILE_STATUS,
}
public class ShaderProgram
@@ -168,64 +173,63 @@ namespace StgSharp.Graphics.OpenGL
/// <summary>
/// CustomizeInit a program with no shader attached.
/// </summary>
internal unsafe ShaderProgram(glRender binding)
internal unsafe ShaderProgram( glRender binding )
{
GL = binding.GL;
handle = GL.CreateProgram();
}
/// <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">ContextName of the Uniform in shader code</param>
/// <param name="name"> ContextName of the Uniform in shader code </param>
/// <returns></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe Uniform<T> GetUniform<T>(string name) where T : struct
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public unsafe Uniform<T> GetUniform<T>( string name ) where T: struct
{
return new Uniform<T>(GL.GetUniformLocation(this.handle, name));
return new Uniform<T>( GL.GetUniformLocation( this.handle, name ) );
}
/// <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">ContextName of the Uniform in shader code</param>
/// <param name="name"> ContextName of the Uniform in shader code </param>
/// <returns></returns>
public unsafe Uniform<T, U> GetUniform<T, U>(string name)
where T : struct
where U : struct
public unsafe Uniform<T, U> GetUniform<T, U>( string name )
where T: struct
where U: struct
{
return new Uniform<T, U>(GL.GetUniformLocation(this.handle, name));
return new Uniform<T, U>(
GL.GetUniformLocation( this.handle, name ) );
}
/// <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">ContextName of the Uniform in shader code</param>
/// <param name="name"> ContextName of the Uniform in shader code </param>
/// <returns></returns>
public unsafe Uniform<T, U, V> GetUniform<T, U, V>(string name)
where T : struct
where U : struct
where V : struct
public unsafe Uniform<T, U, V> GetUniform<T, U, V>( string name )
where T: struct
where U: struct
where V: struct
{
return new Uniform<T, U, V>(GL.GetUniformLocation(this.handle, name));
return new Uniform<T, U, V>(
GL.GetUniformLocation( this.handle, name ) );
}
/// <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">ContextName of the Uniform in shader code</param>
/// <param name="name"> ContextName 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
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>(GL.GetUniformLocation(this.handle, name));
return new Uniform<T, U, V, W>(
GL.GetUniformLocation( this.handle, name ) );
}
/// <summary>
@@ -233,20 +237,18 @@ namespace StgSharp.Graphics.OpenGL
/// </summary>
public unsafe void Link()
{
if (InternalIO.InternalLinkShaderProgram((OpenglContext*)this.GL.ContextHandle, handle.Value) == 0)
{
if( InternalIO.InternalLinkShaderProgram(
( OpenglContext* )this.GL.ContextHandle, handle.Value ) == 0 ) {
IntPtr logPtr = InternalIO.InternalReadSSCLog();
try
{
try {
byte[] logByte = new byte[512];
Marshal.Copy(logPtr, logByte, 0, 512);
string log = Encoding.UTF8.GetString(logByte);
log = log.Replace("\0", string.Empty);
InternalIO.InternalWriteLog(log, LogType.Error);
Marshal.Copy( logPtr, logByte, 0, 512 );
string log = Encoding.UTF8.GetString( logByte );
log = log.Replace( "\0", string.Empty );
InternalIO.InternalWriteLog( log, LogType.Error );
}
catch (Exception ex)
{
InternalIO.InternalWriteLog(ex.Message, LogType.Error);
catch( Exception ex ) {
InternalIO.InternalWriteLog( ex.Message, LogType.Error );
}
}
}
@@ -254,10 +256,10 @@ namespace StgSharp.Graphics.OpenGL
/// <summary>
/// Let the current viewPortDisplay use this shader.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public unsafe void Use()
{
GL.UseProgram(handle);
GL.UseProgram( handle );
}
~ShaderProgram()
@@ -52,93 +52,73 @@ namespace StgSharp.Graphics.OpenGL
}
public sealed class Uniform<T> : Uniform
where T : struct
public sealed class Uniform<T> : Uniform where T: struct
{
internal Uniform()
{
internal Uniform() { }
}
internal unsafe Uniform(GlHandle id)
internal unsafe Uniform( GlHandle id )
{
this.id = id;
}
internal static Uniform<T> FromHandle(GlHandle handle)
internal static Uniform<T> FromHandle( GlHandle handle )
{
return new Uniform<T> { id = handle };
}
}
public sealed class Uniform<T, U> : Uniform
where T : struct
where U : struct
public sealed class Uniform<T, U> : Uniform where T: struct where U: struct
{
internal Uniform() { }
internal Uniform()
{
}
internal unsafe Uniform(GlHandle id)
internal unsafe Uniform( GlHandle id )
{
this.id = id;
}
internal static Uniform<T, U> FromHandle(GlHandle handle)
internal static Uniform<T, U> FromHandle( GlHandle handle )
{
return new Uniform<T, U> { id = handle };
}
}
public sealed class Uniform<T, U, V> : Uniform
where T : struct
where U : struct
where V : struct
public sealed class Uniform<T, U, V> : Uniform where T: struct
where U: struct
where V: struct
{
internal Uniform()
{
internal Uniform() { }
}
internal unsafe Uniform(GlHandle id)
internal unsafe Uniform( GlHandle id )
{
this.id = id;
}
internal static Uniform<T, U, V> FromHandle(GlHandle handle)
internal static Uniform<T, U, V> FromHandle( GlHandle handle )
{
return new Uniform<T, U, V> { id = handle };
}
}
public sealed class Uniform<T, U, V, W> : Uniform
where T : struct
where U : struct
where V : struct
where W : struct
public sealed class Uniform<T, U, V, W> : Uniform where T: struct
where U: struct
where V: struct
where W: struct
{
internal Uniform()
{
internal Uniform() { }
}
internal unsafe Uniform(GlHandle id)
internal unsafe Uniform( GlHandle id )
{
this.id = id;
}
internal static Uniform<T, U, V, W> FromHandle(GlHandle handle)
internal static Uniform<T, U, V, W> FromHandle( GlHandle handle )
{
return new Uniform<T, U, V, W> { id = handle };
}
@@ -148,59 +128,71 @@ namespace StgSharp.Graphics.OpenGL
public unsafe partial class OpenGLFunction
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void SetUniformValue
(Uniform<Matrix44> uniform, Matrix44 mat)
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public void SetUniformValue( Uniform<Matrix44> uniform, Matrix44 mat )
{
Matrix44 temp = mat;
Context.glUniformMatrix4fv(uniform.id.SignedValue, 1, false, (float*)&temp);
Context.glUniformMatrix4fv(
uniform.id.SignedValue, 1, false, ( float* )&temp );
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void SetUniformValue(Uniform<float, float, float, float> uniform, vec4d vec)
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public void SetUniformValue(
Uniform<float, float, float, float> uniform,
Vec4 vec )
{
vec4d temp = vec;
Context.glUniform1fv(uniform.id.SignedValue, 4, &temp);
Vec4 temp = vec;
Context.glUniform1fv( uniform.id.SignedValue, 4, &temp );
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void SetUniformValue(Uniform<vec4d> uniform, vec4d vec)
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public void SetUniformValue( Uniform<Vec4> uniform, Vec4 vec )
{
vec4d temp = vec;
Context.glUniform1fv(uniform.id.SignedValue, 4, &temp);
Vec4 temp = vec;
Context.glUniform1fv( uniform.id.SignedValue, 4, &temp );
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void SetUniformValue(Uniform<float> uniform, float v0)
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public void SetUniformValue( Uniform<float> uniform, float v0 )
{
Context.glUniform1f(uniform.id.SignedValue, v0);
Context.glUniform1f( uniform.id.SignedValue, v0 );
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void SetUniformValue(Uniform<int> uniform, int i0)
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public void SetUniformValue( Uniform<int> uniform, int i0 )
{
Context.glUniform1i(uniform.id.SignedValue, i0);
Context.glUniform1i( uniform.id.SignedValue, i0 );
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void SetUniformValue(Uniform<float, float> uniform, float v0, float v1)
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public void SetUniformValue(
Uniform<float, float> uniform,
float v0,
float v1 )
{
Context.glUniform2f(uniform.id.SignedValue, v0, v1);
Context.glUniform2f( uniform.id.SignedValue, v0, v1 );
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void SetUniformValue(Uniform<float, float, float> uniform, float v0, float v1, float v2)
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public void SetUniformValue(
Uniform<float, float, float> uniform,
float v0,
float v1,
float v2 )
{
Context.glUniform3f(uniform.id.SignedValue, v0, v1, v2);
Context.glUniform3f( uniform.id.SignedValue, v0, v1, v2 );
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void SetUniformValue(Uniform<float, float, float, float> uniform, float v0, float v1, float v2, float v3)
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public void SetUniformValue(
Uniform<float, float, float, float> uniform,
float v0,
float v1,
float v2,
float v3 )
{
Context.glUniform4f(uniform.id.SignedValue, v0, v1, v2, v3);
Context.glUniform4f( uniform.id.SignedValue, v0, v1, v2, v3 );
}
}
}