From 39ce41eb085585c1f65b44c4f1352e100b9a415a Mon Sep 17 00:00:00 2001 From: ChrisDill Date: Fri, 31 Dec 2021 09:30:28 +0000 Subject: [PATCH] Setup unsafe/safe functions for math types in Raylib.cs --- Raylib-cs/Raylib.Utils.cs | 57 +++++++++++++++++++++++++++++++++++++++ Raylib-cs/Raylib.cs | 20 +++++++------- 2 files changed, 67 insertions(+), 10 deletions(-) diff --git a/Raylib-cs/Raylib.Utils.cs b/Raylib-cs/Raylib.Utils.cs index df225f0..8264744 100644 --- a/Raylib-cs/Raylib.Utils.cs +++ b/Raylib-cs/Raylib.Utils.cs @@ -590,6 +590,45 @@ namespace Raylib_cs } } + /// Draw lines sequence + public static void DrawLineStrip(Vector2[] points, int numPoints, Color color) + { + fixed (Vector2* p = points) + { + DrawLineStrip(p, numPoints, color); + } + } + + /// Draw a triangle fan defined by points (first vertex is the center) + public static void DrawTriangleFan(Vector2[] points, int numPoints, Color color) + { + fixed (Vector2* p = points) + { + DrawTriangleFan(p, numPoints, color); + } + } + + /// Draw a triangle strip defined by points + public static void DrawTriangleStrip(Vector2[] points, int pointsCount, Color color) + { + fixed (Vector2* p = points) + { + DrawTriangleStrip(p, pointsCount, color); + } + } + + /// Draw a textured polygon + public static void DrawTexturePoly(Texture2D texture, Vector2 center, Vector2[] points, Vector2[] texcoords, int pointsCount, Color tint) + { + fixed (Vector2* p = points) + { + fixed (Vector2* p1 = texcoords) + { + DrawTexturePoly(texture, center, p, p1, pointsCount, tint); + } + } + } + public static void DrawText(string text, int posX, int posY, int fontSize, Color color) { using var str = new UTF8Buffer(text); @@ -727,6 +766,24 @@ namespace Raylib_cs } } + /// Draw a triangle strip defined by points + public static void DrawTriangleStrip3D(Vector3[] points, int pointsCount, Color color) + { + fixed (Vector3* p = points) + { + DrawTriangleStrip3D(p, pointsCount, color); + } + } + + /// Draw multiple mesh instances with material and different transforms + public static void DrawMeshInstanced(Mesh mesh, Material material, Matrix4x4[] transforms, int instances) + { + fixed (Matrix4x4* p = transforms) + { + DrawMeshInstanced(mesh, material, p, instances); + } + } + public static string SubText(this string input, int position, int length) { return input.Substring(position, Math.Min(length, input.Length)); diff --git a/Raylib-cs/Raylib.cs b/Raylib-cs/Raylib.cs index 2481d73..41f663a 100644 --- a/Raylib-cs/Raylib.cs +++ b/Raylib-cs/Raylib.cs @@ -500,19 +500,19 @@ namespace Raylib_cs /// Compress data (DEFLATE algorithm) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern byte* CompressData(byte[] data, int dataLength, int* compDataLength); + public static extern byte* CompressData(byte* data, int dataLength, int* compDataLength); /// Decompress data (DEFLATE algorithm) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern byte* DecompressData(byte[] compData, int compDataLength, int* dataLength); + public static extern byte* DecompressData(byte* compData, int compDataLength, int* dataLength); /// Encode data to Base64 string [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern byte* EncodeDataBase64(byte[] data, int dataLength, int* outputLength); + public static extern byte* EncodeDataBase64(byte* data, int dataLength, int* outputLength); /// Decode Base64 string data [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern byte* DecodeDataBase64(byte[] data, int* outputLength); + public static extern byte* DecodeDataBase64(byte* data, int* outputLength); // Persistent storage management @@ -800,7 +800,7 @@ namespace Raylib_cs /// Draw lines sequence [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void DrawLineStrip(Vector2[] points, int numPoints, Color color); + public static extern void DrawLineStrip(Vector2* points, int numPoints, Color color); /// Draw a color-filled circle [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -896,11 +896,11 @@ namespace Raylib_cs /// Draw a triangle fan defined by points (first vertex is the center) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void DrawTriangleFan(Vector2[] points, int numPoints, Color color); + public static extern void DrawTriangleFan(Vector2* points, int numPoints, Color color); /// Draw a triangle strip defined by points [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void DrawTriangleStrip(Vector2[] points, int pointsCount, Color color); + public static extern void DrawTriangleStrip(Vector2* points, int pointsCount, Color color); /// Draw a regular polygon (Vector version) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -1306,7 +1306,7 @@ namespace Raylib_cs /// Draw a textured polygon [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void DrawTexturePoly(Texture2D texture, Vector2 center, Vector2[] points, Vector2[] texcoords, int pointsCount, Color tint); + public static extern void DrawTexturePoly(Texture2D texture, Vector2 center, Vector2* points, Vector2* texcoords, int pointsCount, Color tint); // Color/pixel related functions @@ -1519,7 +1519,7 @@ namespace Raylib_cs /// Draw a triangle strip defined by points [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void DrawTriangleStrip3D(Vector3[] points, int pointsCount, Color color); + public static extern void DrawTriangleStrip3D(Vector3* points, int pointsCount, Color color); /// Draw cube [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -1632,7 +1632,7 @@ namespace Raylib_cs /// Draw multiple mesh instances with material and different transforms [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void DrawMeshInstanced(Mesh mesh, Material material, Matrix4x4[] transforms, int instances); + public static extern void DrawMeshInstanced(Mesh mesh, Material material, Matrix4x4* transforms, int instances); /// Export mesh data to file, returns true on success [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]