This repository was archived by the owner on Feb 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
This repository was archived by the owner on Feb 14, 2022. It is now read-only.
TextImage methods only supports ReadOnlySpan<byte> #11
Copy link
Copy link
Open
Labels
enhancementNew feature or requestNew feature or request
Description
The provided methods to set image data only supports ReadOnlySpan as parameter.
Would be nice to implements more overloads or a generic method.
At this moment in WaveEngine we have implemented a converter to use the overload that receive a ITypedArray, but will be nice that this conversion is done by the WebGL.Backend and we work with ReadOnlySpan<byte|sbyte|...>.
This is the code of our converter:
private static unsafe ITypedArray GetData(uint pixelType, void* data, uint sourceSizeInBytes)
{
// https://www.khronos.org/registry/webgl/specs/latest/2.0/ under 'void texImage2D' section
WebAssembly.Core.ITypedArray array;
switch (pixelType)
{
case GLConstants.ColorPointerTypeByte:
array = WebAssembly.Core.Int8Array.From(new ReadOnlySpan<sbyte>(data, (int)sourceSizeInBytes));
break;
case GLConstants.ColorPointerTypeUnsignedByte:
array = WebAssembly.Core.Uint8Array.From(new ReadOnlySpan<byte>(data, (int)sourceSizeInBytes));
break;
case GLConstants.ColorPointerTypeShort:
array = WebAssembly.Core.Int16Array.From(new ReadOnlySpan<short>(data, (int)sourceSizeInBytes));
break;
case GLConstants.ColorPointerTypeUnsignedShort:
case GLConstants.ExtensionsUnsignedShort565:
case GLConstants.PixelTypeUnsignedShort5551:
case GLConstants.PixelTypeUnsignedShort4444:
array = WebAssembly.Core.Uint16Array.From(new ReadOnlySpan<ushort>(data, (int)sourceSizeInBytes));
break;
case GLConstants.ColorPointerTypeInt:
array = WebAssembly.Core.Int32Array.From(new ReadOnlySpan<int>(data, (int)sourceSizeInBytes));
break;
case GLConstants.ColorPointerTypeUnsignedInt:
case GLConstants.ExtensionsUnsignedInt5999Rev:
case GLConstants.VertexAttribTypeUnsignedInt2101010Rev:
case GLConstants.VertexAttribPointerTypeUnsignedInt10f11f11fRev:
case GLConstants.ExtensionsUnsignedInt248:
array = WebAssembly.Core.Uint32Array.From(new ReadOnlySpan<uint>(data, (int)sourceSizeInBytes));
break;
case GLConstants.VertexAttribPointerTypeHalfFloat:
array = WebAssembly.Core.Uint16Array.From(new ReadOnlySpan<ushort>(data, (int)sourceSizeInBytes));
break;
case GLConstants.VertexAttribPointerTypeFloat:
array = WebAssembly.Core.Float32Array.From(new ReadOnlySpan<float>(data, (int)sourceSizeInBytes));
break;
default:
array = WebAssembly.Core.Uint8Array.From(new ReadOnlySpan<byte>(data, (int)sourceSizeInBytes));
break;
}
return array;
}
Thanks!
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request