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:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user