Daily update on 20250430-073804 by Nitload Youmu. Additional Message : full function of syntax analyze to STEP file

Signed-off-by: Nitload <YoumuLiu_NSI@whv0t.onmicrosoft.com>
This commit is contained in:
Nitload
2025-04-30 07:38:04 +08:00
parent a6411e2f25
commit 74c01effe4
52 changed files with 693 additions and 442 deletions
@@ -45,9 +45,11 @@ 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>
/// <returns>
/// New instance of <see cref="Shader" /> instance.
/// </returns>
[MethodImpl( MethodImplOptions.AggressiveInlining )]
protected override sealed ShaderProgram CreateShaderProgram()
{
@@ -55,9 +57,7 @@ namespace StgSharp.Graphics.OpenGL
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
protected override sealed Shader CreateShaderSegment(
ShaderType type,
int count )
protected override sealed Shader CreateShaderSegment( ShaderType type, int count )
{
return new Shader( GL.CreateShaderSet( count, type ), type, this );
}
@@ -71,10 +71,7 @@ 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;
@@ -84,10 +81,14 @@ namespace StgSharp.Graphics.OpenGL
public SerializableTypeCode SSDTypeCode => SerializableTypeCode.Shader;
/// <summary>
/// Attach one shader code to a shader program.
/// 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>
/// <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 )
{
@@ -98,16 +99,22 @@ namespace StgSharp.Graphics.OpenGL
{
string log = GL.GetShaderStatus( this, index, ( int )status );
if( !string.IsNullOrEmpty( log ) ) {
throw new Exception( $"{$"Shader Error \t{status}\n"}{log}" );
throw new InvalidOperationException( $"{$"Shader Error \t{status}\n"}{log}" );
}
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public unsafe void Compile( int index, ReadOnlySpan<byte> codeU8Stream )
{
GL.LoadShaderSource( handle[ index ], codeU8Stream );
GL.CompileShader( handle[ index ] );
CheckStatus( index, ShaderStatus.CompileStatus );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public unsafe void Compile( int index, byte[] codeStream )
{
if( codeStream == null ) {
throw new ArgumentNullException( nameof( codeStream ) );
}
ArgumentNullException.ThrowIfNull( codeStream );
GL.LoadShaderSource( handle[ index ], codeStream );
GL.CompileShader( handle[ index ] );
CheckStatus( index, ShaderStatus.CompileStatus );
@@ -119,8 +126,7 @@ namespace StgSharp.Graphics.OpenGL
if( codeStream == null ) {
throw new ArgumentNullException( nameof( codeStream ) );
}
GL.LoadShaderSource(
handle[ index ], codeStream.AsSpan() );
GL.LoadShaderSource( handle[ index ], codeStream.AsSpan() );
GL.CompileShader( handle[ index ] );
CheckStatus( index, ShaderStatus.CompileStatus );
}
@@ -134,8 +140,7 @@ namespace StgSharp.Graphics.OpenGL
{
string str = File.ReadAllText( fileRoute );
if( string.IsNullOrEmpty( str ) ) {
throw new InvalidOperationException(
$"Cannot load and GLSL code from {fileRoute}" );
throw new InvalidOperationException( $"Cannot load and GLSL code from {fileRoute}" );
}
return Encoding.UTF8.GetBytes( str );
}
@@ -171,7 +176,7 @@ namespace StgSharp.Graphics.OpenGL
internal readonly GlHandle handle;
/// <summary>
/// CustomizeInit a program with no shader attached.
/// CustomizeInit a program with no shader attached.
/// </summary>
internal unsafe ShaderProgram( glRender binding )
{
@@ -180,10 +185,14 @@ namespace StgSharp.Graphics.OpenGL
}
/// <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>
/// <returns></returns>
/// <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
{
@@ -191,70 +200,79 @@ namespace StgSharp.Graphics.OpenGL
}
/// <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>
/// <returns></returns>
public unsafe Uniform<T, U> GetUniform<T, U>( string name )
where T: struct
where U: struct
/// <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
{
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>
/// <returns></returns>
public unsafe Uniform<T, U, V> GetUniform<T, U, V>( string name )
where T: struct
/// <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
{
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>
/// <returns></returns>
public unsafe Uniform<T, U, V, W> GetUniform<T, U, V, W>( string name )
where T: struct
/// <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
{
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>
/// Link the shader to current viewPortDisplay.
/// Link the shader to current viewPortDisplay.
/// </summary>
public unsafe void Link()
{
if( InternalIO.InternalLinkShaderProgram(
( OpenglContext* )this.GL.ContextHandle, handle.Value ) == 0 ) {
( 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 );
}
catch( Exception ex ) {
catch( Exception ex )
{
InternalIO.InternalWriteLog( ex.Message, LogType.Error );
}
}
}
/// <summary>
/// Let the current viewPortDisplay use this shader.
/// Let the current viewPortDisplay use this shader.
/// </summary>
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public unsafe void Use()
+176 -177
View File
@@ -50,8 +50,7 @@ namespace StgSharp.Graphics.OpenGL
private static Dictionary<IntPtr, OpenGLFunction> contextToGLMap = new Dictionary<IntPtr, OpenGLFunction>(
);
private static ThreadLocal<OpenGLFunction> _currentGL = new ThreadLocal<OpenGLFunction>(
);
private static ThreadLocal<OpenGLFunction> _currentGL = new ThreadLocal<OpenGLFunction>();
private OpenglContext* _context;
private Lazy<int> _attachmentColorRange;
@@ -64,8 +63,7 @@ namespace StgSharp.Graphics.OpenGL
InitializeUnusedTextureImageUint );
_attachmentColorRange = new Lazy<int>(
() => {
return GetMaskInteger(
( uint )glConst.MAX_COLOR_ATTACHMENTS );
return GetMaskInteger( ( uint )glConst.MAX_COLOR_ATTACHMENTS );
} );
}
@@ -87,7 +85,8 @@ namespace StgSharp.Graphics.OpenGL
get
{
#if DEBUG
if( ( IntPtr )_context == IntPtr.Zero ) {
if( ( IntPtr )_context == IntPtr.Zero )
{
throw new NullReferenceException();
}
#endif
@@ -126,11 +125,15 @@ namespace StgSharp.Graphics.OpenGL
}
/// <summary>
/// Bind a frame Buffer to a frame Buffer target Same function as <see
/// href="https://docs._gl/gl3/glBindFramebuffer">glBindFramebuffer</see>.
/// Bind a frame Buffer to a frame Buffer target Same function as <see
/// href="https://docs._gl/gl3/glBindFramebuffer"> glBindFramebuffer </see>.
/// </summary>
/// <param _name="target"> The frame Buffer target of the binding operation. </param>
/// <param _name="handle"> The handle of the frame Buffer object to bind. </param>
/// <param _name="target">
/// The frame Buffer target of the binding operation.
/// </param>
/// <param _name="handle">
/// The handle of the frame Buffer object to bind.
/// </param>
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public void BindFrameBuffer( FrameBufferTarget target, GlHandle handle )
{
@@ -156,11 +159,9 @@ namespace StgSharp.Graphics.OpenGL
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public FrameBufferStatus CheckFrameBufferStatus(
FrameBufferTarget target )
public FrameBufferStatus CheckFrameBufferStatus( FrameBufferTarget target )
{
return ( FrameBufferStatus )Context.glCheckFramebufferStatus(
( uint )target );
return ( FrameBufferStatus )Context.glCheckFramebufferStatus( ( uint )target );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
@@ -179,7 +180,8 @@ namespace StgSharp.Graphics.OpenGL
public void ClearError()
{
uint code = 0;
for( int i = 0; i < 1024; i++ ) {
for( int i = 0; i < 1024; i++ )
{
code = Context.glGetError();
if( code == 0 ) {
return;
@@ -201,12 +203,11 @@ namespace StgSharp.Graphics.OpenGL
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public void CombineFrameBufferRenderBuffer(
FrameBufferAttachment attachment,
GlHandle rboHandle )
FrameBufferAttachment attachment,
GlHandle rboHandle )
{
Context.glFramebufferRenderbuffer(
glConst.FRAMEBUFFER, ( uint )attachment, glConst.RENDERBUFFER,
rboHandle.Value );
glConst.FRAMEBUFFER, ( uint )attachment, glConst.RENDERBUFFER, rboHandle.Value );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
@@ -242,12 +243,13 @@ namespace StgSharp.Graphics.OpenGL
{
GlHandle[] ret = new GlHandle[count];
uint t = ( uint )type;
for( int i = 0; i < count; i++ ) {
for( int i = 0; i < count; i++ )
{
uint id = Context.glCreateShader( t );
if( id == 0 ) {
if( id == 0 )
{
uint error = Context.glGetError();
throw new InvalidOperationException(
$"Failed in creating shader: {error}" );
throw new InvalidOperationException( $"Failed in creating shader: {error}" );
}
ret[ i ] = GlHandle.Alloc( id );
}
@@ -266,7 +268,8 @@ namespace StgSharp.Graphics.OpenGL
if( ( handle == null ) || ( handle.Length == 0 ) ) {
throw new ArgumentNullException( nameof( handle ) );
}
fixed( GlHandle* hptr = handle ) {
fixed( GlHandle* hptr = handle )
{
uint* iptr = ( uint* )hptr;
for( int i = 0; i < handle.Length; i++ ) {
Context.glDeleteBuffers( 1, iptr + i );
@@ -275,11 +278,14 @@ namespace StgSharp.Graphics.OpenGL
}
/// <summary>
/// Delete a render Buffer object Very simlilar function as <see
/// href="https://docs.gl/gl3/glDeleteRenderbuffers">glDeleteRenderbuffers</see>. The only
/// deifference is that this mehtod can only delete one renderbuffer at the same time.
/// Delete a render Buffer object Very simlilar function as <see
/// href="https://docs.gl/gl3/glDeleteRenderbuffers"> glDeleteRenderbuffers </see>. The
/// only deifference is that this mehtod can only delete one renderbuffer at the same
/// time.
/// </summary>
/// <param _name="bufferHandle"> Handle to Buffer to delete. </param>
/// <param _name="bufferHandle">
/// Handle to Buffer to delete.
/// </param>
public unsafe void DeleteRenderBuffer( GlHandle bufferHandle )
{
Context.glDeleteRenderbuffers( 1, &bufferHandle.Value );
@@ -288,7 +294,8 @@ namespace StgSharp.Graphics.OpenGL
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public unsafe void DeleteVertexArrays( GlHandle[] arrays )
{
fixed( GlHandle* hptr = arrays ) {
fixed( GlHandle* hptr = arrays )
{
uint* iptr = ( uint* )hptr;
for( int i = 0; i < arrays.Length; i++ ) {
Context.glDeleteVertexArrays( 1, iptr + i );
@@ -297,11 +304,7 @@ namespace StgSharp.Graphics.OpenGL
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public unsafe void DrawElements(
GeometryType mode,
uint count,
TypeCode type,
IntPtr ptr )
public unsafe void DrawElements( GeometryType mode, uint count, TypeCode type, IntPtr ptr )
{
uint a;
a = type switch
@@ -317,14 +320,15 @@ namespace StgSharp.Graphics.OpenGL
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public void DrawElementsInstanced(
GeometryType mode,
uint count,
TypeCode type,
IntPtr ptr,
uint amount )
GeometryType mode,
uint count,
TypeCode type,
IntPtr ptr,
uint amount )
{
uint a;
switch( type ) {
switch( type )
{
case TypeCode.UInt32:
a = glConst.UNSIGNED_INT;
break;
@@ -343,8 +347,7 @@ namespace StgSharp.Graphics.OpenGL
LogType.Error );
return;
}
Context.glDrawElementsInstanced(
( uint )mode, count, a, ( void* )ptr, amount );
Context.glDrawElementsInstanced( ( uint )mode, count, a, ( void* )ptr, amount );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
@@ -355,22 +358,22 @@ namespace StgSharp.Graphics.OpenGL
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public void FrameBufferTexture2d(
FrameBufferTarget target,
uint attachment,
Texture2DTarget texTarget,
GlHandle textureHandle,
int level )
FrameBufferTarget target,
uint attachment,
Texture2DTarget texTarget,
GlHandle textureHandle,
int level )
{
Context.glFramebufferTexture2D(
( uint )target, attachment, ( uint )texTarget,
textureHandle.Value, level );
( uint )target, attachment, ( uint )texTarget, textureHandle.Value, level );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public unsafe GlHandle[] GenBuffers( int count )
{
GlHandle[] h = new GlHandle[count];
fixed( GlHandle* hptr = h ) {
fixed( GlHandle* hptr = h )
{
for( int i = 0; i < count; i++ ) {
Context.glGenBuffers( count, ( ( uint* )hptr ) + i );
}
@@ -448,51 +451,48 @@ namespace StgSharp.Graphics.OpenGL
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public unsafe void GetTextureImage<T>(
Texture2DTarget target,
int level,
ImageChannel channel,
PixelChannelLayout channelLayout,
T[] dataStream )
Texture2DTarget target,
int level,
ImageChannel channel,
PixelChannelLayout channelLayout,
T[] dataStream )
where T: struct,INumber<T>
{
#pragma warning disable CS8500
fixed( T* tptr = dataStream ) {
fixed( T* tptr = dataStream )
{
Context.glGetTexImage(
( uint )target, level, ( uint )channel,
( uint )channelLayout, tptr );
( uint )target, level, ( uint )channel, ( uint )channelLayout, tptr );
}
#pragma warning restore CS8500
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public void GetTextureLevelProperty(
uint textureTypeMask,
int level,
uint propertyMask,
out int propertyValue )
uint textureTypeMask,
int level,
uint propertyMask,
out int propertyValue )
{
fixed( int* iptr = &propertyValue ) {
Context.glGetTexLevelParameteriv(
textureTypeMask, level, propertyMask, iptr );
Context.glGetTexLevelParameteriv( textureTypeMask, level, propertyMask, iptr );
}
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public unsafe GlHandle GetUniformLocation(
GlHandle program,
string name )
public unsafe GlHandle GetUniformLocation( GlHandle program, string name )
{
byte[] code = Encoding.UTF8.GetBytes( name );
fixed( byte* ptr = code ) {
fixed( byte* ptr = code )
{
int ret = Context.glGetUniformLocation( program.Value, ptr );
#if DEBUG
if( ( ret == glConst.INVALID_OPERATION ) || ( ret ==
glConst.INVALID_VALUE ) ) {
if( ( ret == glConst.INVALID_OPERATION ) || ( ret == glConst.INVALID_VALUE ) )
{
throw new InvalidOperationException();
}
if( ret == -1 ) {
throw new UniformEmptyReferenceException(
nameof( program ), name );
throw new UniformEmptyReferenceException( nameof( program ), name );
}
#endif
return GlHandle.SignedAlloc( ret );
@@ -500,47 +500,51 @@ namespace StgSharp.Graphics.OpenGL
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public unsafe void LoadShaderSource(
GlHandle shaderHandle,
byte[] codeStream )
public unsafe void LoadShaderSource( GlHandle shaderHandle, byte[] codeStream )
{
fixed( byte* streamPtr = codeStream ) {
Context.glShaderSource(
shaderHandle.Value, 1, &streamPtr, ( void* )0 );
Context.glShaderSource( shaderHandle.Value, 1, &streamPtr, ( void* )0 );
}
}
public unsafe void LoadShaderSource(
GlHandle shaderHandle,
ReadOnlySpan<char> codeStream )
public unsafe void LoadShaderSource( GlHandle shaderHandle, ReadOnlySpan<char> codeStream )
{
fixed( char* streamPtr = codeStream ) {
fixed( char* streamPtr = codeStream )
{
byte* bptr = ( byte* )streamPtr;
Context.glShaderSource(
shaderHandle.Value, 1, &bptr, ( void* )0 );
Context.glShaderSource( shaderHandle.Value, 1, &bptr, ( void* )0 );
}
}
public unsafe void LoadShaderSource( GlHandle shaderHandle, ReadOnlySpan<byte> codeStream )
{
fixed( byte* streamPtr = codeStream )
{
byte* bptr = streamPtr;
Context.glShaderSource( shaderHandle.Value, 1, &bptr, ( void* )0 );
}
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public void ReadPixels(
(int X, int Y) beginPosition,
(int width, int height) size,
FrameBufferChannel format,
PixelChannelLayout dataType,
ref byte[] stream )
(int X, int Y) beginPosition,
(int width, int height) size,
FrameBufferChannel format,
PixelChannelLayout dataType,
ref byte[] stream )
{
fixed( byte* bptr = stream ) {
Context.glReadPixels(
beginPosition.X, beginPosition.Y, size.width, size.height,
( uint )format, ( uint )dataType, bptr );
beginPosition.X, beginPosition.Y, size.width, size.height, ( uint )format,
( uint )dataType, bptr );
}
}
public void RereadImage(
in Image i,
(int X, int Y) beginPosition,
FrameBufferChannel format,
PixelChannelLayout dataType )
in Image i,
(int X, int Y) beginPosition,
FrameBufferChannel format,
PixelChannelLayout dataType )
{
byte[] pixels = i.PixelBuffer;
if( !pixels.CheckArrayFormat( dataType ) ) {
@@ -548,33 +552,31 @@ namespace StgSharp.Graphics.OpenGL
}
fixed( byte* bptr = pixels ) {
Context.glReadPixels(
beginPosition.X, beginPosition.Y, i.Width, i.Height,
( uint )format, ( uint )dataType, bptr );
beginPosition.X, beginPosition.Y, i.Width, i.Height, ( uint )format,
( uint )dataType, bptr );
}
i.PixelUpdateCount++;
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public unsafe void SetBufferData<T>(
BufferType bufferType,
T bufferData,
BufferUsage usage )
BufferType bufferType,
T bufferData,
BufferUsage usage )
where T: struct
{
int size = Marshal.SizeOf<T>();
#pragma warning disable CS8500
T* p = &bufferData;
#pragma warning restore CS8500
Context.glBufferData(
( uint )bufferType, ( IntPtr )size, ( IntPtr )p,
( uint )usage );
Context.glBufferData( ( uint )bufferType, ( IntPtr )size, ( IntPtr )p, ( uint )usage );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public unsafe void SetBufferData<T>(
BufferType bufferType,
T[] bufferArray,
BufferUsage usage )
BufferType bufferType,
T[] bufferArray,
BufferUsage usage )
where T: struct,INumber<T>
{
int size = bufferArray.Length * Marshal.SizeOf( typeof( T ) );
@@ -583,19 +585,18 @@ namespace StgSharp.Graphics.OpenGL
}
#pragma warning disable CS8500
fixed( void* bufferPtr = bufferArray )
#pragma warning restore CS8500
{
#pragma warning restore CS8500
{
Context.glBufferData(
( uint )bufferType, ( IntPtr )size, ( IntPtr )bufferPtr,
( uint )usage );
( uint )bufferType, ( IntPtr )size, ( IntPtr )bufferPtr, ( uint )usage );
}
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public unsafe void SetBufferData<T>(
BufferType bufferType,
ReadOnlySpan<T> bufferArray,
BufferUsage usage )
BufferType bufferType,
ReadOnlySpan<T> bufferArray,
BufferUsage usage )
where T: struct,INumber<T>
{
int size = bufferArray.Length * Marshal.SizeOf( typeof( T ) );
@@ -604,19 +605,18 @@ namespace StgSharp.Graphics.OpenGL
}
#pragma warning disable CS8500
fixed( void* bufferPtr = bufferArray )
#pragma warning restore CS8500
{
#pragma warning restore CS8500
{
Context.glBufferData(
( uint )bufferType, ( IntPtr )size, ( IntPtr )bufferPtr,
( uint )usage );
( uint )bufferType, ( IntPtr )size, ( IntPtr )bufferPtr, ( uint )usage );
}
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public unsafe void SetBufferData<T>(
BufferType bufferType,
Span<T> bufferArray,
BufferUsage usage )
BufferType bufferType,
Span<T> bufferArray,
BufferUsage usage )
where T: struct, INumber<T>
{
int size = bufferArray.Length * Marshal.SizeOf( typeof( T ) );
@@ -626,19 +626,18 @@ namespace StgSharp.Graphics.OpenGL
#pragma warning disable CS8500
fixed( void* bufferPtr = &bufferArray.GetPinnableReference() )
#pragma warning restore CS8500
{
#pragma warning restore CS8500
{
Context.glBufferData(
( uint )bufferType, ( IntPtr )size, ( IntPtr )bufferPtr,
( uint )usage );
( uint )bufferType, ( IntPtr )size, ( IntPtr )bufferPtr, ( uint )usage );
}
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public unsafe void SetBufferVectorData<T>(
BufferType bufferType,
ReadOnlySpan<T> bufferArray,
BufferUsage usage )
BufferType bufferType,
ReadOnlySpan<T> bufferArray,
BufferUsage usage )
where T: struct, IVector<T>
{
int size = bufferArray.Length * Marshal.SizeOf( typeof( T ) );
@@ -647,19 +646,18 @@ namespace StgSharp.Graphics.OpenGL
}
#pragma warning disable CS8500
fixed( void* bufferPtr = &bufferArray.GetPinnableReference() )
#pragma warning restore CS8500
{
#pragma warning restore CS8500
{
Context.glBufferData(
( uint )bufferType, ( IntPtr )size, ( IntPtr )bufferPtr,
( uint )usage );
( uint )bufferType, ( IntPtr )size, ( IntPtr )bufferPtr, ( uint )usage );
}
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public unsafe void SetBufferVectorData<T>(
BufferType bufferType,
T[] bufferArray,
BufferUsage usage )
BufferType bufferType,
T[] bufferArray,
BufferUsage usage )
where T: struct, IVector<T>
{
int size = bufferArray.Length * Marshal.SizeOf( typeof( T ) );
@@ -668,28 +666,26 @@ namespace StgSharp.Graphics.OpenGL
}
#pragma warning disable CS8500
fixed( void* bufferPtr = bufferArray )
#pragma warning restore CS8500
{
#pragma warning restore CS8500
{
Context.glBufferData(
( uint )bufferType, ( IntPtr )size, ( IntPtr )bufferPtr,
( uint )usage );
( uint )bufferType, ( IntPtr )size, ( IntPtr )bufferPtr, ( uint )usage );
}
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public unsafe void SetRenderBufferStorage(
RenderBufferInternalFormat internalFormat,
(int width, int height) size )
RenderBufferInternalFormat internalFormat,
(int width, int height) size )
{
Context.glRenderbufferStorage(
glConst.RENDERBUFFER, ( uint )internalFormat, size.width,
size.height );
glConst.RENDERBUFFER, ( uint )internalFormat, size.width, size.height );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public unsafe void SetRenderBufferStorage(
RenderBufferInternalFormat internalFormat,
(uint width, uint height) size )
RenderBufferInternalFormat internalFormat,
(uint width, uint height) size )
{
Context.glRenderbufferStorage(
glConst.RENDERBUFFER, ( uint )internalFormat, ( int )size.width,
@@ -698,60 +694,60 @@ namespace StgSharp.Graphics.OpenGL
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public void SetVertexAttribute(
uint index,
int size,
TypeCode t,
bool normalized,
uint stride,
int pointer )
uint index,
int size,
TypeCode t,
bool normalized,
uint stride,
int pointer )
{
uint type = InternalIO.GLtype[ t ];
Context.glVertexAttribPointer(
index, size, type, normalized ? 1 : 0, stride,
( void* )pointer );
index, size, type, normalized ? 1 : 0, stride, ( void* )pointer );
Context.glEnableVertexAttribArray( index );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public void TextureImage2d<T>(
Texture2DTarget target,
int level,
ImageChannel sourceChannel,
uint width,
uint height,
ImageChannel targetChannel,
PixelChannelLayout type,
T[] pixels )
Texture2DTarget target,
int level,
ImageChannel sourceChannel,
uint width,
uint height,
ImageChannel targetChannel,
PixelChannelLayout type,
T[] pixels )
where T: struct, INumber<T>
{
#pragma warning disable CS8500
fixed( T* tptr = pixels ) {
T* ptr = ( ( pixels == null ) || ( pixels.Length == 0 ) ) ?
( T* )IntPtr.Zero : tptr;
fixed( T* tptr = pixels )
{
T* ptr = ( ( pixels == null ) || ( pixels.Length == 0 ) ) ? ( T* )IntPtr.Zero : tptr;
Context.glTexImage2D(
( uint )target, level, ( uint )sourceChannel, width, height,
0, ( uint )targetChannel, ( uint )type, tptr );
( uint )target, level, ( uint )sourceChannel, width, height, 0,
( uint )targetChannel, ( uint )type, tptr );
}
#pragma warning restore CS8500
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public void TextureImage2d<T>(
Texture2DTarget target,
int level,
ImageChannel sourceChannel,
uint width,
uint height,
ImageChannel targetChannel,
PixelChannelLayout type,
Span<T> pixelSpan )
Texture2DTarget target,
int level,
ImageChannel sourceChannel,
uint width,
uint height,
ImageChannel targetChannel,
PixelChannelLayout type,
Span<T> pixelSpan )
where T: struct, INumber<T>
{
#pragma warning disable CS8500
fixed( T* tptr = pixelSpan ) {
fixed( T* tptr = pixelSpan )
{
Context.glTexImage2D(
( uint )target, level, ( uint )sourceChannel, width, height,
0, ( uint )targetChannel, ( uint )type, tptr );
( uint )target, level, ( uint )sourceChannel, width, height, 0,
( uint )targetChannel, ( uint )type, tptr );
}
#pragma warning restore CS8500
}
@@ -763,8 +759,8 @@ namespace StgSharp.Graphics.OpenGL
}
public static bool TryGetFunctionPackage(
IntPtr handle,
out OpenGLFunction functionPackage )
IntPtr handle,
out OpenGLFunction functionPackage )
{
return contextToGLMap.TryGetValue( handle, out functionPackage );
}
@@ -798,7 +794,10 @@ namespace StgSharp.Graphics.OpenGL
if( contextToGLMap.TryGetValue( handle, out pack ) ) {
return pack;
}
pack = new OpenGLFunction { _context = ( OpenglContext* )handle };
pack = new OpenGLFunction
{
_context = ( OpenglContext* )handle
};
contextToGLMap.Add( handle, pack );
return pack;
}