@@ -125,7 +125,7 @@ public class WebGLContext : RenderingContext
125
125
public int DrawingBufferHeight { get ; private set ; }
126
126
#endregion
127
127
128
- public WebGLContext ( BECanvasComponent reference , WebGLContextAttributes attributes = null ) : base ( reference , CONTEXT_NAME , attributes )
128
+ public WebGLContext ( BECanvasComponent reference , WebGLContextAttributes attributes = null , string contextName = CONTEXT_NAME ) : base ( reference , contextName , attributes )
129
129
{
130
130
}
131
131
@@ -289,12 +289,12 @@ protected override async Task ExtendedInitializeAsync()
289
289
public async Task BufferDataAsync ( BufferType target , int size , BufferUsageHint usage ) => await this . BatchCallAsync ( BUFFER_DATA , isMethodCall : true , target , size , usage ) ;
290
290
291
291
[ Obsolete ( "Use the async version instead, which is already called internally." ) ]
292
- public void BufferData < T > ( BufferType target , T [ ] data , BufferUsageHint usage ) => this . CallMethod < object > ( BUFFER_DATA , target , this . ConvertToByteArray ( data ) , usage ) ;
293
- public async Task BufferDataAsync < T > ( BufferType target , T [ ] data , BufferUsageHint usage ) => await this . BatchCallAsync ( BUFFER_DATA , isMethodCall : true , target , this . ConvertToByteArray ( data ) , usage ) ;
292
+ public void BufferData < T > ( BufferType target , T [ ] data , BufferUsageHint usage ) where T : unmanaged => this . CallMethod < object > ( BUFFER_DATA , target , this . ConvertToByteArray ( data ) , usage ) ;
293
+ public async Task BufferDataAsync < T > ( BufferType target , T [ ] data , BufferUsageHint usage ) where T : unmanaged => await this . BatchCallAsync ( BUFFER_DATA , isMethodCall : true , target , this . ConvertToByteArray ( data ) , usage ) ;
294
294
295
295
[ Obsolete ( "Use the async version instead, which is already called internally." ) ]
296
- public void BufferSubData < T > ( BufferType target , uint offset , T [ ] data ) => this . CallMethod < object > ( BUFFER_SUB_DATA , target , offset , this . ConvertToByteArray ( data ) ) ;
297
- public async Task BufferSubDataAsync < T > ( BufferType target , uint offset , T [ ] data ) => await this . BatchCallAsync ( BUFFER_SUB_DATA , isMethodCall : true , target , offset , this . ConvertToByteArray ( data ) ) ;
296
+ public void BufferSubData < T > ( BufferType target , uint offset , T [ ] data ) where T : unmanaged => this . CallMethod < object > ( BUFFER_SUB_DATA , target , offset , this . ConvertToByteArray ( data ) ) ;
297
+ public async Task BufferSubDataAsync < T > ( BufferType target , uint offset , T [ ] data ) where T : unmanaged => await this . BatchCallAsync ( BUFFER_SUB_DATA , isMethodCall : true , target , offset , this . ConvertToByteArray ( data ) ) ;
298
298
299
299
[ Obsolete ( "Use the async version instead, which is already called internally." ) ]
300
300
public WebGLBuffer CreateBuffer ( ) => this . CallMethod < WebGLBuffer > ( CREATE_BUFFER ) ;
@@ -410,7 +410,7 @@ public void TexImage2D<T>(Texture2DType target, int level, PixelFormat internalF
410
410
=> this . CallMethod < object > ( TEX_IMAGE_2D , target , level , internalFormat , width , height , format , type , pixels ) ;
411
411
public async Task TexImage2DAsync < T > ( Texture2DType target , int level , PixelFormat internalFormat , int width , int height , PixelFormat format , PixelType type , T [ ] pixels )
412
412
where T : struct
413
- => await this . BatchCallAsync ( TEX_IMAGE_2D , isMethodCall : true , target , level , internalFormat , width , height , format , type , pixels ) ;
413
+ => await this . BatchCallAsync ( TEX_IMAGE_2D , isMethodCall : true , target , level , internalFormat , width , height , 0 , format , type , pixels ) ;
414
414
415
415
[ Obsolete ( "Use the async version instead, which is already called internally." ) ]
416
416
public void TexSubImage2D < T > ( Texture2DType target , int level , int xoffset , int yoffset , int width , int height , PixelFormat format , PixelType type , T [ ] pixels )
@@ -730,10 +730,18 @@ public async Task VertexAttribAsync(uint index, params float[] value)
730
730
public void Flush ( ) => this . CallMethod < object > ( FLUSH ) ;
731
731
public async Task FlushAsync ( ) => await this . BatchCallAsync ( FLUSH , isMethodCall : true ) ;
732
732
733
- private byte [ ] ConvertToByteArray < T > ( T [ ] arr )
733
+ private byte [ ] ConvertToByteArray < T > ( T [ ] arr ) where T : unmanaged
734
734
{
735
735
byte [ ] byteArr = new byte [ arr . Length * Marshal . SizeOf < T > ( ) ] ;
736
- Buffer . BlockCopy ( arr , 0 , byteArr , 0 , byteArr . Length ) ;
736
+ var handle = GCHandle . Alloc ( arr , GCHandleType . Pinned ) ;
737
+ try
738
+ {
739
+ Marshal . Copy ( handle . AddrOfPinnedObject ( ) , byteArr , 0 , byteArr . Length ) ;
740
+ }
741
+ finally
742
+ {
743
+ handle . Free ( ) ;
744
+ }
737
745
return byteArr ;
738
746
}
739
747
private async Task < int > GetDrawingBufferWidthAsync ( ) => await this . GetPropertyAsync < int > ( DRAWING_BUFFER_WIDTH ) ;
0 commit comments