Watch
2
0
Fork
You've already forked raylib-cs
0

Yet more string changes

- Use sbyte/byte correctly in Raylib.cs
- Using Marshal.StringToCoTaskMemUTF8
- Update utils string usage
This commit is contained in:
Rgebee 2022-01-12 20:12:55 +00:00
commit 8ecc4bded9
3 changed files with 278 additions and 182 deletions

View file

@ -9,21 +9,15 @@ namespace Raylib_cs
/// <summary>Initialize window and OpenGL context</summary> /// <summary>Initialize window and OpenGL context</summary>
public static void InitWindow(int width, int height, string title) public static void InitWindow(int width, int height, string title)
{ {
using var str = new UTF8Buffer(title); using var str1 = title.ToUTF8Buffer();
fixed (byte* b = str.buffer) InitWindow(width, height, str1.AsPointer());
{
InitWindow(width, height, b);
}
} }
/// <summary>Set title for window (only PLATFORM_DESKTOP)</summary> /// <summary>Set title for window (only PLATFORM_DESKTOP)</summary>
public static void SetWindowTitle(string title) public static void SetWindowTitle(string title)
{ {
using var str = new UTF8Buffer(title); using var str1 = title.ToUTF8Buffer();
fixed (byte* b = str.buffer) SetWindowTitle(str1.AsPointer());
{
SetWindowTitle(b);
}
} }
/// <summary>Get the human-readable, UTF-8 encoded name of the primary monitor</summary> /// <summary>Get the human-readable, UTF-8 encoded name of the primary monitor</summary>
@ -41,13 +35,101 @@ namespace Raylib_cs
/// <summary>Set clipboard text content</summary> /// <summary>Set clipboard text content</summary>
public static void SetClipboardText(string text) public static void SetClipboardText(string text)
{ {
using var str = new UTF8Buffer(text); using var str1 = text.ToUTF8Buffer();
fixed (byte* b = str.buffer) SetClipboardText(str1.AsPointer());
}
/// <summary>Load shader from files and bind default locations</summary>
public static Shader LoadShader(string vsFileName, string fsFileName)
{
using var str1 = vsFileName.ToUTF8Buffer();
using var str2 = fsFileName.ToUTF8Buffer();
return LoadShader(str1.AsPointer(), str2.AsPointer());
}
/// <summary>Load shader from code string and bind default locations</summary>
public static Shader LoadShaderFromMemory(string vsCode, string fsCode)
{
using var str1 = vsCode.ToUTF8Buffer();
using var str2 = fsCode.ToUTF8Buffer();
return LoadShaderFromMemory(str1.AsPointer(), str2.AsPointer());
}
/// <summary>Get shader uniform location</summary>
public static int GetShaderLocation(Shader shader, string uniformName)
{
using var str1 = uniformName.ToUTF8Buffer();
return GetShaderLocation(shader, str1.AsPointer());
}
/// <summary>Get shader attribute location</summary>
public static int GetShaderLocationAttrib(Shader shader, string attribName)
{
using var str1 = attribName.ToUTF8Buffer();
return GetShaderLocation(shader, str1.AsPointer());
}
/// <summary>Takes a screenshot of current screen (saved a .png)</summary>
public static void TakeScreenshot(string fileName)
{
using var str1 = fileName.ToUTF8Buffer();
TakeScreenshot(str1.AsPointer());
}
/// <summary>Check file extension</summary>
public static CBool IsFileExtension(string fileName, string ext)
{
using var str1 = fileName.ToUTF8Buffer();
using var str2 = ext.ToUTF8Buffer();
return IsFileExtension(str1.AsPointer(), str2.AsPointer());
}
/// <summary>Get file modification time (last write time)</summary>
public static long GetFileModTime(string fileName)
{
using var str1 = fileName.ToUTF8Buffer();
return GetFileModTime(str1.AsPointer());
}
/// <summary>Load image from file into CPU memory (RAM)</summary>
public static Image LoadImage(string fileName)
{
using var str1 = fileName.ToUTF8Buffer();
return LoadImage(str1.AsPointer());
}
/// <summary>Load image from RAW file data</summary>
public static Image LoadImageRaw(string fileName, int width, int height, PixelFormat format, int headerSize)
{
using var str1 = fileName.ToUTF8Buffer();
return LoadImageRaw(str1.AsPointer(), width, height, format, headerSize);
}
/// <summary>Load image sequence from file (frames appended to image.data)</summary>
public static Image LoadImageAnim(string fileName, int[] frames)
{
using var str1 = fileName.ToUTF8Buffer();
fixed (int* p = frames)
{ {
SetClipboardText(b); return LoadImageAnim(str1.AsPointer(), p);
} }
} }
/// <summary>Export image data to file</summary>
public static void ExportImage(Image image, string fileName)
{
using var str1 = fileName.ToUTF8Buffer();
ExportImage(image, str1.AsPointer());
}
/// <summary>Show trace log messages (LOG_DEBUG, LOG_INFO, LOG_WARNING, LOG_ERROR)</summary>
public static void TraceLog(TraceLogLevel logLevel, string text)
{
using var str1 = text.ToUTF8Buffer();
TraceLog(logLevel, str1.AsPointer());
}
/// <summary>Set shader uniform value vector</summary> /// <summary>Set shader uniform value vector</summary>
public static void SetShaderValueV<T>(Shader shader, int uniformLoc, T[] values, ShaderUniformDataType uniformType, int count) public static void SetShaderValueV<T>(Shader shader, int uniformLoc, T[] values, ShaderUniformDataType uniformType, int count)
where T : unmanaged where T : unmanaged
@ -92,9 +174,10 @@ namespace Raylib_cs
/// <summary>Load file data as byte array (read)</summary> /// <summary>Load file data as byte array (read)</summary>
public static byte* LoadFileData(string fileName, ref uint bytesRead) public static byte* LoadFileData(string fileName, ref uint bytesRead)
{ {
using var str1 = fileName.ToUTF8Buffer();
fixed (uint* p = &bytesRead) fixed (uint* p = &bytesRead)
{ {
return LoadFileData(fileName, p); return LoadFileData(str1.AsPointer(), p);
} }
} }
@ -140,21 +223,15 @@ namespace Raylib_cs
/// <summary>Create an image from text (default font)</summary> /// <summary>Create an image from text (default font)</summary>
public static Image ImageText(string text, int fontSize, Color color) public static Image ImageText(string text, int fontSize, Color color)
{ {
using var str = new UTF8Buffer(text); using var str1 = text.ToUTF8Buffer();
fixed (byte* b = str.buffer) return ImageText(str1.AsPointer(), fontSize, color);
{
return ImageText(b, fontSize, color);
}
} }
/// <summary>Create an image from text (custom sprite font)</summary> /// <summary>Create an image from text (custom sprite font)</summary>
public static Image ImageTextEx(Font font, string text, float fontSize, float spacing, Color tint) public static Image ImageTextEx(Font font, string text, float fontSize, float spacing, Color tint)
{ {
using var str = new UTF8Buffer(text); using var str1 = text.ToUTF8Buffer();
fixed (byte* b = str.buffer) return ImageTextEx(font, str1.AsPointer(), fontSize, spacing, tint);
{
return ImageTextEx(font, b, fontSize, spacing, tint);
}
} }
/// <summary>Convert image to POT (power-of-two)</summary> /// <summary>Convert image to POT (power-of-two)</summary>
@ -466,29 +543,30 @@ namespace Raylib_cs
/// <summary>Draw text (using default font) within an image (destination)</summary> /// <summary>Draw text (using default font) within an image (destination)</summary>
public static void ImageDrawText(ref Image dst, string text, int x, int y, int fontSize, Color color) public static void ImageDrawText(ref Image dst, string text, int x, int y, int fontSize, Color color)
{ {
using var str1 = text.ToUTF8Buffer();
fixed (Image* p = &dst) fixed (Image* p = &dst)
{ {
using var str = new UTF8Buffer(text); ImageDrawText(p, str1.AsPointer(), x, y, fontSize, color);
fixed (byte* b = str.buffer)
{
ImageDrawText(p, b, x, y, fontSize, color);
}
} }
} }
/// <summary>Draw text (custom sprite font) within an image (destination)</summary> /// <summary>Draw text (custom sprite font) within an image (destination)</summary>
public static void ImageDrawTextEx(ref Image dst, Font font, string text, Vector2 position, int fontSize, float spacing, Color color) public static void ImageDrawTextEx(ref Image dst, Font font, string text, Vector2 position, int fontSize, float spacing, Color color)
{ {
using var str1 = text.ToUTF8Buffer();
fixed (Image* p = &dst) fixed (Image* p = &dst)
{ {
using var str = new UTF8Buffer(text); ImageDrawTextEx(p, font, str1.AsPointer(), position, fontSize, spacing, color);
fixed (byte* b = str.buffer)
{
ImageDrawTextEx(p, font, b, position, fontSize, spacing, color);
}
} }
} }
/// <summary>Load texture from file into GPU memory (VRAM)</summary>
public static Texture2D LoadTexture(string fileName)
{
using var str1 = fileName.ToUTF8Buffer();
return LoadTexture(str1.AsPointer());
}
/// <summary>Generate GPU mipmaps for a texture</summary> /// <summary>Generate GPU mipmaps for a texture</summary>
public static void GenTextureMipmaps(ref Texture2D texture) public static void GenTextureMipmaps(ref Texture2D texture)
{ {
@ -497,6 +575,20 @@ namespace Raylib_cs
GenTextureMipmaps(p); GenTextureMipmaps(p);
} }
} }
/// <summary>Load font from file into GPU memory (VRAM)</summary>
public static Font LoadFont(string fileName)
{
using var str1 = fileName.ToUTF8Buffer();
return LoadFont(str1.AsPointer());
}
/// <summary>Load font from file with extended parameters</summary>
public static Font LoadFontEx(string fileName, int fontSize, int[] fontChars, int charsCount)
{
using var str1 = fileName.ToUTF8Buffer();
return LoadFontEx(str1.AsPointer(), fontSize, fontChars, charsCount);
}
/// <summary>Upload vertex data into GPU and provided VAO/VBO ids</summary> /// <summary>Upload vertex data into GPU and provided VAO/VBO ids</summary>
public static void UploadMesh(ref Mesh mesh, CBool dynamic) public static void UploadMesh(ref Mesh mesh, CBool dynamic)
@ -537,20 +629,17 @@ namespace Raylib_cs
/// <summary>Load model animations from file</summary> /// <summary>Load model animations from file</summary>
public static ReadOnlySpan<ModelAnimation> LoadModelAnimations(string fileName, ref uint animsCount) public static ReadOnlySpan<ModelAnimation> LoadModelAnimations(string fileName, ref uint animsCount)
{ {
using var str = new UTF8Buffer(fileName); using var str1 = fileName.ToUTF8Buffer();
fixed (byte* b = str.buffer) fixed (uint* p = &animsCount)
{ {
fixed (uint* p = &animsCount) var model = LoadModelAnimations(str1.AsPointer(), p);
if ((IntPtr)model == IntPtr.Zero)
{ {
var model = LoadModelAnimations(b, p); throw new ApplicationException("Failed to load animation");
if ((IntPtr)model == IntPtr.Zero)
{
throw new ApplicationException("Failed to load animation");
}
return new ReadOnlySpan<ModelAnimation>(model, (int)animsCount);
} }
return new ReadOnlySpan<ModelAnimation>(model, (int)animsCount);
} }
} }
@ -629,118 +718,91 @@ namespace Raylib_cs
} }
} }
/// <summary>Draw text (using default font)</summary>
public static void DrawText(string text, int posX, int posY, int fontSize, Color color) public static void DrawText(string text, int posX, int posY, int fontSize, Color color)
{ {
using var str = new UTF8Buffer(text); using var str1 = text.ToUTF8Buffer();
fixed (byte* b = str.buffer) DrawText(str1.AsPointer(), posX, posY, fontSize, color);
{
DrawText(b, posX, posY, fontSize, color);
}
} }
/// <summary>Draw text using font and additional parameters</summary>
public static void DrawTextEx(Font font, string text, Vector2 position, float fontSize, float spacing, Color tint) public static void DrawTextEx(Font font, string text, Vector2 position, float fontSize, float spacing, Color tint)
{ {
using var str = new UTF8Buffer(text); using var str1 = text.ToUTF8Buffer();
fixed (byte* b = str.buffer) DrawTextEx(font, str1.AsPointer(), position, fontSize, spacing, tint);
{
DrawTextEx(font, b, position, fontSize, spacing, tint);
}
} }
/// <summary>Draw text using Font and pro parameters (rotation)</summary>
public static void DrawTextPro(Font font, string text, Vector2 position, float fontSize, float spacing, Color tint) public static void DrawTextPro(Font font, string text, Vector2 position, float fontSize, float spacing, Color tint)
{ {
using var str = new UTF8Buffer(text); using var str1 = text.ToUTF8Buffer();
fixed (byte* b = str.buffer) DrawTextEx(font, str1.AsPointer(), position, fontSize, spacing, tint);
{
DrawTextEx(font, b, position, fontSize, spacing, tint);
}
} }
/// <summary>Measure string width for default font</summary>
public static int MeasureText(string text, int fontSize) public static int MeasureText(string text, int fontSize)
{ {
using var str = new UTF8Buffer(text); using var str1 = text.ToUTF8Buffer();
fixed (byte* b = str.buffer) return MeasureText(str1.AsPointer(), fontSize);
{
return MeasureText(b, fontSize);
}
} }
/// <summary>Measure string size for Font</summary>
public static Vector2 MeasureTextEx(Font font, string text, float fontSize, float spacing) public static Vector2 MeasureTextEx(Font font, string text, float fontSize, float spacing)
{ {
using var str = new UTF8Buffer(text); using var str1 = text.ToUTF8Buffer();
fixed (byte* b = str.buffer) return MeasureTextEx(font, str1.AsPointer(), fontSize, spacing);
{
return MeasureTextEx(font, b, fontSize, spacing);
}
} }
/// <summary>Append text at specific position and move cursor!</summary>
public static void TextAppend(string text, string append, int position) public static void TextAppend(string text, string append, int position)
{ {
using var str = new UTF8Buffer(text); using var str1 = text.ToUTF8Buffer();
using var str1 = new UTF8Buffer(append); using var str2 = append.ToUTF8Buffer();
fixed (byte* p1 = str.buffer) TextAppend(str1.AsPointer(), str2.AsPointer(), &position);
{
fixed (byte* p2 = str1.buffer)
{
TextAppend(p1, p2, &position);
}
}
} }
/// <summary>Get Pascal case notation version of provided string</summary>
public static string TextToPascal(string text) public static string TextToPascal(string text)
{ {
using var str = new UTF8Buffer(text); using var str1 = text.ToUTF8Buffer();
fixed (byte* b = str.buffer) return Utf8StringUtils.GetUTF8String(TextToPascal(str1.AsPointer()));
{
return Utf8StringUtils.GetUTF8String(TextToPascal(b));
}
} }
/// <summary>Get integer value from text (negative values not supported)</summary>
public static int TextToInteger(string text) public static int TextToInteger(string text)
{ {
using var str = new UTF8Buffer(text); using var str1 = text.ToUTF8Buffer();
fixed (byte* b = str.buffer) return TextToInteger(str1.AsPointer());
{
return TextToInteger(b);
}
} }
/// <summary>Get all codepoints in a string, codepoints count returned by parameters</summary>
public static int[] LoadCodepoints(string text, ref int count) public static int[] LoadCodepoints(string text, ref int count)
{ {
using var str = new UTF8Buffer(text); using var str1 = text.ToUTF8Buffer();
fixed (byte* b = str.buffer) fixed (int* c = &count)
{ {
fixed (int* c = &count) var pointsPtr = LoadCodepoints(str1.AsPointer(), c);
{ var codepoints = new ReadOnlySpan<int>(pointsPtr, count).ToArray();
var pointsPtr = LoadCodepoints(b, c); UnloadCodepoints(pointsPtr);
var codepoints = new ReadOnlySpan<int>(pointsPtr, count).ToArray(); return codepoints;
UnloadCodepoints(pointsPtr);
return codepoints;
}
} }
} }
/// <summary>Get total number of characters (codepoints) in a UTF8 encoded string</summary>
public static int GetCodepointCount(string text) public static int GetCodepointCount(string text)
{ {
using var str = new UTF8Buffer(text); using var str1 = text.ToUTF8Buffer();
fixed (byte* b = str.buffer) return GetCodepointCount(str1.AsPointer());
{
return GetCodepointCount(b);
}
} }
/// <summary>Returns next codepoint in a UTF8 encoded string; 0x3f('?') is returned on failure</summary> /// <summary>Returns next codepoint in a UTF8 encoded string; 0x3f('?') is returned on failure</summary>
/// <returns>single codepoint / "char"</returns> /// <returns>single codepoint / "char"</returns>
public static int GetCodepoint(string text, ref int bytesProcessed) public static int GetCodepoint(string text, ref int bytesProcessed)
{ {
using var str = new UTF8Buffer(text); using var str1 = text.ToUTF8Buffer();
fixed (byte* b = str.buffer) fixed (int* p = &bytesProcessed)
{ {
// this probably wont work return GetCodepoint(str1.AsPointer(), p);
fixed (int* p = &bytesProcessed)
{
return GetCodepoint(b, p);
}
} }
} }
@ -766,6 +828,13 @@ namespace Raylib_cs
} }
} }
/// <summary>Draw a model (with texture if set)</summary>
public static Model LoadModel(string fileName)
{
using var str1 = fileName.ToUTF8Buffer();
return LoadModel(str1.AsPointer());
}
/// <summary>Draw a triangle strip defined by points</summary> /// <summary>Draw a triangle strip defined by points</summary>
public static void DrawTriangleStrip3D(Vector3[] points, int pointsCount, Color color) public static void DrawTriangleStrip3D(Vector3[] points, int pointsCount, Color color)
{ {
@ -784,6 +853,27 @@ namespace Raylib_cs
} }
} }
/// <summary>Load wave data from file</summary>
public static Wave LoadWave(string fileName)
{
using var str1 = fileName.ToUTF8Buffer();
return LoadWave(str1.AsPointer());
}
/// <summary>Load sound from file</summary>
public static Sound LoadSound(string fileName)
{
using var str1 = fileName.ToUTF8Buffer();
return LoadSound(str1.AsPointer());
}
/// <summary>Load music stream from file</summary>
public static Music LoadMusicStream(string fileName)
{
using var str1 = fileName.ToUTF8Buffer();
return LoadMusicStream(str1.AsPointer());
}
public static string SubText(this string input, int position, int length) public static string SubText(this string input, int position, int length)
{ {
return input.Substring(position, Math.Min(length, input.Length)); return input.Substring(position, Math.Min(length, input.Length));

View file

@ -32,7 +32,7 @@ namespace Raylib_cs
/// <summary>Initialize window and OpenGL context</summary> /// <summary>Initialize window and OpenGL context</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void InitWindow(int width, int height, byte* title); public static extern void InitWindow(int width, int height, sbyte* title);
/// <summary>Check if KEY_ESCAPE pressed or Close icon pressed</summary> /// <summary>Check if KEY_ESCAPE pressed or Close icon pressed</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
@ -104,7 +104,7 @@ namespace Raylib_cs
/// <summary>Set title for window (only PLATFORM_DESKTOP)</summary> /// <summary>Set title for window (only PLATFORM_DESKTOP)</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void SetWindowTitle(byte* title); public static extern void SetWindowTitle(sbyte* title);
/// <summary>Set window position on screen (only PLATFORM_DESKTOP)</summary> /// <summary>Set window position on screen (only PLATFORM_DESKTOP)</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
@ -176,15 +176,15 @@ namespace Raylib_cs
/// <summary>Get the human-readable, UTF-8 encoded name of the primary monitor</summary> /// <summary>Get the human-readable, UTF-8 encoded name of the primary monitor</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern byte* GetMonitorName(int monitor); public static extern sbyte* GetMonitorName(int monitor);
/// <summary>Get clipboard text content</summary> /// <summary>Get clipboard text content</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern byte* GetClipboardText(); public static extern sbyte* GetClipboardText();
/// <summary>Set clipboard text content</summary> /// <summary>Set clipboard text content</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void SetClipboardText(byte* text); public static extern void SetClipboardText(sbyte* text);
// Custom frame control functions // Custom frame control functions
// NOTE: Those functions are intended for advance users that want full control over the frame processing // NOTE: Those functions are intended for advance users that want full control over the frame processing
@ -316,19 +316,19 @@ namespace Raylib_cs
/// <summary>Load shader from files and bind default locations</summary> /// <summary>Load shader from files and bind default locations</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Shader LoadShader(string vsFileName, string fsFileName); public static extern Shader LoadShader(sbyte* vsFileName, sbyte* fsFileName);
/// <summary>Load shader from code strings and bind default locations</summary> /// <summary>Load shader from code strings and bind default locations</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Shader LoadShaderFromMemory(string vsCode, string fsCode); public static extern Shader LoadShaderFromMemory(sbyte* vsCode, sbyte* fsCode);
/// <summary>Get shader uniform location</summary> /// <summary>Get shader uniform location</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern int GetShaderLocation(Shader shader, string uniformName); public static extern int GetShaderLocation(Shader shader, sbyte* uniformName);
/// <summary>Get shader attribute location</summary> /// <summary>Get shader attribute location</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern int GetShaderLocationAttrib(Shader shader, string attribName); public static extern int GetShaderLocationAttrib(Shader shader, sbyte* attribName);
/// <summary>Set shader uniform value</summary> /// <summary>Set shader uniform value</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
@ -413,7 +413,7 @@ namespace Raylib_cs
/// <summary>Takes a screenshot of current screen (saved a .png)</summary> /// <summary>Takes a screenshot of current screen (saved a .png)</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void TakeScreenshot(string fileName); public static extern void TakeScreenshot(sbyte* fileName);
/// <summary>Setup window configuration flags (view FLAGS)</summary> /// <summary>Setup window configuration flags (view FLAGS)</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
@ -421,7 +421,7 @@ namespace Raylib_cs
/// <summary>Show trace log messages (LOG_DEBUG, LOG_INFO, LOG_WARNING, LOG_ERROR)</summary> /// <summary>Show trace log messages (LOG_DEBUG, LOG_INFO, LOG_WARNING, LOG_ERROR)</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void TraceLog(TraceLogLevel logLevel, string text); public static extern void TraceLog(TraceLogLevel logLevel, sbyte* text);
/// <summary>Set the current threshold (minimum) log level</summary> /// <summary>Set the current threshold (minimum) log level</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
@ -468,7 +468,7 @@ namespace Raylib_cs
/// <summary>Load file data as byte array (read)</summary> /// <summary>Load file data as byte array (read)</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern byte* LoadFileData(string fileName, uint* bytesRead); public static extern byte* LoadFileData(sbyte* fileName, uint* bytesRead);
/// <summary>Unload file data allocated by LoadFileData()</summary> /// <summary>Unload file data allocated by LoadFileData()</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
@ -476,11 +476,11 @@ namespace Raylib_cs
/// <summary>Save data to file from byte array (write)</summary> /// <summary>Save data to file from byte array (write)</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern CBool SaveFileData(string fileName, void* data, uint bytesToWrite); public static extern CBool SaveFileData(sbyte* fileName, void* data, uint bytesToWrite);
/// <summary>Check file extension</summary> /// <summary>Check file extension</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern CBool IsFileExtension(string fileName, string ext); public static extern CBool IsFileExtension(sbyte* fileName, sbyte* ext);
/// <summary>Check if a file has been dropped into window</summary> /// <summary>Check if a file has been dropped into window</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
@ -488,7 +488,7 @@ namespace Raylib_cs
/// <summary>Get dropped files names (memory should be freed)</summary> /// <summary>Get dropped files names (memory should be freed)</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern byte** GetDroppedFiles(int* count); public static extern sbyte** GetDroppedFiles(int* count);
/// <summary>Clear dropped files paths buffer (free memory)</summary> /// <summary>Clear dropped files paths buffer (free memory)</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
@ -496,7 +496,7 @@ namespace Raylib_cs
/// <summary>Get file modification time (last write time)</summary> /// <summary>Get file modification time (last write time)</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern int GetFileModTime(string fileName); public static extern int GetFileModTime(sbyte* fileName);
/// <summary>Compress data (DEFLATE algorithm)</summary> /// <summary>Compress data (DEFLATE algorithm)</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
@ -508,7 +508,7 @@ namespace Raylib_cs
/// <summary>Encode data to Base64 string</summary> /// <summary>Encode data to Base64 string</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern byte* EncodeDataBase64(byte* data, int dataLength, int* outputLength); public static extern sbyte* EncodeDataBase64(byte* data, int dataLength, int* outputLength);
/// <summary>Decode Base64 string data</summary> /// <summary>Decode Base64 string data</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
@ -527,7 +527,7 @@ namespace Raylib_cs
/// <summary>Open URL with default system browser (if available)</summary> /// <summary>Open URL with default system browser (if available)</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void OpenURL(string url); public static extern void OpenURL(sbyte* url);
//------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------
// Input Handling Functions (Module: core) // Input Handling Functions (Module: core)
@ -572,7 +572,7 @@ namespace Raylib_cs
/// <summary>Return gamepad internal name id</summary> /// <summary>Return gamepad internal name id</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern byte* GetGamepadName(int gamepad); public static extern sbyte* GetGamepadName(int gamepad);
/// <summary>Detect if a gamepad button has been pressed once</summary> /// <summary>Detect if a gamepad button has been pressed once</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
@ -604,7 +604,7 @@ namespace Raylib_cs
/// <summary>Set internal gamepad mappings (SDL_GameControllerDB)</summary> /// <summary>Set internal gamepad mappings (SDL_GameControllerDB)</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern int SetGamepadMappings(string mappings); public static extern int SetGamepadMappings(sbyte* mappings);
// Input-related functions: mouse // Input-related functions: mouse
@ -962,19 +962,19 @@ namespace Raylib_cs
/// <summary>Load image from file into CPU memory (RAM)</summary> /// <summary>Load image from file into CPU memory (RAM)</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Image LoadImage(string fileName); public static extern Image LoadImage(sbyte* fileName);
/// <summary>Load image from RAW file data</summary> /// <summary>Load image from RAW file data</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Image LoadImageRaw(string fileName, int width, int height, PixelFormat format, int headerSize); public static extern Image LoadImageRaw(sbyte* fileName, int width, int height, PixelFormat format, int headerSize);
/// <summary>Load image sequence from file (frames appended to image.data)</summary> /// <summary>Load image sequence from file (frames appended to image.data)</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Image LoadImageAnim(string fileName, int* frames); public static extern Image LoadImageAnim(sbyte* fileName, int* frames);
/// <summary>Load image from memory buffer, fileType refers to extension: i.e. "png"</summary> /// <summary>Load image from memory buffer, fileType refers to extension: i.e. "png"</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Image LoadImageFromMemory(string fileType, byte* fileData, int dataSize); public static extern Image LoadImageFromMemory(sbyte* fileType, byte* fileData, int dataSize);
/// <summary>Load image from GPU texture data</summary> /// <summary>Load image from GPU texture data</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
@ -990,11 +990,11 @@ namespace Raylib_cs
/// <summary>Export image data to file</summary> /// <summary>Export image data to file</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void ExportImage(Image image, string fileName); public static extern void ExportImage(Image image, sbyte* fileName);
/// <summary>Export image as code file defining an array of bytes</summary> /// <summary>Export image as code file defining an array of bytes</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void ExportImageAsCode(Image image, string fileName); public static extern void ExportImageAsCode(Image image, sbyte* fileName);
// Image generation functions // Image generation functions
@ -1040,11 +1040,11 @@ namespace Raylib_cs
/// <summary>Create an image from text (default font)</summary> /// <summary>Create an image from text (default font)</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Image ImageText(byte* text, int fontSize, Color color); public static extern Image ImageText(sbyte* text, int fontSize, Color color);
/// <summary>Create an image from text (custom sprite font)</summary> /// <summary>Create an image from text (custom sprite font)</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Image ImageTextEx(Font font, byte* text, float fontSize, float spacing, Color tint); public static extern Image ImageTextEx(Font font, sbyte* text, float fontSize, float spacing, Color tint);
/// <summary>Convert image to POT (power-of-two)</summary> /// <summary>Convert image to POT (power-of-two)</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
@ -1212,11 +1212,11 @@ namespace Raylib_cs
/// <summary>Draw text (using default font) within an image (destination)</summary> /// <summary>Draw text (using default font) within an image (destination)</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void ImageDrawText(Image* dst, byte* text, int x, int y, int fontSize, Color color); public static extern void ImageDrawText(Image* dst, sbyte* text, int x, int y, int fontSize, Color color);
/// <summary>Draw text (custom sprite font) within an image (destination)</summary> /// <summary>Draw text (custom sprite font) within an image (destination)</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void ImageDrawTextEx(Image* dst, Font font, byte* text, Vector2 position, float fontSize, float spacing, Color tint); public static extern void ImageDrawTextEx(Image* dst, Font font, sbyte* text, Vector2 position, float fontSize, float spacing, Color tint);
// Texture loading functions // Texture loading functions
@ -1224,7 +1224,7 @@ namespace Raylib_cs
/// <summary>Load texture from file into GPU memory (VRAM)</summary> /// <summary>Load texture from file into GPU memory (VRAM)</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Texture2D LoadTexture(string fileName); public static extern Texture2D LoadTexture(sbyte* fileName);
/// <summary>Load texture from image data</summary> /// <summary>Load texture from image data</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
@ -1368,11 +1368,11 @@ namespace Raylib_cs
/// <summary>Load font from file into GPU memory (VRAM)</summary> /// <summary>Load font from file into GPU memory (VRAM)</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Font LoadFont(string fileName); public static extern Font LoadFont(sbyte* fileName);
/// <summary>Load font from file with extended parameters</summary> /// <summary>Load font from file with extended parameters</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Font LoadFontEx(string fileName, int fontSize, int[] fontChars, int charsCount); public static extern Font LoadFontEx(sbyte* fileName, int fontSize, int[] fontChars, int charsCount);
/// <summary>Load font from Image (XNA style)</summary> /// <summary>Load font from Image (XNA style)</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
@ -1381,7 +1381,7 @@ namespace Raylib_cs
/// <summary>Load font from memory buffer, fileType refers to extension: i.e. "ttf"<br/> /// <summary>Load font from memory buffer, fileType refers to extension: i.e. "ttf"<br/>
/// fileData refers to const unsigned char *</summary> /// fileData refers to const unsigned char *</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Font LoadFontFromMemory(string fileType, byte* fileData, int dataSize, int fontSize, int[] fontChars, int charsCount); public static extern Font LoadFontFromMemory(sbyte* fileType, byte* fileData, int dataSize, int fontSize, int[] fontChars, int charsCount);
/// <summary>Load font data for further use</summary> /// <summary>Load font data for further use</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
@ -1408,15 +1408,15 @@ namespace Raylib_cs
/// <summary>Draw text (using default font)</summary> /// <summary>Draw text (using default font)</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void DrawText(byte* text, int posX, int posY, int fontSize, Color color); public static extern void DrawText(sbyte* text, int posX, int posY, int fontSize, Color color);
/// <summary>Draw text using font and additional parameters</summary> /// <summary>Draw text using font and additional parameters</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void DrawTextEx(Font font, byte* text, Vector2 position, float fontSize, float spacing, Color tint); public static extern void DrawTextEx(Font font, sbyte* text, Vector2 position, float fontSize, float spacing, Color tint);
/// <summary>Draw text using Font and pro parameters (rotation)</summary> /// <summary>Draw text using Font and pro parameters (rotation)</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void DrawTextPro(Font font, byte* text, Vector2 position, float fontSize, float spacing, Color tint); public static extern void DrawTextPro(Font font, sbyte* text, Vector2 position, float fontSize, float spacing, Color tint);
/// <summary>Draw one character (codepoint)</summary> /// <summary>Draw one character (codepoint)</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
@ -1427,11 +1427,11 @@ namespace Raylib_cs
/// <summary>Measure string width for default font</summary> /// <summary>Measure string width for default font</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern int MeasureText(byte* text, int fontSize); public static extern int MeasureText(sbyte* text, int fontSize);
/// <summary>Measure string size for Font</summary> /// <summary>Measure string size for Font</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Vector2 MeasureTextEx(Font font, byte* text, float fontSize, float spacing); public static extern Vector2 MeasureTextEx(Font font, sbyte* text, float fontSize, float spacing);
/// <summary>Get glyph index position in font for a codepoint (unicode character), fallback to '?' if not found</summary> /// <summary>Get glyph index position in font for a codepoint (unicode character), fallback to '?' if not found</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
@ -1450,29 +1450,29 @@ namespace Raylib_cs
/// <summary>Text formatting with variables (sprintf style)</summary> /// <summary>Text formatting with variables (sprintf style)</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern string TextFormat(string text); public static extern sbyte* TextFormat(sbyte* text);
/// <summary>Get a piece of a text string</summary> /// <summary>Get a piece of a text string</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern string TextSubtext(string text, int position, int length); public static extern sbyte* TextSubtext(sbyte* text, int position, int length);
/// <summary>Append text at specific position and move cursor!</summary> /// <summary>Append text at specific position and move cursor!</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void TextAppend(byte* text, byte* append, int* position); public static extern void TextAppend(sbyte* text, sbyte* append, int* position);
/// <summary>Get Pascal case notation version of provided string</summary> /// <summary>Get Pascal case notation version of provided string</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern byte* TextToPascal(byte* text); public static extern sbyte* TextToPascal(sbyte* text);
/// <summary>Get integer value from text (negative values not supported)</summary> /// <summary>Get integer value from text (negative values not supported)</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern int TextToInteger(byte* text); public static extern int TextToInteger(sbyte* text);
// UTF8 text strings management functions // UTF8 text strings management functions
/// <summary>Get all codepoints in a string, codepoints count returned by parameters</summary> /// <summary>Get all codepoints in a string, codepoints count returned by parameters</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern int* LoadCodepoints(byte* text, int* count); public static extern int* LoadCodepoints(sbyte* text, int* count);
/// <summary>Unload codepoints data from memory</summary> /// <summary>Unload codepoints data from memory</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
@ -1480,19 +1480,19 @@ namespace Raylib_cs
/// <summary>Get total number of characters (codepoints) in a UTF8 encoded string</summary> /// <summary>Get total number of characters (codepoints) in a UTF8 encoded string</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern int GetCodepointCount(byte* text); public static extern int GetCodepointCount(sbyte* text);
/// <summary>Returns next codepoint in a UTF8 encoded string; 0x3f('?') is returned on failure</summary> /// <summary>Returns next codepoint in a UTF8 encoded string; 0x3f('?') is returned on failure</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern int GetCodepoint(byte* text, int* bytesProcessed); public static extern int GetCodepoint(sbyte* text, int* bytesProcessed);
/// <summary>Encode codepoint into utf8 text (char array length returned as parameter)</summary> /// <summary>Encode codepoint into utf8 text (char array length returned as parameter)</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern byte* CodepointToUTF8(int codepoint, int* byteSize); public static extern sbyte* CodepointToUTF8(int codepoint, int* byteSize);
/// <summary>Encode text as codepoints array into UTF-8 text string (WARNING: memory must be freed!)</summary> /// <summary>Encode text as codepoints array into UTF-8 text string (WARNING: memory must be freed!)</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern byte* TextCodepointsToUTF8(int* codepoints, int length); public static extern sbyte* TextCodepointsToUTF8(int* codepoints, int length);
//------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------
@ -1594,7 +1594,7 @@ namespace Raylib_cs
/// <summary>Load model from files (meshes and materials)</summary> /// <summary>Load model from files (meshes and materials)</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Model LoadModel(string fileName); public static extern Model LoadModel(sbyte* fileName);
/// <summary>Load model from generated mesh (default material)</summary> /// <summary>Load model from generated mesh (default material)</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
@ -1636,7 +1636,7 @@ namespace Raylib_cs
/// <summary>Export mesh data to file, returns true on success</summary> /// <summary>Export mesh data to file, returns true on success</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern CBool ExportMesh(Mesh mesh, string fileName); public static extern CBool ExportMesh(Mesh mesh, sbyte* fileName);
/// <summary>Compute mesh bounding box limits</summary> /// <summary>Compute mesh bounding box limits</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
@ -1656,7 +1656,7 @@ namespace Raylib_cs
//TODO: safe Helper method //TODO: safe Helper method
/// <summary>Load materials from model file</summary> /// <summary>Load materials from model file</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Material* LoadMaterials(string fileName, int* materialCount); public static extern Material* LoadMaterials(sbyte* fileName, int* materialCount);
/// <summary>Load default material (Supports: DIFFUSE, SPECULAR, NORMAL maps)</summary> /// <summary>Load default material (Supports: DIFFUSE, SPECULAR, NORMAL maps)</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
@ -1759,7 +1759,7 @@ namespace Raylib_cs
/// <summary>Load model animations from file</summary> /// <summary>Load model animations from file</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern ModelAnimation* LoadModelAnimations(byte* fileName, uint* animsCount); public static extern ModelAnimation* LoadModelAnimations(sbyte* fileName, uint* animsCount);
/// <summary>Update model animation pose</summary> /// <summary>Update model animation pose</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
@ -1843,16 +1843,16 @@ namespace Raylib_cs
/// <summary>Load wave data from file</summary> /// <summary>Load wave data from file</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Wave LoadWave(string fileName); public static extern Wave LoadWave(sbyte* fileName);
/// <summary>Load wave from memory buffer, fileType refers to extension: i.e. "wav"<br/> /// <summary>Load wave from memory buffer, fileType refers to extension: i.e. "wav"<br/>
/// fileData refers to a const unsigned char *</summary> /// fileData refers to a const unsigned char *</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Wave LoadWaveFromMemory(string fileType, byte* fileData, int dataSize); public static extern Wave LoadWaveFromMemory(sbyte* fileType, byte* fileData, int dataSize);
/// <summary>Load sound from file</summary> /// <summary>Load sound from file</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Sound LoadSound(string fileName); public static extern Sound LoadSound(sbyte* fileName);
/// <summary>Load sound from wave data</summary> /// <summary>Load sound from wave data</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
@ -1872,11 +1872,11 @@ namespace Raylib_cs
/// <summary>Export wave data to file</summary> /// <summary>Export wave data to file</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void ExportWave(Wave wave, string fileName); public static extern void ExportWave(Wave wave, sbyte* fileName);
/// <summary>Export wave sample data to code (.h)</summary> /// <summary>Export wave sample data to code (.h)</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void ExportWaveAsCode(Wave wave, string fileName); public static extern void ExportWaveAsCode(Wave wave, sbyte* fileName);
// Wave/Sound management functions // Wave/Sound management functions
@ -1947,12 +1947,12 @@ namespace Raylib_cs
/// <summary>Load music stream from file</summary> /// <summary>Load music stream from file</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Music LoadMusicStream(string fileName); public static extern Music LoadMusicStream(sbyte* fileName);
//TODO: Span/Helper method //TODO: Span/Helper method
/// <summary>Load music stream from data</summary> /// <summary>Load music stream from data</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Music LoadMusicStreamFromMemory(string fileType, byte* data, int dataSize); public static extern Music LoadMusicStreamFromMemory(sbyte* fileType, byte* data, int dataSize);
/// <summary>Unload music stream</summary> /// <summary>Unload music stream</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]

View file

@ -1,5 +1,4 @@
using System; using System;
using System.Buffers;
using System.Text; using System.Text;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
@ -11,41 +10,48 @@ namespace Raylib_cs
/// </summary> /// </summary>
public ref struct UTF8Buffer public ref struct UTF8Buffer
{ {
public byte[] buffer; private IntPtr data;
public UTF8Buffer(string text) public UTF8Buffer(string text)
{ {
int length = (text.Length * 4) + 1; data = Marshal.StringToCoTaskMemUTF8(text);
buffer = ArrayPool<byte>.Shared.Rent(length); }
int count = Encoding.UTF8.GetBytes(text.AsSpan(), buffer.AsSpan());
buffer[count] = 0; public unsafe sbyte* AsPointer()
{
return (sbyte*)data.ToPointer();
} }
public void Dispose() public void Dispose()
{ {
ArrayPool<byte>.Shared.Return(buffer); Marshal.FreeCoTaskMem(data);
} }
} }
public static class Utf8StringUtils public static class Utf8StringUtils
{ {
public static byte[] ToUtf8String(this string sourceText) public static UTF8Buffer ToUTF8Buffer(this string text)
{ {
if (sourceText == null) return new UTF8Buffer(text);
}
public static byte[] ToUtf8String(this string text)
{
if (text == null)
{ {
return null; return null;
} }
var length = Encoding.UTF8.GetByteCount(sourceText); var length = Encoding.UTF8.GetByteCount(text);
var byteArray = new byte[length + 1]; var byteArray = new byte[length + 1];
var wrote = Encoding.UTF8.GetBytes(sourceText, 0, sourceText.Length, byteArray, 0); var wrote = Encoding.UTF8.GetBytes(text, 0, text.Length, byteArray, 0);
byteArray[wrote] = 0; byteArray[wrote] = 0;
return byteArray; return byteArray;
} }
public static unsafe string GetUTF8String(byte* bytes) public static unsafe string GetUTF8String(sbyte* bytes)
{ {
return Marshal.PtrToStringUTF8((IntPtr)bytes); return Marshal.PtrToStringUTF8((IntPtr)bytes);
} }