From 794b82de0e85c1042ad21792a84262f8800217dd Mon Sep 17 00:00:00 2001 From: ChrisDill Date: Thu, 11 Nov 2021 12:00:42 +0000 Subject: [PATCH 01/14] Minor fixes - Rename Gestures enum to Gesture - Update tests to net6.0 --- Raylib-cs.Tests/Raylib-cs.Tests.csproj | 2 +- Raylib-cs/Raylib.cs | 17 +++++++++-------- Raylib-cs/types/Input.cs | 4 ++-- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/Raylib-cs.Tests/Raylib-cs.Tests.csproj b/Raylib-cs.Tests/Raylib-cs.Tests.csproj index 1b23439..0518e96 100644 --- a/Raylib-cs.Tests/Raylib-cs.Tests.csproj +++ b/Raylib-cs.Tests/Raylib-cs.Tests.csproj @@ -1,6 +1,6 @@ - net5.0 + net6.0 ../Logo/raylib-cs.ico true diff --git a/Raylib-cs/Raylib.cs b/Raylib-cs/Raylib.cs index beaf96f..ec9de42 100644 --- a/Raylib-cs/Raylib.cs +++ b/Raylib-cs/Raylib.cs @@ -24,14 +24,15 @@ namespace Raylib_cs /// /// Logging: Redirect trace log messages /// WARNING: This callback is intended for advance users - /// + /// [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void TraceLogCallback(TraceLogLevel logLevel, string text, IntPtr args); + /// /// FileIO: Load binary data /// WARNING: This callback is intended for advance users - /// - /// refers to a unsigned char * + /// + /// refers to a unsigned char * [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate IntPtr LoadFileDataCallback(string fileName, ref int bytesRead); @@ -776,16 +777,16 @@ namespace Raylib_cs /// Enable a set of gestures using flags [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void SetGesturesEnabled(Gestures flags); + public static extern void SetGesturesEnabled(Gesture flags); /// Check if a gesture have been detected [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.I1)] - public static extern bool IsGestureDetected(Gestures gesture); + public static extern bool IsGestureDetected(Gesture gesture); /// Get latest detected gesture [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern Gestures GetGestureDetected(); + public static extern Gesture GetGestureDetected(); /// Get touch points count [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -1449,7 +1450,7 @@ namespace Raylib_cs /// Set color formatted into destination pixel pointer [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void SetPixelColor(IntPtr srcPtr, Color color, PixelFormat format); + public static extern void SetPixelColor(IntPtr dstPtr, Color color, PixelFormat format); /// Get pixel data size in bytes for certain format [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -1854,7 +1855,7 @@ namespace Raylib_cs [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void DrawBillboardRec(Camera3D camera, Texture2D texture, Rectangle source, Vector3 center, float size, Color tint); - // Draw a billboard texture defined by source and rotation + /// Draw a billboard texture defined by source and rotation [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void DrawBillboardPro(Camera3D camera, Texture2D texture, Rectangle source, Vector3 position, Vector3 up, Vector2 size, Vector2 origin, float rotation, Color tint); diff --git a/Raylib-cs/types/Input.cs b/Raylib-cs/types/Input.cs index 18677ae..cc1030b 100644 --- a/Raylib-cs/types/Input.cs +++ b/Raylib-cs/types/Input.cs @@ -350,10 +350,10 @@ namespace Raylib_cs GAMEPAD_BUTTON_RIGHT_THUMB } - /// Gestures + /// Gesture /// NOTE: It could be used as flags to enable only some gestures [Flags] - public enum Gestures + public enum Gesture { GESTURE_NONE = 0, GESTURE_TAP = 1, From 5014ebbfe0abb70a3a1167b1862133ffd98e6ba5 Mon Sep 17 00:00:00 2001 From: ChrisDill Date: Thu, 11 Nov 2021 12:00:42 +0000 Subject: [PATCH 02/14] Testing CBool type instead of bool --- Raylib-cs/Raylib.cs | 156 ++++++++++++++------------------------- Raylib-cs/RaylibUtils.cs | 26 +++++++ Raylib-cs/Rlgl.cs | 23 +++--- 3 files changed, 89 insertions(+), 116 deletions(-) diff --git a/Raylib-cs/Raylib.cs b/Raylib-cs/Raylib.cs index ec9de42..1b65cd2 100644 --- a/Raylib-cs/Raylib.cs +++ b/Raylib-cs/Raylib.cs @@ -42,7 +42,7 @@ namespace Raylib_cs /// /// refers to a void * [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public delegate bool SaveFileDataCallback(string fileName, IntPtr data, ref int bytesToWrite); + public delegate CBool SaveFileDataCallback(string fileName, IntPtr data, ref int bytesToWrite); /// /// FileIO: Load text data @@ -56,7 +56,7 @@ namespace Raylib_cs /// WARNING: This callback is intended for advance users /// [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public delegate bool SaveFileTextCallback(string fileName, string text); + public delegate CBool SaveFileTextCallback(string fileName, string text); /// /// Returns color with alpha applied, alpha goes from 0.0f to 1.0f @@ -79,8 +79,7 @@ namespace Raylib_cs /// Check if KEY_ESCAPE pressed or Close icon pressed [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - [return: MarshalAs(UnmanagedType.I1)] - public static extern bool WindowShouldClose(); + public static extern CBool WindowShouldClose(); /// Close window and unload OpenGL context [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -88,48 +87,39 @@ namespace Raylib_cs /// Check if window has been initialized successfully [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - [return: MarshalAs(UnmanagedType.I1)] - public static extern bool IsWindowReady(); + public static extern CBool IsWindowReady(); /// Check if window is currently fullscreen [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - [return: MarshalAs(UnmanagedType.I1)] - public static extern bool IsWindowFullscreen(); + public static extern CBool IsWindowFullscreen(); /// Check if window is currently hidden (only PLATFORM_DESKTOP) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - [return: MarshalAs(UnmanagedType.I1)] - public static extern bool IsWindowHidden(); + public static extern CBool IsWindowHidden(); /// Check if window is currently minimized (only PLATFORM_DESKTOP) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - [return: MarshalAs(UnmanagedType.I1)] - public static extern bool IsWindowMinimized(); + public static extern CBool IsWindowMinimized(); /// Check if window is currently maximized (only PLATFORM_DESKTOP) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - [return: MarshalAs(UnmanagedType.I1)] - public static extern bool IsWindowMaximized(); + public static extern CBool IsWindowMaximized(); /// Check if window is currently focused (only PLATFORM_DESKTOP) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - [return: MarshalAs(UnmanagedType.I1)] - public static extern bool IsWindowFocused(); + public static extern CBool IsWindowFocused(); /// Check if window has been resized last frame [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - [return: MarshalAs(UnmanagedType.I1)] - public static extern bool IsWindowResized(); + public static extern CBool IsWindowResized(); /// Check if one specific window flag is enabled [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - [return: MarshalAs(UnmanagedType.I1)] - public static extern bool IsWindowState(ConfigFlags flag); + public static extern CBool IsWindowState(ConfigFlags flag); /// Set window configuration state using flags [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - [return: MarshalAs(UnmanagedType.I1)] - public static extern bool SetWindowState(ConfigFlags flag); + public static extern CBool SetWindowState(ConfigFlags flag); /// Clear window configuration state flags [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -281,8 +271,7 @@ namespace Raylib_cs /// Check if cursor is not visible [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - [return: MarshalAs(UnmanagedType.I1)] - public static extern bool IsCursorHidden(); + public static extern CBool IsCursorHidden(); /// Enables cursor (unlock cursor) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -294,8 +283,7 @@ namespace Raylib_cs /// Disables cursor (lock cursor) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - [return: MarshalAs(UnmanagedType.I1)] - public static extern bool IsCursorOnScreen(); + public static extern CBool IsCursorOnScreen(); // Drawing-related functions @@ -548,18 +536,15 @@ namespace Raylib_cs /// Save data to file from byte array (write) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - [return: MarshalAs(UnmanagedType.I1)] - public static extern bool SaveFileData(string fileName, IntPtr data, int bytesToWrite); + public static extern CBool SaveFileData(string fileName, IntPtr data, int bytesToWrite); /// Check file extension [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - [return: MarshalAs(UnmanagedType.I1)] - public static extern bool IsFileExtension(string fileName, string ext); + public static extern CBool IsFileExtension(string fileName, string ext); /// Check if a file has been dropped into window [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - [return: MarshalAs(UnmanagedType.I1)] - public static extern bool IsFileDropped(); + public static extern CBool IsFileDropped(); /// Get dropped files names (memory should be freed) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -586,8 +571,7 @@ namespace Raylib_cs /// Save integer value to storage file (to defined position) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - [return: MarshalAs(UnmanagedType.I1)] - public static extern bool SaveStorageValue(uint position, int value); + public static extern CBool SaveStorageValue(uint position, int value); /// Load integer value from storage file (from defined position) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -605,23 +589,19 @@ namespace Raylib_cs /// Detect if a key has been pressed once [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - [return: MarshalAs(UnmanagedType.I1)] - public static extern bool IsKeyPressed(KeyboardKey key); + public static extern CBool IsKeyPressed(KeyboardKey key); /// Detect if a key is being pressed [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - [return: MarshalAs(UnmanagedType.I1)] - public static extern bool IsKeyDown(KeyboardKey key); + public static extern CBool IsKeyDown(KeyboardKey key); /// Detect if a key has been released once [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - [return: MarshalAs(UnmanagedType.I1)] - public static extern bool IsKeyReleased(KeyboardKey key); + public static extern CBool IsKeyReleased(KeyboardKey key); /// Detect if a key is NOT being pressed [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - [return: MarshalAs(UnmanagedType.I1)] - public static extern bool IsKeyUp(KeyboardKey key); + public static extern CBool IsKeyUp(KeyboardKey key); /// Set a custom key to exit program (default is ESC) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -640,8 +620,7 @@ namespace Raylib_cs /// Detect if a gamepad is available [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - [return: MarshalAs(UnmanagedType.I1)] - public static extern bool IsGamepadAvailable(int gamepad); + public static extern CBool IsGamepadAvailable(int gamepad); /// Return gamepad internal name id [DllImport(nativeLibName, EntryPoint = "GetGamepadName", CallingConvention = CallingConvention.Cdecl)] @@ -655,23 +634,19 @@ namespace Raylib_cs /// Detect if a gamepad button has been pressed once [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - [return: MarshalAs(UnmanagedType.I1)] - public static extern bool IsGamepadButtonPressed(int gamepad, GamepadButton button); + public static extern CBool IsGamepadButtonPressed(int gamepad, GamepadButton button); /// Detect if a gamepad button is being pressed [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - [return: MarshalAs(UnmanagedType.I1)] - public static extern bool IsGamepadButtonDown(int gamepad, GamepadButton button); + public static extern CBool IsGamepadButtonDown(int gamepad, GamepadButton button); /// Detect if a gamepad button has been released once [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - [return: MarshalAs(UnmanagedType.I1)] - public static extern bool IsGamepadButtonReleased(int gamepad, GamepadButton button); + public static extern CBool IsGamepadButtonReleased(int gamepad, GamepadButton button); /// Detect if a gamepad button is NOT being pressed [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - [return: MarshalAs(UnmanagedType.I1)] - public static extern bool IsGamepadButtonUp(int gamepad, GamepadButton button); + public static extern CBool IsGamepadButtonUp(int gamepad, GamepadButton button); /// Get the last gamepad button pressed [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -694,23 +669,19 @@ namespace Raylib_cs /// Detect if a mouse button has been pressed once [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - [return: MarshalAs(UnmanagedType.I1)] - public static extern bool IsMouseButtonPressed(MouseButton button); + public static extern CBool IsMouseButtonPressed(MouseButton button); /// Detect if a mouse button is being pressed [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - [return: MarshalAs(UnmanagedType.I1)] - public static extern bool IsMouseButtonDown(MouseButton button); + public static extern CBool IsMouseButtonDown(MouseButton button); /// Detect if a mouse button has been released once [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - [return: MarshalAs(UnmanagedType.I1)] - public static extern bool IsMouseButtonReleased(MouseButton button); + public static extern CBool IsMouseButtonReleased(MouseButton button); /// Detect if a mouse button is NOT being pressed [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - [return: MarshalAs(UnmanagedType.I1)] - public static extern bool IsMouseButtonUp(MouseButton button); + public static extern CBool IsMouseButtonUp(MouseButton button); /// Returns mouse position X [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -781,8 +752,7 @@ namespace Raylib_cs /// Check if a gesture have been detected [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - [return: MarshalAs(UnmanagedType.I1)] - public static extern bool IsGestureDetected(Gesture gesture); + public static extern CBool IsGestureDetected(Gesture gesture); /// Get latest detected gesture [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -1005,42 +975,35 @@ namespace Raylib_cs /// Check collision between two rectangles [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - [return: MarshalAs(UnmanagedType.I1)] - public static extern bool CheckCollisionRecs(Rectangle rec1, Rectangle rec2); + public static extern CBool CheckCollisionRecs(Rectangle rec1, Rectangle rec2); /// Check collision between two circles [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - [return: MarshalAs(UnmanagedType.I1)] - public static extern bool CheckCollisionCircles(Vector2 center1, float radius1, Vector2 center2, float radius2); + public static extern CBool CheckCollisionCircles(Vector2 center1, float radius1, Vector2 center2, float radius2); /// Check collision between circle and rectangle [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - [return: MarshalAs(UnmanagedType.I1)] - public static extern bool CheckCollisionCircleRec(Vector2 center, float radius, Rectangle rec); + public static extern CBool CheckCollisionCircleRec(Vector2 center, float radius, Rectangle rec); /// Check if point is inside rectangle [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - [return: MarshalAs(UnmanagedType.I1)] - public static extern bool CheckCollisionPointRec(Vector2 point, Rectangle rec); + public static extern CBool CheckCollisionPointRec(Vector2 point, Rectangle rec); /// Check if point is inside circle [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - [return: MarshalAs(UnmanagedType.I1)] - public static extern bool CheckCollisionPointCircle(Vector2 point, Vector2 center, float radius); + public static extern CBool CheckCollisionPointCircle(Vector2 point, Vector2 center, float radius); /// Check if point is inside a triangle [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - [return: MarshalAs(UnmanagedType.I1)] - public static extern bool CheckCollisionPointTriangle(Vector2 point, Vector2 p1, Vector2 p2, Vector2 p3); + public static extern CBool CheckCollisionPointTriangle(Vector2 point, Vector2 p1, Vector2 p2, Vector2 p3); /// Check the collision between two lines defined by two points each, returns collision point by reference [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - [return: MarshalAs(UnmanagedType.I1)] - public static extern bool CheckCollisionLines(Vector2 startPos1, Vector2 endPos1, Vector2 startPos2, Vector2 endPos2, ref Vector2 collisionPoint); + public static extern CBool CheckCollisionLines(Vector2 startPos1, Vector2 endPos1, Vector2 startPos2, Vector2 endPos2, ref Vector2 collisionPoint); /// Check if point belongs to line created between two points [p1] and [p2] with defined margin in pixels [threshold] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern bool CheckCollisionPointLine(Vector2 point, Vector2 p1, Vector2 p2, int threshold); + public static extern CBool CheckCollisionPointLine(Vector2 point, Vector2 p1, Vector2 p2, int threshold); /// Get collision rectangle for two rectangles collision [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -1718,7 +1681,7 @@ namespace Raylib_cs /// Upload vertex data into GPU and provided VAO/VBO ids [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void UploadMesh(ref Mesh mesh, bool dynamic); + public static extern void UploadMesh(ref Mesh mesh, CBool dynamic); /// Update mesh vertex data in GPU for a specific buffer index /// data refers to a void * @@ -1739,8 +1702,7 @@ namespace Raylib_cs /// Export mesh data to file, returns true on success [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - [return: MarshalAs(UnmanagedType.I1)] - public static extern bool ExportMesh(Mesh mesh, string fileName); + public static extern CBool ExportMesh(Mesh mesh, string fileName); /// Compute mesh bounding box limits [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -1757,8 +1719,8 @@ namespace Raylib_cs // Material loading/unloading functions - /// Load materials from model file - /// IntPtr refers to Material * + /// Load materials from model file + /// IntPtr refers to Material * [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr LoadMaterials(string fileName, ref int materialCount); @@ -1880,30 +1842,25 @@ namespace Raylib_cs /// Check model animation skeleton match [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - [return: MarshalAs(UnmanagedType.I1)] - public static extern bool IsModelAnimationValid(Model model, ModelAnimation anim); + public static extern CBool IsModelAnimationValid(Model model, ModelAnimation anim); // Collision detection functions /// Detect collision between two spheres [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - [return: MarshalAs(UnmanagedType.I1)] - public static extern bool CheckCollisionSpheres(Vector3 center1, float radius1, Vector3 center2, float radius2); + public static extern CBool CheckCollisionSpheres(Vector3 center1, float radius1, Vector3 center2, float radius2); /// Detect collision between two bounding boxes [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - [return: MarshalAs(UnmanagedType.I1)] - public static extern bool CheckCollisionBoxes(BoundingBox box1, BoundingBox box2); + public static extern CBool CheckCollisionBoxes(BoundingBox box1, BoundingBox box2); /// Detect collision between box and sphere [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - [return: MarshalAs(UnmanagedType.I1)] - public static extern bool CheckCollisionBoxSphere(BoundingBox box, Vector3 center, float radius); + public static extern CBool CheckCollisionBoxSphere(BoundingBox box, Vector3 center, float radius); /// Detect collision between ray and sphere [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - [return: MarshalAs(UnmanagedType.I1)] - public static extern bool GetRayCollisionSphere(Ray ray, Vector3 center, float radius); + public static extern CBool GetRayCollisionSphere(Ray ray, Vector3 center, float radius); /// Detect collision between ray and box [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -1942,8 +1899,7 @@ namespace Raylib_cs /// Check if audio device has been initialized successfully [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - [return: MarshalAs(UnmanagedType.I1)] - public static extern bool IsAudioDeviceReady(); + public static extern CBool IsAudioDeviceReady(); /// Set master volume (listener) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -2023,8 +1979,7 @@ namespace Raylib_cs /// Check if a sound is currently playing [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - [return: MarshalAs(UnmanagedType.I1)] - public static extern bool IsSoundPlaying(Sound sound); + public static extern CBool IsSoundPlaying(Sound sound); /// Set volume for a sound (1.0 is max level) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -2076,8 +2031,7 @@ namespace Raylib_cs /// Check if music is playing [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - [return: MarshalAs(UnmanagedType.I1)] - public static extern bool IsMusicStreamPlaying(Music music); + public static extern CBool IsMusicStreamPlaying(Music music); /// Updates buffers for music streaming [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -2133,8 +2087,7 @@ namespace Raylib_cs /// Check if any audio stream buffers requires refill [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - [return: MarshalAs(UnmanagedType.I1)] - public static extern bool IsAudioStreamProcessed(AudioStream stream); + public static extern CBool IsAudioStreamProcessed(AudioStream stream); /// Play audio stream [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -2150,8 +2103,7 @@ namespace Raylib_cs /// Check if audio stream is playing [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - [return: MarshalAs(UnmanagedType.I1)] - public static extern bool IsAudioStreamPlaying(AudioStream stream); + public static extern CBool IsAudioStreamPlaying(AudioStream stream); /// Stop audio stream [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] diff --git a/Raylib-cs/RaylibUtils.cs b/Raylib-cs/RaylibUtils.cs index 57e5780..c065007 100644 --- a/Raylib-cs/RaylibUtils.cs +++ b/Raylib-cs/RaylibUtils.cs @@ -4,6 +4,32 @@ using Raylib_cs; namespace Raylib_cs { + [StructLayout(LayoutKind.Sequential)] + public readonly struct CBool + { + private readonly byte value; + + private CBool(bool value) + { + this.value = Convert.ToByte(value); + } + + public static implicit operator CBool(bool value) + { + return new CBool(value); + } + + public static implicit operator bool(CBool x) + { + return Convert.ToBoolean(x.value); + } + + public override string ToString() + { + return Convert.ToBoolean(value).ToString(); + } + } + /// /// Utility functions for parts of the api that are not easy to interact with via pinvoke. /// diff --git a/Raylib-cs/Rlgl.cs b/Raylib-cs/Rlgl.cs index f0bb0d8..d49264d 100644 --- a/Raylib-cs/Rlgl.cs +++ b/Raylib-cs/Rlgl.cs @@ -200,8 +200,7 @@ namespace Raylib_cs /// Enable vertex array (VAO, if supported) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - [return: MarshalAs(UnmanagedType.I1)] - public static extern bool rlEnableVertexArray(uint vaoId); + public static extern CBool rlEnableVertexArray(uint vaoId); /// Disable vertex array (VAO, if supported) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -353,8 +352,7 @@ namespace Raylib_cs /// Check if stereo render is enabled [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - [return: MarshalAs(UnmanagedType.I1)] - public static extern bool rlIsStereoRenderEnabled(); + public static extern CBool rlIsStereoRenderEnabled(); /// Clear color buffer with color [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -439,8 +437,7 @@ namespace Raylib_cs /// Check internal buffer overflow for a given number of vertex [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - [return: MarshalAs(UnmanagedType.I1)] - public static extern bool rlCheckRenderBatchLimit(int vCount); + public static extern CBool rlCheckRenderBatchLimit(int vCount); /// Set current texture for render batch and check buffers limits [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -455,11 +452,11 @@ namespace Raylib_cs /// Load a vertex buffer attribute [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern uint rlLoadVertexBuffer(IntPtr buffer, int size, bool dynamic); + public static extern uint rlLoadVertexBuffer(IntPtr buffer, int size, CBool dynamic); /// Load a new attributes element buffer [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern uint rlLoadVertexBufferElement(IntPtr buffer, int size, bool dynamic); + public static extern uint rlLoadVertexBufferElement(IntPtr buffer, int size, CBool dynamic); /// Update GPU buffer with new data [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -472,7 +469,7 @@ namespace Raylib_cs public static extern void rlUnloadVertexBuffer(uint vboId); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void rlSetVertexAttribute(uint index, int compSize, int type, bool normalized, int stride, IntPtr pointer); + public static extern void rlSetVertexAttribute(uint index, int compSize, int type, CBool normalized, int stride, IntPtr pointer); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void rlSetVertexAttributeDivisor(uint index, int divisor); @@ -503,7 +500,7 @@ namespace Raylib_cs /// Load depth texture/renderbuffer (to be attached to fbo) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern uint rlLoadTextureDepth(int width, int height, bool useRenderBuffer); + public static extern uint rlLoadTextureDepth(int width, int height, CBool useRenderBuffer); /// Load texture cubemap /// data refers to a void * @@ -550,13 +547,11 @@ namespace Raylib_cs /// Verify framebuffer is complete [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - [return: MarshalAs(UnmanagedType.I1)] - public static extern bool rlFramebufferComplete(uint id); + public static extern CBool rlFramebufferComplete(uint id); /// Delete framebuffer from GPU [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - [return: MarshalAs(UnmanagedType.I1)] - public static extern bool rlUnloadFramebuffer(uint id); + public static extern CBool rlUnloadFramebuffer(uint id); // Shaders management From de6caec6f1dfa400731ed03b9a9eb47fdef0cbb1 Mon Sep 17 00:00:00 2001 From: ChrisDill Date: Thu, 11 Nov 2021 12:00:42 +0000 Subject: [PATCH 03/14] Update XmlDoc comments --- Raylib-cs/Raylib.cs | 82 ++++++++++++++++++------------------ Raylib-cs/RaylibUtils.cs | 2 +- Raylib-cs/Rlgl.cs | 10 ++--- Raylib-cs/types/Audio.cs | 4 +- Raylib-cs/types/Image.cs | 6 ++- Raylib-cs/types/Input.cs | 13 +++--- Raylib-cs/types/Mesh.cs | 2 +- Raylib-cs/types/Texture2D.cs | 11 ++--- 8 files changed, 67 insertions(+), 63 deletions(-) diff --git a/Raylib-cs/Raylib.cs b/Raylib-cs/Raylib.cs index 1b65cd2..1c5094e 100644 --- a/Raylib-cs/Raylib.cs +++ b/Raylib-cs/Raylib.cs @@ -22,14 +22,14 @@ namespace Raylib_cs // WARNING: These callbacks are intended for advance users /// - /// Logging: Redirect trace log messages + /// Logging: Redirect trace log messages
/// WARNING: This callback is intended for advance users ///
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void TraceLogCallback(TraceLogLevel logLevel, string text, IntPtr args); /// - /// FileIO: Load binary data + /// FileIO: Load binary data
/// WARNING: This callback is intended for advance users ///
/// refers to a unsigned char * @@ -37,29 +37,29 @@ namespace Raylib_cs public delegate IntPtr LoadFileDataCallback(string fileName, ref int bytesRead); /// - /// FileIO: Save binary data + /// FileIO: Save binary data
/// WARNING: This callback is intended for advance users ///
- /// refers to a void * [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate CBool SaveFileDataCallback(string fileName, IntPtr data, ref int bytesToWrite); /// - /// FileIO: Load text data + /// FileIO: Load text data
/// WARNING: This callback is intended for advance users ///
+ /// refers to a char * [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public delegate string LoadFileTextCallback(string fileName); + public delegate IntPtr LoadFileTextCallback(string fileName); /// - /// FileIO: Save text data + /// FileIO: Save text data
/// WARNING: This callback is intended for advance users ///
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate CBool SaveFileTextCallback(string fileName, string text); /// - /// Returns color with alpha applied, alpha goes from 0.0f to 1.0f + /// Returns color with alpha applied, alpha goes from 0.0f to 1.0f
/// NOTE: Added for compatability with previous versions ///
public static Color Fade(Color color, float alpha) => ColorAlpha(color, alpha); @@ -71,9 +71,7 @@ namespace Raylib_cs // Window-related functions - /// - /// Initialize window and OpenGL context - /// + /// Initialize window and OpenGL context [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void InitWindow(int width, int height, [MarshalAs(UnmanagedType.LPUTF8Str)] string title); @@ -165,7 +163,7 @@ namespace Raylib_cs [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SetWindowSize(int width, int height); - /// Get native window handle + /// Get native window handle
/// IntPtr refers to a void *
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr GetWindowHandle(); @@ -386,12 +384,12 @@ namespace Raylib_cs [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int GetShaderLocationAttrib(Shader shader, string attribName); - /// Set shader uniform value - /// value refers to a const void * + /// Set shader uniform value
+ /// refers to a const void *
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SetShaderValue(Shader shader, int uniformLoc, IntPtr value, ShaderUniformDataType uniformType); - /// Set shader uniform value vector + /// Set shader uniform value vector
/// value refers to a const void *
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SetShaderValueV(Shader shader, int uniformLoc, IntPtr value, ShaderUniformDataType uniformType, int count); @@ -524,12 +522,12 @@ namespace Raylib_cs // Files management functions - /// Load file data as byte array (read) + /// Load file data as byte array (read)
/// IntPtr refers to unsigned char *
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr LoadFileData(string fileName, ref int bytesRead); - /// Unload file data allocated by LoadFileData() + /// Unload file data allocated by LoadFileData()
/// data refers to a unsigned char *
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void UnloadFileData(IntPtr data); @@ -548,7 +546,7 @@ namespace Raylib_cs /// Get dropped files names (memory should be freed) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static unsafe extern byte** GetDroppedFiles(int* count); + public static extern unsafe byte** GetDroppedFiles(int* count); /// Clear dropped files paths buffer (free memory) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -814,9 +812,9 @@ namespace Raylib_cs // Basic Shapes Drawing Functions (Module: shapes) //------------------------------------------------------------------------------------ - /// Set texture and rectangle to be used on shapes drawing - /// NOTE: It can be useful when using basic shapes and one single font, - /// defining a font char white rectangle would allow drawing everything in a single draw call + /// Set texture and rectangle to be used on shapes drawing
+ /// NOTE: It can be useful when using basic shapes and one single font.
+ /// Defining a white rectangle would allow drawing everything in a single draw call.
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SetShapesTexture(Texture2D texture, Rectangle source); @@ -1001,7 +999,7 @@ namespace Raylib_cs [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern CBool CheckCollisionLines(Vector2 startPos1, Vector2 endPos1, Vector2 startPos2, Vector2 endPos2, ref Vector2 collisionPoint); - /// Check if point belongs to line created between two points [p1] and [p2] with defined margin in pixels [threshold] + /// Check if point belongs to line created between two points [p1] and [p2] with defined margin in pixels [threshold] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern CBool CheckCollisionPointLine(Vector2 point, Vector2 p1, Vector2 p2, int threshold); @@ -1029,7 +1027,7 @@ namespace Raylib_cs [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Image LoadImageAnim(string fileName, ref int frames); - /// Load image from memory buffer, fileType refers to extension: i.e. "png" + /// Load image from memory buffer, fileType refers to extension: i.e. "png"
/// fileData refers to const unsigned char *
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Image LoadImageFromMemory(string fileType, IntPtr fileData, int dataSize); @@ -1192,17 +1190,17 @@ namespace Raylib_cs [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void ImageColorReplace(ref Image image, Color color, Color replace); - /// Load color data from image as a Color array (RGBA - 32bit) + /// Load color data from image as a Color array (RGBA - 32bit)
/// IntPtr refers to Color *
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr LoadImageColors(Image image); - /// Load colors palette from image as a Color array (RGBA - 32bit) + /// Load colors palette from image as a Color array (RGBA - 32bit)
/// IntPtr refers to Color *
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr LoadImagePaletee(Image image, int maxPaletteSize, ref int colorsCount); - /// Unload color data loaded with LoadImageColors() + /// Unload color data loaded with LoadImageColors()
/// colors refers to Color *
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void UnloadImageColors(IntPtr colors); @@ -1308,7 +1306,7 @@ namespace Raylib_cs [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void UnloadRenderTexture(RenderTexture2D target); - /// Update GPU texture with new data + /// Update GPU texture with new data
/// pixels refers to a const void *
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void UpdateTexture(Texture2D texture, IntPtr pixels); @@ -1442,13 +1440,13 @@ namespace Raylib_cs [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Font LoadFontFromImage(Image image, Color key, int firstChar); - /// Load font from memory buffer, fileType refers to extension: i.e. "ttf" + /// Load font from memory buffer, fileType refers to extension: i.e. "ttf"
/// fileData refers to const unsigned char *
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Font LoadFontFromMemory(string fileType, IntPtr fileData, int dataSize, int fontSize, int[] fontChars, int charsCount); - /// Load font data for further use - /// fileData refers to const unsigned char * + /// Load font data for further use
+ /// fileData refers to const unsigned char *
/// IntPtr refers to GlyphInfo *
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr LoadFontData(IntPtr fileData, int dataSize, int fontSize, int[] fontChars, int charsCount, FontType type); @@ -1457,7 +1455,7 @@ namespace Raylib_cs [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Image GenImageFontAtlas(IntPtr chars, ref IntPtr recs, int charsCount, int fontSize, int padding, int packMethod); - /// Unload font chars info data (RAM) + /// Unload font chars info data (RAM)
/// chars refers to GlpyhInfo *
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void UnloadFontData(IntPtr chars, int charsCount); @@ -1542,7 +1540,7 @@ namespace Raylib_cs // UTF8 text strings management functions - /// Get all codepoints in a string, codepoints count returned by parameters + /// Get all codepoints in a string, codepoints count returned by parameters
/// IntPtr refers to a int *
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr GetCodepoints(string text, ref int count); @@ -1683,8 +1681,8 @@ namespace Raylib_cs [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void UploadMesh(ref Mesh mesh, CBool dynamic); - /// Update mesh vertex data in GPU for a specific buffer index - /// data refers to a void * + /// Update mesh vertex data in GPU for a specific buffer index
+ /// data refers to a void *
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void UpdateMeshBuffer(Mesh mesh, int index, IntPtr data, int dataSize, int offset); @@ -1719,7 +1717,7 @@ namespace Raylib_cs // Material loading/unloading functions - /// Load materials from model file + /// Load materials from model file
/// IntPtr refers to Material *
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr LoadMaterials(string fileName, ref int materialCount); @@ -1823,7 +1821,7 @@ namespace Raylib_cs // Model animations loading/unloading functions - /// Load model animations from file + /// Load model animations from file
/// IntPtr refers to ModelAnimation *
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr LoadModelAnimations(string fileName, ref int animsCount); @@ -1912,7 +1910,7 @@ namespace Raylib_cs [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Wave LoadWave(string fileName); - /// Load wave from memory buffer, fileType refers to extension: i.e. "wav" + /// Load wave from memory buffer, fileType refers to extension: i.e. "wav"
/// fileData refers to a const unsigned char *
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Wave LoadWaveFromMemory(string fileType, IntPtr fileData, int dataSize); @@ -1925,8 +1923,8 @@ namespace Raylib_cs [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Sound LoadSoundFromWave(Wave wave); - /// Update sound buffer with new data - /// data refers to a const void * + /// Update sound buffer with new data
+ /// refers to a const void *
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void UpdateSound(Sound sound, IntPtr data, int samplesCount); @@ -2001,12 +1999,12 @@ namespace Raylib_cs [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void WaveCrop(ref Wave wave, int initSample, int finalSample); - /// Get samples data from wave as a floats array + /// Get samples data from wave as a floats array
/// IntPtr refers to float *
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr LoadWaveSamples(Wave wave); - /// Unload samples data loaded with LoadWaveSamples() + /// Unload samples data loaded with LoadWaveSamples()
/// samples refers to float *
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void UnloadWaveSamples(IntPtr samples); @@ -2080,7 +2078,7 @@ namespace Raylib_cs [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void UnloadAudioStream(AudioStream stream); - /// Update audio stream buffers with data + /// Update audio stream buffers with data
/// data refers to a const void *
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void UpdateAudioStream(AudioStream stream, IntPtr data, int samplesCount); diff --git a/Raylib-cs/RaylibUtils.cs b/Raylib-cs/RaylibUtils.cs index c065007..741b7a2 100644 --- a/Raylib-cs/RaylibUtils.cs +++ b/Raylib-cs/RaylibUtils.cs @@ -4,7 +4,7 @@ using Raylib_cs; namespace Raylib_cs { - [StructLayout(LayoutKind.Sequential)] + [StructLayout(LayoutKind.Sequential)] public readonly struct CBool { private readonly byte value; diff --git a/Raylib-cs/Rlgl.cs b/Raylib-cs/Rlgl.cs index d49264d..34587d3 100644 --- a/Raylib-cs/Rlgl.cs +++ b/Raylib-cs/Rlgl.cs @@ -493,7 +493,7 @@ namespace Raylib_cs // Textures data management - /// Load texture in GPU + /// Load texture in GPU
/// data refers to a void *
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern uint rlLoadTexture(IntPtr data, int width, int height, PixelFormat format, int mipmapCount); @@ -502,12 +502,12 @@ namespace Raylib_cs [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern uint rlLoadTextureDepth(int width, int height, CBool useRenderBuffer); - /// Load texture cubemap + /// Load texture cubemap
/// data refers to a void *
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern uint rlLoadTextureCubemap(IntPtr data, int size, PixelFormat format); - /// Update GPU texture with new data + /// Update GPU texture with new data
/// data refers to a const void *
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void rlUpdateTexture(uint id, int width, int height, PixelFormat format, IntPtr data); @@ -524,12 +524,12 @@ namespace Raylib_cs [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void rlGenerateMipmaps(ref Texture2D texture); - /// Read texture pixel data + /// Read texture pixel data
/// IntPtr refers to a void *
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr rlReadTexturePixels(Texture2D texture); - /// Read screen pixel data (color buffer) + /// Read screen pixel data (color buffer)
/// IntPtr refers to a unsigned char *
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr rlReadScreenPixels(int width, int height); diff --git a/Raylib-cs/types/Audio.cs b/Raylib-cs/types/Audio.cs index 5709ee5..5f14236 100644 --- a/Raylib-cs/types/Audio.cs +++ b/Raylib-cs/types/Audio.cs @@ -36,7 +36,7 @@ namespace Raylib_cs } /// - /// Audio stream type + /// Audio stream type
/// NOTE: Useful to create custom audio streams not bound to a specific file ///
[StructLayout(LayoutKind.Sequential)] @@ -81,7 +81,7 @@ namespace Raylib_cs } /// - /// Music stream type (audio file streaming from memory) + /// Music stream type (audio file streaming from memory)
/// NOTE: Anything longer than ~10 seconds should be streamed ///
[StructLayout(LayoutKind.Sequential)] diff --git a/Raylib-cs/types/Image.cs b/Raylib-cs/types/Image.cs index e5e1f9f..271cc55 100644 --- a/Raylib-cs/types/Image.cs +++ b/Raylib-cs/types/Image.cs @@ -3,8 +3,10 @@ using System.Runtime.InteropServices; namespace Raylib_cs { - /// Pixel formats - /// NOTE: Support depends on OpenGL version and platform + /// + /// Pixel formats
+ /// NOTE: Support depends on OpenGL version and platform + ///
public enum PixelFormat { /// diff --git a/Raylib-cs/types/Input.cs b/Raylib-cs/types/Input.cs index cc1030b..fd032c7 100644 --- a/Raylib-cs/types/Input.cs +++ b/Raylib-cs/types/Input.cs @@ -4,9 +4,10 @@ using System.Runtime.InteropServices; namespace Raylib_cs { - /// Keyboard keys (US keyboard layout) - /// NOTE: Use GetKeyPressed() to allow redefining - /// required keys for alternative layouts + /// + /// Keyboard keys (US keyboard layout)
+ /// NOTE: Use GetKeyPressed() to allow redefining required keys for alternative layouts + ///
public enum KeyboardKey { /// @@ -350,8 +351,10 @@ namespace Raylib_cs GAMEPAD_BUTTON_RIGHT_THUMB } - /// Gesture - /// NOTE: It could be used as flags to enable only some gestures + /// + /// Gesture
+ /// NOTE: It could be used as flags to enable only some gestures + ///
[Flags] public enum Gesture { diff --git a/Raylib-cs/types/Mesh.cs b/Raylib-cs/types/Mesh.cs index c7746a2..6c29141 100644 --- a/Raylib-cs/types/Mesh.cs +++ b/Raylib-cs/types/Mesh.cs @@ -27,7 +27,7 @@ namespace Raylib_cs } /// - /// Vertex data definning a mesh + /// Vertex data definning a mesh
/// NOTE: Data stored in CPU memory (and GPU) ///
[StructLayout(LayoutKind.Sequential)] diff --git a/Raylib-cs/types/Texture2D.cs b/Raylib-cs/types/Texture2D.cs index f8c7f0d..7315b6a 100644 --- a/Raylib-cs/types/Texture2D.cs +++ b/Raylib-cs/types/Texture2D.cs @@ -2,9 +2,11 @@ using System.Runtime.InteropServices; namespace Raylib_cs { - /// Texture parameters: filter mode - /// NOTE 1: Filtering considers mipmaps if available in the texture - /// NOTE 2: Filter is accordingly set for minification and magnification + /// + /// Texture parameters: filter mode
+ /// NOTE 1: Filtering considers mipmaps if available in the texture
+ /// NOTE 2: Filter is accordingly set for minification and magnification + ///
public enum TextureFilter { /// @@ -97,8 +99,7 @@ namespace Raylib_cs } /// - /// Texture2D type - ///
+ /// Texture2D type
/// NOTE: Data stored in GPU memory ///
[StructLayout(LayoutKind.Sequential)] From 1b647fa4c315b91751954ff89da8140675263554 Mon Sep 17 00:00:00 2001 From: ChrisDill Date: Thu, 11 Nov 2021 12:00:42 +0000 Subject: [PATCH 04/14] Update build.yml to net6.0 for tests --- .github/workflows/build.yml | 4 ++-- Raylib-cs/types/Input.cs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c9d45fc..f5d73a5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -18,7 +18,7 @@ jobs: - name: Setup dotnet uses: actions/setup-dotnet@v1 with: - dotnet-version: 5.0.x + dotnet-version: 6.0.x - name: Build project run: dotnet build -c Release - name: Test project @@ -96,7 +96,7 @@ jobs: xpath: "//PackageVersion" - name: Create NuGet Package - run: dotnet pack -c Release + run: dotnet pack -c Release Raylib-cs - name: Upload NuGet Package As Artifact uses: actions/upload-artifact@v2 diff --git a/Raylib-cs/types/Input.cs b/Raylib-cs/types/Input.cs index fd032c7..ca03fdf 100644 --- a/Raylib-cs/types/Input.cs +++ b/Raylib-cs/types/Input.cs @@ -162,7 +162,7 @@ namespace Raylib_cs MOUSE_BUTTON_EXTRA = 4, /// - /// Mouse button fordward (advanced mouse device) + /// Mouse button forward (advanced mouse device) /// MOUSE_BUTTON_FORWARD = 5, From dd76d0ae9e849671b8d1d7da5f513c63de7b281d Mon Sep 17 00:00:00 2001 From: ChrisDill Date: Thu, 11 Nov 2021 12:00:42 +0000 Subject: [PATCH 05/14] Remove Easings.cs - Easings used to be part of raylib. It is now a separate extra library so I am removing it from the main bindings. --- Raylib-cs/Easings.cs | 264 ------------------------------------------- 1 file changed, 264 deletions(-) delete mode 100644 Raylib-cs/Easings.cs diff --git a/Raylib-cs/Easings.cs b/Raylib-cs/Easings.cs deleted file mode 100644 index 89d14a3..0000000 --- a/Raylib-cs/Easings.cs +++ /dev/null @@ -1,264 +0,0 @@ -using System; - -namespace Raylib_cs -{ - public static class Easings - { - // Linear Easing functions - public static float EaseLinearNone(float t, float b, float c, float d) - { - return (c * t / d + b); - } - - public static float EaseLinearIn(float t, float b, float c, float d) - { - return (c * t / d + b); - } - - public static float EaseLinearOut(float t, float b, float c, float d) - { - return (c * t / d + b); - } - - public static float EaseLinearInOut(float t, float b, float c, float d) - { - return (c * t / d + b); - } - - // Sine Easing functions - public static float EaseSineIn(float t, float b, float c, float d) - { - return (-c * MathF.Cos(t / d * (MathF.PI / 2)) + c + b); - } - - public static float EaseSineOut(float t, float b, float c, float d) - { - return (c * MathF.Sin(t / d * (MathF.PI / 2)) + b); - } - - public static float EaseSineInOut(float t, float b, float c, float d) - { - return (-c / 2 * (MathF.Cos(MathF.PI * t / d) - 1) + b); - } - - // Circular Easing functions - public static float EaseCircIn(float t, float b, float c, float d) - { - return (-c * (MathF.Sqrt(1 - (t /= d) * t) - 1) + b); - } - - public static float EaseCircOut(float t, float b, float c, float d) - { - return (c * MathF.Sqrt(1 - (t = t / d - 1) * t) + b); - } - - public static float EaseCircInOut(float t, float b, float c, float d) - { - if ((t /= d / 2) < 1) - { - return (-c / 2 * (MathF.Sqrt(1 - t * t) - 1) + b); - } - return (c / 2 * (MathF.Sqrt(1 - t * (t -= 2)) + 1) + b); - } - - // Cubic Easing functions - public static float EaseCubicIn(float t, float b, float c, float d) - { - return (c * (t /= d) * t * t + b); - } - - public static float EaseCubicOut(float t, float b, float c, float d) - { - return (c * ((t = t / d - 1) * t * t + 1) + b); - } - - public static float EaseCubicInOut(float t, float b, float c, float d) - { - if ((t /= d / 2) < 1) - { - return (c / 2 * t * t * t + b); - } - return (c / 2 * ((t -= 2) * t * t + 2) + b); - } - - // Quadratic Easing functions - public static float EaseQuadIn(float t, float b, float c, float d) - { - return (c * (t /= d) * t + b); - } - - public static float EaseQuadOut(float t, float b, float c, float d) - { - return (-c * (t /= d) * (t - 2) + b); - } - - public static float EaseQuadInOut(float t, float b, float c, float d) - { - if ((t /= d / 2) < 1) - { - return (((c / 2) * (t * t)) + b); - } - return (-c / 2 * (((t - 2) * (--t)) - 1) + b); - } - - // Exponential Easing functions - public static float EaseExpoIn(float t, float b, float c, float d) - { - return (t == 0) ? b : (c * MathF.Pow(2, 10 * (t / d - 1)) + b); - } - - public static float EaseExpoOut(float t, float b, float c, float d) - { - return (t == d) ? (b + c) : (c * (-MathF.Pow(2, -10 * t / d) + 1) + b); - } - - public static float EaseExpoInOut(float t, float b, float c, float d) - { - if (t == 0) - { - return b; - } - if (t == d) - { - return (b + c); - } - if ((t /= d / 2) < 1) - { - return (c / 2 * MathF.Pow(2, 10 * (t - 1)) + b); - } - return (c / 2 * (-MathF.Pow(2, -10 * --t) + 2) + b); - } - - // Back Easing functions - public static float EaseBackIn(float t, float b, float c, float d) - { - float s = 1.70158f; - float postFix = t /= d; - return (c * (postFix) * t * ((s + 1) * t - s) + b); - } - - public static float EaseBackOut(float t, float b, float c, float d) - { - float s = 1.70158f; - return (c * ((t = t / d - 1) * t * ((s + 1) * t + s) + 1) + b); - } - - public static float EaseBackInOut(float t, float b, float c, float d) - { - float s = 1.70158f; - if ((t /= d / 2) < 1) - { - return (c / 2 * (t * t * (((s *= (1.525f)) + 1) * t - s)) + b); - } - - float postFix = t -= 2; - return (c / 2 * ((postFix) * t * (((s *= (1.525f)) + 1) * t + s) + 2) + b); - } - - // Bounce Easing functions - public static float EaseBounceOut(float t, float b, float c, float d) - { - if ((t /= d) < (1 / 2.75f)) - { - return (c * (7.5625f * t * t) + b); - } - else if (t < (2 / 2.75f)) - { - float postFix = t -= (1.5f / 2.75f); - return (c * (7.5625f * (postFix) * t + 0.75f) + b); - } - else if (t < (2.5 / 2.75)) - { - float postFix = t -= (2.25f / 2.75f); - return (c * (7.5625f * (postFix) * t + 0.9375f) + b); - } - else - { - float postFix = t -= (2.625f / 2.75f); - return (c * (7.5625f * (postFix) * t + 0.984375f) + b); - } - } - - public static float EaseBounceIn(float t, float b, float c, float d) - { - return (c - EaseBounceOut(d - t, 0, c, d) + b); - } - - public static float EaseBounceInOut(float t, float b, float c, float d) - { - if (t < d / 2) - { - return (EaseBounceIn(t * 2, 0, c, d) * 0.5f + b); - } - else - { - return (EaseBounceOut(t * 2 - d, 0, c, d) * 0.5f + c * 0.5f + b); - } - } - - // Elastic Easing functions - public static float EaseElasticIn(float t, float b, float c, float d) - { - if (t == 0) - { - return b; - } - if ((t /= d) == 1) - { - return (b + c); - } - - float p = d * 0.3f; - float a = c; - float s = p / 4; - float postFix = a * MathF.Pow(2, 10 * (t -= 1)); - - return (-(postFix * MathF.Sin((t * d - s) * (2 * MathF.PI) / p)) + b); - } - - public static float EaseElasticOut(float t, float b, float c, float d) - { - if (t == 0) - { - return b; - } - if ((t /= d) == 1) - { - return (b + c); - } - - float p = d * 0.3f; - float a = c; - float s = p / 4; - - return (a * MathF.Pow(2, -10 * t) * MathF.Sin((t * d - s) * (2 * MathF.PI) / p) + c + b); - } - - public static float EaseElasticInOut(float t, float b, float c, float d) - { - if (t == 0) - { - return b; - } - if ((t /= d / 2) == 2) - { - return (b + c); - } - - float p = d * (0.3f * 1.5f); - float a = c; - float s = p / 4; - - float postFix = 0f; - if (t < 1) - { - postFix = a * MathF.Pow(2, 10 * (t -= 1)); - return -0.5f * (postFix * MathF.Sin((t * d - s) * (2 * MathF.PI) / p)) + b; - } - - postFix = a * MathF.Pow(2, -10 * (t -= 1)); - - return (postFix * MathF.Sin((t * d - s) * (2 * MathF.PI) / p) * 0.5f + c + b); - } - } -} From 88c14c635021b2ed276379e398116ea0555b9657 Mon Sep 17 00:00:00 2001 From: ChrisDill Date: Thu, 11 Nov 2021 12:00:42 +0000 Subject: [PATCH 06/14] Update rlgl --- Raylib-cs/Rlgl.cs | 174 +++++++++++++++++++++------------ Raylib-cs/types/RenderBatch.cs | 148 ++++++++++++++++++++++++++++ 2 files changed, 259 insertions(+), 63 deletions(-) create mode 100644 Raylib-cs/types/RenderBatch.cs diff --git a/Raylib-cs/Rlgl.cs b/Raylib-cs/Rlgl.cs index 34587d3..dffbbcd 100644 --- a/Raylib-cs/Rlgl.cs +++ b/Raylib-cs/Rlgl.cs @@ -5,53 +5,6 @@ using System.Security; namespace Raylib_cs { - /// RenderBatch type - [StructLayout(LayoutKind.Sequential)] - public struct RenderBatch - { - int buffersCount; // Number of vertex buffers (multi-buffering support) - int currentBuffer; // Current buffer tracking in case of multi-buffering - IntPtr vertexBuffer; // Dynamic buffer(s) for vertex data - - IntPtr draws; // Draw calls array, depends on textureId - int drawsCounter; // Draw calls counter - float currentDepth; // Current depth value for next draw - } - - public enum GlVersion - { - OPENGL_11 = 1, - OPENGL_21, - OPENGL_33, - OPENGL_ES_20 - } - - public enum FramebufferAttachType - { - RL_ATTACHMENT_COLOR_CHANNEL0 = 0, - RL_ATTACHMENT_COLOR_CHANNEL1, - RL_ATTACHMENT_COLOR_CHANNEL2, - RL_ATTACHMENT_COLOR_CHANNEL3, - RL_ATTACHMENT_COLOR_CHANNEL4, - RL_ATTACHMENT_COLOR_CHANNEL5, - RL_ATTACHMENT_COLOR_CHANNEL6, - RL_ATTACHMENT_COLOR_CHANNEL7, - RL_ATTACHMENT_DEPTH = 100, - RL_ATTACHMENT_STENCIL = 200, - } - - public enum FramebufferAttachTextureType - { - RL_ATTACHMENT_CUBEMAP_POSITIVE_X = 0, - RL_ATTACHMENT_CUBEMAP_NEGATIVE_X, - RL_ATTACHMENT_CUBEMAP_POSITIVE_Y, - RL_ATTACHMENT_CUBEMAP_NEGATIVE_Y, - RL_ATTACHMENT_CUBEMAP_POSITIVE_Z, - RL_ATTACHMENT_CUBEMAP_NEGATIVE_Z, - RL_ATTACHMENT_TEXTURE2D = 100, - RL_ATTACHMENT_RENDERBUFFER = 200, - } - [SuppressUnmanagedCodeSecurity] public static class Rlgl { @@ -99,6 +52,22 @@ namespace Raylib_cs public const int RL_UNSIGNED_BYTE = 0x1401; public const int RL_FLOAT = 0x1406; + // Buffer usage hint + public const int RL_STREAM_DRAW = 0x88E0; + public const int RL_STREAM_READ = 0x88E1; + public const int RL_STREAM_COPY = 0x88E2; + public const int RL_STATIC_DRAW = 0x88E4; + public const int RL_STATIC_READ = 0x88E5; + public const int RL_STATIC_COPY = 0x88E6; + public const int RL_DYNAMIC_DRAW = 0x88E8; + public const int RL_DYNAMIC_READ = 0x88E9; + public const int RL_DYNAMIC_COPY = 0x88EA; + + // GL Shader type + public const int RL_FRAGMENT_SHADER = 0x8B30; + public const int RL_VERTEX_SHADER = 0x8B31; + public const int RL_COMPUTE_SHADER = 0x91B9; + // ------------------------------------------------------------------------------------ // Functions Declaration - Matrix operations // ------------------------------------------------------------------------------------ @@ -125,7 +94,7 @@ namespace Raylib_cs /// Multiply the current matrix by a rotation matrix [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void rlRotatef(float angleDeg, float x, float y, float z); + public static extern void rlRotatef(float angle, float x, float y, float z); /// Multiply the current matrix by a scaling matrix [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -133,7 +102,7 @@ namespace Raylib_cs /// Multiply the current matrix by another matrix [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void rlMultMatrixf(ref float[] matf); + public static extern void rlMultMatrixf(float[] matf); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void rlFrustum(double left, double right, double bottom, double top, double znear, double zfar); @@ -230,6 +199,17 @@ namespace Raylib_cs [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void rlDisableVertexAttribute(uint index); + /// Enable attribute state pointer
+ /// buffer refers to a void *
+ /// NOTE: Only available for GRAPHICS_API_OPENGL_11
+ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern void rlEnableStatePointer(int vertexAttribType, IntPtr buffer); + + /// Disable attribute state pointer
+ /// NOTE: Only available for GRAPHICS_API_OPENGL_11
+ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern void rlDisableStatePointer(int vertexAttribType); + // Textures state @@ -279,9 +259,21 @@ namespace Raylib_cs [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void rlDisableFramebuffer(); + /// Activate multiple draw color buffers + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern void rlActiveDrawBuffers(int count); + // General render state + /// Enable color blending + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern void rlEnableColorBlend(); + + /// Disable color blending + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern void rlDisableColorBlend(); + /// Enable depth test [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void rlEnableDepthTest(); @@ -368,7 +360,7 @@ namespace Raylib_cs /// Set blending mode [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void rlSetBlendMode(int mode); + public static extern void rlSetBlendMode(BlendMode mode); /// Set blending mode factor and equation (using OpenGL factors) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -387,12 +379,12 @@ namespace Raylib_cs [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void rlglClose(); - /// Load OpenGL extensions - /// loader refers to a void * + /// Load OpenGL extensions
+ /// loader refers to a void *
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void rlLoadExtensions(IntPtr loader); - /// Returns current OpenGL version + /// Get current OpenGL version [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern GlVersion rlGetVersion(); @@ -404,18 +396,23 @@ namespace Raylib_cs [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int rlGetFramebufferHeight(); - /// Get default shader - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern Shader rlGetShaderDefault(); - /// Get default texture [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern Texture2D rlGetTextureDefault(); + public static extern uint rlGetTextureIdDefault(); + /// Get default shader + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern uint rlGetShaderIdDefault(); + + /// Get default shader locations + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static unsafe extern int* rlGetShaderLocsDefault(); // Render batch management - /// Load a render batch system + /// Load a render batch system
+ /// NOTE: rlgl provides a default render batch to behave like OpenGL 1.1 immediate mode
+ /// but this render batch API is exposed in case custom batches are required
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern RenderBatch rlLoadRenderBatch(int numBuffers, int bufferElements); @@ -460,7 +457,7 @@ namespace Raylib_cs /// Update GPU buffer with new data [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void rlUpdateVertexBuffer(int bufferId, IntPtr data, int dataSize, int offset); + public static extern void rlUpdateVertexBuffer(uint bufferId, IntPtr data, int dataSize, int offset); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void rlUnloadVertexArray(uint vaoId); @@ -516,18 +513,22 @@ namespace Raylib_cs [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void rlGetGlTextureFormats(PixelFormat format, ref uint glInternalFormat, ref uint glFormat, ref uint glType); + /// Get OpenGL internal formats + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern IntPtr rlGetPixelFormatName(PixelFormat format); + /// Unload texture from GPU memory [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void rlUnloadTexture(uint id); /// Generate mipmap data for selected texture [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void rlGenerateMipmaps(ref Texture2D texture); + public static extern void rlGenTextureMipmaps(uint id, int width, int height, PixelFormat format, ref int[] mipmaps); /// Read texture pixel data
/// IntPtr refers to a void *
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr rlReadTexturePixels(Texture2D texture); + public static extern IntPtr rlReadTexturePixels(uint id, int width, int height, PixelFormat format); /// Read screen pixel data (color buffer)
/// IntPtr refers to a unsigned char *
@@ -560,7 +561,8 @@ namespace Raylib_cs [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern uint rlLoadShaderCode(string vsCode, string fsCode); - /// Compile custom shader and return shader id (type: GL_VERTEX_SHADER, GL_FRAGMENT_SHADER) + /// Compile custom shader and return shader id
+ /// (type: RL_VERTEX_SHADER, RL_FRAGMENT_SHADER, RL_COMPUTE_SHADER)
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern uint rlCompileShader(string shaderCode, int type); @@ -597,6 +599,52 @@ namespace Raylib_cs public static extern void rlSetShader(Shader shader); + // Compute shader management + + /// Load compute shader program + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern uint rlLoadComputeShaderProgram(uint shaderId); + + /// Dispatch compute shader (equivalent to *draw* for graphics pilepine) + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern void rlComputeShaderDispatch(uint groupX, uint groupY, uint groupZ); + + /// Load shader storage buffer object (SSBO) + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern unsafe uint rlLoadShaderBuffer(ulong size, void* data, int usageHint); + + /// Unload shader storage buffer object (SSBO) + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern void rlUnloadShaderBuffer(uint ssboId); + + /// Update SSBO buffer data + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern void rlUpdateShaderBufferElements(Shader shader); + + /// Get SSBO buffer size + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern unsafe ulong rlGetShaderBufferSize(uint id, void* dest, ulong count, ulong offset); + + /// Bind SSBO buffer + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern unsafe void rlReadShaderBufferElements(uint id, void* dest, ulong count, ulong offset); + + /// Copy SSBO buffer data + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern void rlBindShaderBuffer(uint id, uint index); + + + // Buffer management + + /// Copy SSBO buffer data + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern void rlCopyBuffersElements(uint destId, uint srcId, ulong destOffset, ulong srcOffset, ulong count); + + /// Bind image texture + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern void rlBindImageTexture(uint id, uint index, uint format, int readOnly); + + // Matrix state management /// Get internal modelview matrix diff --git a/Raylib-cs/types/RenderBatch.cs b/Raylib-cs/types/RenderBatch.cs new file mode 100644 index 0000000..e3e3c05 --- /dev/null +++ b/Raylib-cs/types/RenderBatch.cs @@ -0,0 +1,148 @@ +using System; +using System.Runtime.InteropServices; + +namespace Raylib_cs +{ + /// + /// RenderBatch type + /// + [StructLayout(LayoutKind.Sequential)] + public struct RenderBatch + { + /// + /// Number of vertex buffers (multi-buffering support) + /// + int buffersCount; + + /// + /// Current buffer tracking in case of multi-buffering + /// + int currentBuffer; + + /// + /// Dynamic buffer(s) for vertex data + /// + IntPtr vertexBuffer; + + /// + /// Draw calls array, depends on textureId + /// + IntPtr draws; + + /// + /// Draw calls counter + /// + int drawsCounter; + + /// + /// Current depth value for next draw + /// + float currentDepth; + } + + /// + /// Dynamic vertex buffers (position + texcoords + colors + indices arrays) + /// + [StructLayout(LayoutKind.Sequential)] + public unsafe struct VertexBuffer + { + /// + /// Number of elements in the buffer (QUADS) + /// + public int elementCount; + + /// + /// Vertex position (XYZ - 3 components per vertex) (shader-location = 0, float *) + /// + public IntPtr vertices; + + /// + /// Vertex texture coordinates (UV - 2 components per vertex) (shader-location = 1, float *) + /// + public IntPtr texcoords; + + /// + /// Vertex colors (RGBA - 4 components per vertex) (shader-location = 3, unsigned char *) + /// + public IntPtr colors; + + /// + /// Vertex indices (in case vertex data comes indexed) (6 indices per quad)
+ /// unsigned int * for GRAPHICS_API_OPENGL_11 or GRAPHICS_API_OPENGL_33
+ /// unsigned short * for GRAPHICS_API_OPENGL_ES2 + ///
+ public IntPtr indices; + + /// + /// OpenGL Vertex Array Object id + /// + public uint vaoId; + + /// + /// OpenGL Vertex Buffer Objects id (4 types of vertex data) + /// + public fixed uint vboId[4]; + } + + /// + /// Dynamic vertex buffers (position + texcoords + colors + indices arrays) + /// + [StructLayout(LayoutKind.Sequential)] + public struct DrawCall + { + /// + /// Drawing mode: LINES, TRIANGLES, QUADS + /// + int mode; + + /// + /// Number of vertices for the draw call + /// + int vertexCount; + + /// + /// Number of vertices required for index alignment (LINES, TRIANGLES) + /// + int vertexAlignment; + + /// + /// Texture id to be used on the draw -> Use to create new draw call if changes + /// + uint textureId; + } + + public enum GlVersion + { + OPENGL_11 = 1, + OPENGL_21, + OPENGL_33, + OPENGL_43, + OPENGL_ES_20 + } + + public enum FramebufferAttachType + { + RL_ATTACHMENT_COLOR_CHANNEL0 = 0, + RL_ATTACHMENT_COLOR_CHANNEL1, + RL_ATTACHMENT_COLOR_CHANNEL2, + RL_ATTACHMENT_COLOR_CHANNEL3, + RL_ATTACHMENT_COLOR_CHANNEL4, + RL_ATTACHMENT_COLOR_CHANNEL5, + RL_ATTACHMENT_COLOR_CHANNEL6, + RL_ATTACHMENT_COLOR_CHANNEL7, + RL_ATTACHMENT_DEPTH = 100, + RL_ATTACHMENT_STENCIL = 200, + } + + public enum FramebufferAttachTextureType + { + RL_ATTACHMENT_CUBEMAP_POSITIVE_X = 0, + RL_ATTACHMENT_CUBEMAP_NEGATIVE_X, + RL_ATTACHMENT_CUBEMAP_POSITIVE_Y, + RL_ATTACHMENT_CUBEMAP_NEGATIVE_Y, + RL_ATTACHMENT_CUBEMAP_POSITIVE_Z, + RL_ATTACHMENT_CUBEMAP_NEGATIVE_Z, + RL_ATTACHMENT_TEXTURE2D = 100, + RL_ATTACHMENT_RENDERBUFFER = 200, + } +} From f9e39d322653b0ea553835db2765bde9b82da385 Mon Sep 17 00:00:00 2001 From: ChrisDill Date: Thu, 11 Nov 2021 12:00:42 +0000 Subject: [PATCH 07/14] More XmlDoc comments --- Raylib-cs/types/Camera.cs | 8 ++++++-- Raylib-cs/types/Core.cs | 18 ++++++++++++------ Raylib-cs/types/Font.cs | 4 +++- Raylib-cs/types/Input.cs | 20 +++++++++++++++----- Raylib-cs/types/Material.cs | 14 ++++++++------ Raylib-cs/types/NPatchInfo.cs | 4 +++- Raylib-cs/types/Shader.cs | 12 +++++++++--- Raylib-cs/types/Texture2D.cs | 10 +++++++--- 8 files changed, 63 insertions(+), 27 deletions(-) diff --git a/Raylib-cs/types/Camera.cs b/Raylib-cs/types/Camera.cs index c51ba46..5b716a1 100644 --- a/Raylib-cs/types/Camera.cs +++ b/Raylib-cs/types/Camera.cs @@ -38,7 +38,9 @@ namespace Raylib_cs } } - /// Camera system modes + /// + /// Camera system modes + /// public enum CameraMode { CAMERA_CUSTOM = 0, @@ -48,7 +50,9 @@ namespace Raylib_cs CAMERA_THIRD_PERSON } - /// Camera projection + /// + /// Camera projection + /// public enum CameraProjection { CAMERA_PERSPECTIVE = 0, diff --git a/Raylib-cs/types/Core.cs b/Raylib-cs/types/Core.cs index b3eba85..5cfba6c 100644 --- a/Raylib-cs/types/Core.cs +++ b/Raylib-cs/types/Core.cs @@ -2,9 +2,11 @@ using System; namespace Raylib_cs { - /// System config flags - /// NOTE: Every bit registers one state (use it with bit masks) - /// By default all flags are set to 0 + /// + /// System config flags
+ /// NOTE: Every bit registers one state (use it with bit masks)
+ /// By default all flags are set to 0 + ///
[Flags] public enum ConfigFlags { @@ -79,8 +81,10 @@ namespace Raylib_cs FLAG_INTERLACED_HINT = 0x00010000, } - /// Trace log level - /// NOTE: Organized by priority level + /// + /// Trace log level
+ /// NOTE: Organized by priority level + ///
public enum TraceLogLevel { /// @@ -124,7 +128,9 @@ namespace Raylib_cs LOG_NONE } - /// Color blending modes (pre-defined) + /// + /// Color blending modes (pre-defined) + /// public enum BlendMode { /// diff --git a/Raylib-cs/types/Font.cs b/Raylib-cs/types/Font.cs index 7917202..b559315 100644 --- a/Raylib-cs/types/Font.cs +++ b/Raylib-cs/types/Font.cs @@ -3,7 +3,9 @@ using System.Runtime.InteropServices; namespace Raylib_cs { - /// Font type, defines generation method + /// + /// Font type, defines generation method + /// public enum FontType { /// diff --git a/Raylib-cs/types/Input.cs b/Raylib-cs/types/Input.cs index ca03fdf..8ab79ee 100644 --- a/Raylib-cs/types/Input.cs +++ b/Raylib-cs/types/Input.cs @@ -133,7 +133,9 @@ namespace Raylib_cs KEY_VOLUME_DOWN = 25 } - /// Mouse buttons + /// + /// Mouse buttons + /// public enum MouseButton { /// @@ -176,7 +178,9 @@ namespace Raylib_cs MOUSE_MIDDLE_BUTTON = MOUSE_BUTTON_MIDDLE, } - /// Mouse cursor + /// + /// Mouse cursor + /// public enum MouseCursor { /// @@ -269,7 +273,9 @@ namespace Raylib_cs GAMEPAD_AXIS_RIGHT_TRIGGER = 5 } - /// Gamepad buttons + /// + /// Gamepad buttons + /// public enum GamepadButton { /// @@ -371,7 +377,9 @@ namespace Raylib_cs GESTURE_PINCH_OUT = 512 } - /// Head-Mounted-Display device parameters + /// + /// Head-Mounted-Display device parameters + /// [StructLayout(LayoutKind.Sequential)] public unsafe struct VrDeviceInfo { @@ -426,7 +434,9 @@ namespace Raylib_cs public fixed float chromaAbCorrection[4]; } - /// VR Stereo rendering configuration for simulator + /// + /// VR Stereo rendering configuration for simulator + /// [StructLayout(LayoutKind.Sequential)] public struct VrStereoConfig { diff --git a/Raylib-cs/types/Material.cs b/Raylib-cs/types/Material.cs index 2252fe6..3c07e81 100644 --- a/Raylib-cs/types/Material.cs +++ b/Raylib-cs/types/Material.cs @@ -3,21 +3,23 @@ using System.Runtime.InteropServices; namespace Raylib_cs { - /// Material map index + /// + /// Material map index + /// public enum MaterialMapIndex { /// - /// MAP_DIFFUSE + /// NOTE: Same as MATERIAL_MAP_DIFFUSE /// MATERIAL_MAP_ALBEDO = 0, /// - /// MAP_SPECULAR + /// NOTE: Same as MATERIAL_MAP_SPECULAR /// - MATERIAL_MAP_METALNESS = 1, + MATERIAL_MAP_METALNESS, - MATERIAL_MAP_NORMAL = 2, - MATERIAL_MAP_ROUGHNESS = 3, + MATERIAL_MAP_NORMAL, + MATERIAL_MAP_ROUGHNESS, MATERIAL_MAP_OCCLUSION, MATERIAL_MAP_EMISSION, MATERIAL_MAP_HEIGHT, diff --git a/Raylib-cs/types/NPatchInfo.cs b/Raylib-cs/types/NPatchInfo.cs index d44f9ae..c5dfad6 100644 --- a/Raylib-cs/types/NPatchInfo.cs +++ b/Raylib-cs/types/NPatchInfo.cs @@ -2,7 +2,9 @@ using System.Runtime.InteropServices; namespace Raylib_cs { - /// N-patch layout + /// + /// N-patch layout + /// public enum NPatchLayout { /// diff --git a/Raylib-cs/types/Shader.cs b/Raylib-cs/types/Shader.cs index 9b520a9..f82192a 100644 --- a/Raylib-cs/types/Shader.cs +++ b/Raylib-cs/types/Shader.cs @@ -3,7 +3,9 @@ using System.Runtime.InteropServices; namespace Raylib_cs { - /// Shader location index + /// + /// Shader location index + /// public enum ShaderLocationIndex { SHADER_LOC_VERTEX_POSITION = 0, @@ -37,7 +39,9 @@ namespace Raylib_cs SHADER_LOC_MAP_SPECULAR = SHADER_LOC_MAP_METALNESS, } - // Shader attribute data types + /// + /// Shader attribute data types + /// public enum ShaderAttributeDataType { SHADER_ATTRIB_FLOAT = 0, @@ -46,7 +50,9 @@ namespace Raylib_cs SHADER_ATTRIB_VEC4 } - /// Shader uniform data type + /// + /// Shader uniform data type + /// public enum ShaderUniformDataType { SHADER_UNIFORM_FLOAT = 0, diff --git a/Raylib-cs/types/Texture2D.cs b/Raylib-cs/types/Texture2D.cs index 7315b6a..915af28 100644 --- a/Raylib-cs/types/Texture2D.cs +++ b/Raylib-cs/types/Texture2D.cs @@ -40,7 +40,9 @@ namespace Raylib_cs TEXTURE_FILTER_ANISOTROPIC_16X, } - /// Texture parameters: wrap mode + /// + /// Texture parameters: wrap mode + /// public enum TextureWrap { /// @@ -64,7 +66,9 @@ namespace Raylib_cs TEXTURE_WRAP_MIRROR_CLAMP } - /// Cubemap layouts + /// + /// Cubemap layouts + /// public enum CubemapLayout { /// @@ -99,7 +103,7 @@ namespace Raylib_cs } /// - /// Texture2D type
+ /// Texture2D type
/// NOTE: Data stored in GPU memory ///
[StructLayout(LayoutKind.Sequential)] From bb7ceb21020c646fd4618e194d46e96bc11eab0e Mon Sep 17 00:00:00 2001 From: ChrisDill Date: Thu, 11 Nov 2021 12:00:42 +0000 Subject: [PATCH 08/14] Use CBool in structs --- Raylib-cs/types/Audio.cs | 2 +- Raylib-cs/types/Shapes.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Raylib-cs/types/Audio.cs b/Raylib-cs/types/Audio.cs index 5f14236..2f68020 100644 --- a/Raylib-cs/types/Audio.cs +++ b/Raylib-cs/types/Audio.cs @@ -100,7 +100,7 @@ namespace Raylib_cs /// /// Music looping enable /// - public byte looping; + public CBool looping; /// /// Type of music context (audio filetype) diff --git a/Raylib-cs/types/Shapes.cs b/Raylib-cs/types/Shapes.cs index 07a292c..b403521 100644 --- a/Raylib-cs/types/Shapes.cs +++ b/Raylib-cs/types/Shapes.cs @@ -76,7 +76,7 @@ namespace Raylib_cs /// /// Did the ray hit something? /// - public byte hit; + public CBool hit; /// /// Distance to nearest hit From e5400d0baea4560537472ccc9876b432a6bce909 Mon Sep 17 00:00:00 2001 From: ChrisDill Date: Thu, 11 Nov 2021 12:00:42 +0000 Subject: [PATCH 09/14] Big unsafe update 1 --- Raylib-cs/Raylib.cs | 14 ++++----- Raylib-cs/RaylibUtils.cs | 56 +++++++++++++++------------------- Raylib-cs/types/Audio.cs | 14 ++++----- Raylib-cs/types/Font.cs | 6 ++-- Raylib-cs/types/Image.cs | 6 ++-- Raylib-cs/types/Material.cs | 10 +++--- Raylib-cs/types/Mesh.cs | 48 ++++++++++++++--------------- Raylib-cs/types/Model.cs | 22 ++++++------- Raylib-cs/types/RenderBatch.cs | 24 +++++++-------- Raylib-cs/types/Shader.cs | 4 +-- 10 files changed, 97 insertions(+), 107 deletions(-) diff --git a/Raylib-cs/Raylib.cs b/Raylib-cs/Raylib.cs index 1c5094e..14f0306 100644 --- a/Raylib-cs/Raylib.cs +++ b/Raylib-cs/Raylib.cs @@ -6,7 +6,7 @@ using System.Security; namespace Raylib_cs { [SuppressUnmanagedCodeSecurity] - public static class Raylib + public static unsafe class Raylib { /// /// Used by DllImport to load the native library. @@ -384,15 +384,13 @@ namespace Raylib_cs [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int GetShaderLocationAttrib(Shader shader, string attribName); - /// Set shader uniform value
- /// refers to a const void *
+ /// Set shader uniform value [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void SetShaderValue(Shader shader, int uniformLoc, IntPtr value, ShaderUniformDataType uniformType); + public static extern void SetShaderValue(Shader shader, int uniformLoc, void* value, ShaderUniformDataType uniformType); - /// Set shader uniform value vector
- /// value refers to a const void *
+ /// Set shader uniform value vector [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void SetShaderValueV(Shader shader, int uniformLoc, IntPtr value, ShaderUniformDataType uniformType, int count); + public static extern void SetShaderValueV(Shader shader, int uniformLoc, void* value, ShaderUniformDataType uniformType, int count); /// Set shader uniform value (matrix 4x4) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -546,7 +544,7 @@ namespace Raylib_cs /// Get dropped files names (memory should be freed) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern unsafe byte** GetDroppedFiles(int* count); + public static extern byte** GetDroppedFiles(int* count); /// Clear dropped files paths buffer (free memory) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] diff --git a/Raylib-cs/RaylibUtils.cs b/Raylib-cs/RaylibUtils.cs index 741b7a2..e90e44c 100644 --- a/Raylib-cs/RaylibUtils.cs +++ b/Raylib-cs/RaylibUtils.cs @@ -33,20 +33,20 @@ namespace Raylib_cs /// /// Utility functions for parts of the api that are not easy to interact with via pinvoke. /// - public static class Utils + public static unsafe class Utils { public static string SubText(this string input, int position, int length) { return input.Substring(position, Math.Min(length, input.Length)); } - public static unsafe string[] GetDroppedFiles() + public static string[] GetDroppedFiles() { int count; var buffer = Raylib.GetDroppedFiles(&count); var files = new string[count]; - for (int i = 0; i < count; i++) + for (var i = 0; i < count; i++) { files[i] = Marshal.PtrToStringUTF8((IntPtr)buffer[i]); } @@ -56,67 +56,59 @@ namespace Raylib_cs return files; } - public unsafe static Material GetMaterial(ref Model model, int materialIndex) + public static Material GetMaterial(ref Model model, int materialIndex) { - Material* materials = (Material*)model.materials.ToPointer(); - return *materials; + return model.materials[materialIndex]; } - public unsafe static Texture2D GetMaterialTexture(ref Model model, int materialIndex, MaterialMapIndex mapIndex) + public static Texture2D GetMaterialTexture(ref Model model, int materialIndex, MaterialMapIndex mapIndex) { - Material* materials = (Material*)model.materials.ToPointer(); - MaterialMap* maps = (MaterialMap*)materials[0].maps.ToPointer(); - return maps[(int)mapIndex].texture; + return model.materials[materialIndex].maps[(int)mapIndex].texture; } - public unsafe static void SetMaterialTexture(ref Model model, int materialIndex, MaterialMapIndex mapIndex, ref Texture2D texture) + public static void SetMaterialTexture(ref Model model, int materialIndex, MaterialMapIndex mapIndex, ref Texture2D texture) { - Material* materials = (Material*)model.materials.ToPointer(); - Raylib.SetMaterialTexture(ref materials[materialIndex], (int)mapIndex, texture); + Raylib.SetMaterialTexture(ref model.materials[materialIndex], (int)mapIndex, texture); } - public unsafe static void SetMaterialShader(ref Model model, int materialIndex, ref Shader shader) + public static void SetMaterialShader(ref Model model, int materialIndex, ref Shader shader) { - Material* materials = (Material*)model.materials.ToPointer(); - materials[materialIndex].shader = shader; + model.materials[materialIndex].shader = shader; } - public static unsafe void SetShaderValueV(Shader shader, int uniformLoc, T[] values, ShaderUniformDataType uniformType, int count) where T : unmanaged + public static void SetShaderValueV(Shader shader, int uniformLoc, T[] values, ShaderUniformDataType uniformType, int count) + where T : unmanaged { SetShaderValueV(shader, uniformLoc, (Span)values, uniformType, count); } - public static unsafe void SetShaderValueV(Shader shader, int uniformLoc, Span values, ShaderUniformDataType uniformType, int count) where T : unmanaged + public static void SetShaderValueV(Shader shader, int uniformLoc, Span values, ShaderUniformDataType uniformType, int count) + where T : unmanaged { fixed (T* valuePtr = values) { - Raylib.SetShaderValueV(shader, uniformLoc, (IntPtr)valuePtr, uniformType, count); + Raylib.SetShaderValueV(shader, uniformLoc, valuePtr, uniformType, count); } } - public static unsafe void SetShaderValue(Shader shader, int uniformLoc, ref T value, ShaderUniformDataType uniformType, int count = 0) where T : unmanaged + public static void SetShaderValue(Shader shader, int uniformLoc, T value, ShaderUniformDataType uniformType) + where T : unmanaged { - fixed (T* valuePtr = &value) - { - Raylib.SetShaderValue(shader, uniformLoc, (IntPtr)valuePtr, uniformType); - } + Raylib.SetShaderValue(shader, uniformLoc, &value, uniformType); } - public static unsafe void SetShaderValue(Shader shader, int uniformLoc, T value, ShaderUniformDataType uniformType) where T : unmanaged - { - Raylib.SetShaderValue(shader, uniformLoc, (IntPtr)(&value), uniformType); - } - - public static unsafe void SetShaderValue(Shader shader, int uniformLoc, T[] values, ShaderUniformDataType uniformType) where T : unmanaged + public static void SetShaderValue(Shader shader, int uniformLoc, T[] values, ShaderUniformDataType uniformType) + where T : unmanaged { SetShaderValue(shader, uniformLoc, (Span)values, uniformType); } - public static unsafe void SetShaderValue(Shader shader, int uniformLoc, Span values, ShaderUniformDataType uniformType) where T : unmanaged + public static void SetShaderValue(Shader shader, int uniformLoc, Span values, ShaderUniformDataType uniformType) + where T : unmanaged { fixed (T* valuePtr = values) { - Raylib.SetShaderValue(shader, uniformLoc, (IntPtr)valuePtr, uniformType); + Raylib.SetShaderValue(shader, uniformLoc, valuePtr, uniformType); } } } diff --git a/Raylib-cs/types/Audio.cs b/Raylib-cs/types/Audio.cs index 2f68020..83a601c 100644 --- a/Raylib-cs/types/Audio.cs +++ b/Raylib-cs/types/Audio.cs @@ -7,7 +7,7 @@ namespace Raylib_cs /// Wave type, defines audio wave data ///
[StructLayout(LayoutKind.Sequential)] - public struct Wave + public unsafe struct Wave { /// /// Number of samples @@ -30,9 +30,9 @@ namespace Raylib_cs public uint channels; /// - /// Buffer data pointer (void *) + /// Buffer data pointer /// - public IntPtr data; + public void* data; } /// @@ -45,7 +45,7 @@ namespace Raylib_cs /// /// Pointer to internal data(rAudioBuffer *) used by the audio system /// - public IntPtr audioBuffer; + public IntPtr buffer; /// /// Frequency (samples per second) @@ -85,7 +85,7 @@ namespace Raylib_cs /// NOTE: Anything longer than ~10 seconds should be streamed /// [StructLayout(LayoutKind.Sequential)] - public struct Music + public unsafe struct Music { /// /// Audio stream @@ -108,8 +108,8 @@ namespace Raylib_cs public int ctxType; /// - /// Audio context data, depends on type (void *) + /// Audio context data, depends on type /// - public IntPtr ctxData; + public void* ctxData; } } diff --git a/Raylib-cs/types/Font.cs b/Raylib-cs/types/Font.cs index b559315..f9cc4c9 100644 --- a/Raylib-cs/types/Font.cs +++ b/Raylib-cs/types/Font.cs @@ -60,7 +60,7 @@ namespace Raylib_cs /// Font, font texture and GlyphInfo array data /// [StructLayout(LayoutKind.Sequential)] - public struct Font + public unsafe struct Font { /// /// Base size (default chars height) @@ -85,11 +85,11 @@ namespace Raylib_cs /// /// Rectangles in texture for the glyphs /// - public IntPtr recs; + public Rectangle* recs; /// /// Glyphs info data /// - public IntPtr glyphs; + public GlyphInfo* glyphs; } } diff --git a/Raylib-cs/types/Image.cs b/Raylib-cs/types/Image.cs index 271cc55..f60c114 100644 --- a/Raylib-cs/types/Image.cs +++ b/Raylib-cs/types/Image.cs @@ -119,12 +119,12 @@ namespace Raylib_cs /// Image, pixel data stored in CPU memory (RAM) /// [StructLayout(LayoutKind.Sequential)] - public struct Image + public unsafe struct Image { /// - /// Image raw data (void *) + /// Image raw data /// - public IntPtr data; + public void* data; /// /// Image base width diff --git a/Raylib-cs/types/Material.cs b/Raylib-cs/types/Material.cs index 3c07e81..1d82983 100644 --- a/Raylib-cs/types/Material.cs +++ b/Raylib-cs/types/Material.cs @@ -71,7 +71,7 @@ namespace Raylib_cs /// Material type (generic) /// [StructLayout(LayoutKind.Sequential)] - public struct Material + public unsafe struct Material { /// /// Material shader @@ -79,13 +79,13 @@ namespace Raylib_cs public Shader shader; /// - /// Material maps (MaterialMap *) + /// Material maps /// - public IntPtr maps; + public MaterialMap *maps; /// - /// Material generic parameters (if required, float *) + /// Material generic parameters (if required) /// - public IntPtr param; + public float *param; } } diff --git a/Raylib-cs/types/Mesh.cs b/Raylib-cs/types/Mesh.cs index 6c29141..910dad7 100644 --- a/Raylib-cs/types/Mesh.cs +++ b/Raylib-cs/types/Mesh.cs @@ -31,7 +31,7 @@ namespace Raylib_cs /// NOTE: Data stored in CPU memory (and GPU) /// [StructLayout(LayoutKind.Sequential)] - public struct Mesh + public unsafe struct Mesh { /// /// Number of vertices stored in arrays @@ -46,63 +46,63 @@ namespace Raylib_cs #region Default vertex data /// - /// Vertex position (XYZ - 3 components per vertex) (shader-location = 0, float *) + /// Vertex position (XYZ - 3 components per vertex) (shader-location = 0) /// - public IntPtr vertices; + public float* vertices; /// - /// Vertex texture coordinates (UV - 2 components per vertex) (shader-location = 1, float *) + /// Vertex texture coordinates (UV - 2 components per vertex) (shader-location = 1) /// - public IntPtr texcoords; + public float* texcoords; /// - /// Vertex second texture coordinates (useful for lightmaps) (shader-location = 5, float *) + /// Vertex second texture coordinates (useful for lightmaps) (shader-location = 5) /// - public IntPtr texcoords2; + public float* texcoords2; /// - /// Vertex normals (XYZ - 3 components per vertex) (shader-location = 2, float *) + /// Vertex normals (XYZ - 3 components per vertex) (shader-location = 2) /// - public IntPtr normals; + public float* normals; /// - /// Vertex tangents (XYZW - 4 components per vertex) (shader-location = 4, float *) + /// Vertex tangents (XYZW - 4 components per vertex) (shader-location = 4) /// - public IntPtr tangents; + public float* tangents; /// - /// Vertex colors (RGBA - 4 components per vertex) (shader-location = 3, unsigned char *) + /// Vertex colors (RGBA - 4 components per vertex) (shader-location = 3) /// - public IntPtr colors; + public byte* colors; /// - /// Vertex indices (in case vertex data comes indexed, unsigned short *) + /// Vertex indices (in case vertex data comes indexed) /// - public IntPtr indices; + public ushort* indices; #endregion #region Animation vertex data /// - /// Animated vertex positions (after bones transformations, float *) + /// Animated vertex positions (after bones transformations) /// - public IntPtr animVertices; + public float* animVertices; /// - /// Animated normals (after bones transformations, float *) + /// Animated normals (after bones transformations) /// - public IntPtr animNormals; + public float* animNormals; /// - /// Vertex bone ids, up to 4 bones influence by vertex (skinning, int *) + /// Vertex bone ids, up to 4 bones influence by vertex (skinning) /// - public IntPtr boneIds; + public byte* boneIds; /// - /// Vertex bone weight, up to 4 bones influence by vertex (skinning, float *) + /// Vertex bone weight, up to 4 bones influence by vertex (skinning) /// - public IntPtr boneWeights; + public float* boneWeights; #endregion @@ -116,7 +116,7 @@ namespace Raylib_cs /// /// OpenGL Vertex Buffer Objects id (default vertex data, uint[]) /// - public IntPtr vboId; + public uint* vboId; #endregion } diff --git a/Raylib-cs/types/Model.cs b/Raylib-cs/types/Model.cs index 91638d3..76c795d 100644 --- a/Raylib-cs/types/Model.cs +++ b/Raylib-cs/types/Model.cs @@ -8,12 +8,12 @@ namespace Raylib_cs /// Bone information /// [StructLayout(LayoutKind.Sequential)] - public struct BoneInfo + public unsafe struct BoneInfo { /// /// Bone name (char[32]) /// - public IntPtr name; + public fixed sbyte name[32]; /// /// Bone parent @@ -25,7 +25,7 @@ namespace Raylib_cs /// Model type /// [StructLayout(LayoutKind.Sequential)] - public struct Model + public unsafe struct Model { /// /// Local transform matrix @@ -45,17 +45,17 @@ namespace Raylib_cs /// /// Meshes array (Mesh *) /// - public IntPtr meshes; + public Mesh *meshes; /// /// Materials array (Material *) /// - public IntPtr materials; + public Material *materials; /// /// Mesh material number (int *) /// - public IntPtr meshMaterial; + public int *meshMaterial; /// /// Number of bones @@ -65,19 +65,19 @@ namespace Raylib_cs /// /// Bones information (skeleton, BoneInfo *) /// - public IntPtr bones; + public BoneInfo *bones; /// /// Bones base transformation (pose, Transform *) /// - public IntPtr bindPose; + public Transform *bindPose; } /// /// Model animation /// [StructLayout(LayoutKind.Sequential)] - public struct ModelAnimation + public unsafe struct ModelAnimation { /// /// Number of bones @@ -92,11 +92,11 @@ namespace Raylib_cs /// /// Bones information (skeleton, BoneInfo *) /// - public IntPtr bones; + public BoneInfo *bones; /// /// Poses array by frame (Transform **) /// - public IntPtr framePoses; + public Transform *framePoses; } } diff --git a/Raylib-cs/types/RenderBatch.cs b/Raylib-cs/types/RenderBatch.cs index e3e3c05..f4abc16 100644 --- a/Raylib-cs/types/RenderBatch.cs +++ b/Raylib-cs/types/RenderBatch.cs @@ -7,7 +7,7 @@ namespace Raylib_cs /// RenderBatch type /// [StructLayout(LayoutKind.Sequential)] - public struct RenderBatch + public unsafe struct RenderBatch { /// /// Number of vertex buffers (multi-buffering support) @@ -22,12 +22,12 @@ namespace Raylib_cs /// /// Dynamic buffer(s) for vertex data /// - IntPtr vertexBuffer; + VertexBuffer* vertexBuffer; /// /// Draw calls array, depends on textureId /// - IntPtr draws; + DrawCall* draws; /// /// Draw calls counter @@ -52,26 +52,26 @@ namespace Raylib_cs public int elementCount; /// - /// Vertex position (XYZ - 3 components per vertex) (shader-location = 0, float *) + /// Vertex position (XYZ - 3 components per vertex) (shader-location = 0) /// - public IntPtr vertices; + public float* vertices; /// - /// Vertex texture coordinates (UV - 2 components per vertex) (shader-location = 1, float *) + /// Vertex texture coordinates (UV - 2 components per vertex) (shader-location = 1) /// - public IntPtr texcoords; + public float* texcoords; /// - /// Vertex colors (RGBA - 4 components per vertex) (shader-location = 3, unsigned char *) + /// Vertex colors (RGBA - 4 components per vertex) (shader-location = 3) /// - public IntPtr colors; + public byte* colors; /// /// Vertex indices (in case vertex data comes indexed) (6 indices per quad)
- /// unsigned int * for GRAPHICS_API_OPENGL_11 or GRAPHICS_API_OPENGL_33
- /// unsigned short * for GRAPHICS_API_OPENGL_ES2 + /// unsigned int* for GRAPHICS_API_OPENGL_11 or GRAPHICS_API_OPENGL_33
+ /// unsigned short* for GRAPHICS_API_OPENGL_ES2 ///
- public IntPtr indices; + public void* indices; /// /// OpenGL Vertex Array Object id diff --git a/Raylib-cs/types/Shader.cs b/Raylib-cs/types/Shader.cs index f82192a..e79e9a7 100644 --- a/Raylib-cs/types/Shader.cs +++ b/Raylib-cs/types/Shader.cs @@ -70,7 +70,7 @@ namespace Raylib_cs /// Shader type (generic) /// [StructLayout(LayoutKind.Sequential)] - public struct Shader + public unsafe struct Shader { /// /// Shader program id @@ -80,6 +80,6 @@ namespace Raylib_cs /// /// Shader locations array (MAX_SHADER_LOCATIONS, int *) /// - public IntPtr locs; + public int* locs; } } From f578765e8e7bfa61cdf4b2955f1d4277947d2731 Mon Sep 17 00:00:00 2001 From: ChrisDill Date: Fri, 26 Nov 2021 07:32:07 +0000 Subject: [PATCH 10/14] Big unsafe update 2 --- Raylib-cs/Raylib.cs | 127 ++++++++---------- Raylib-cs/Raymath.cs | 309 ++++++++++++++++++++++++++----------------- Raylib-cs/Rlgl.cs | 65 +++++---- 3 files changed, 267 insertions(+), 234 deletions(-) diff --git a/Raylib-cs/Raylib.cs b/Raylib-cs/Raylib.cs index 14f0306..846a592 100644 --- a/Raylib-cs/Raylib.cs +++ b/Raylib-cs/Raylib.cs @@ -9,7 +9,7 @@ namespace Raylib_cs public static unsafe class Raylib { /// - /// Used by DllImport to load the native library. + /// Used by DllImport to load the native library /// public const string nativeLibName = "raylib"; @@ -163,10 +163,9 @@ namespace Raylib_cs [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SetWindowSize(int width, int height); - /// Get native window handle
- /// IntPtr refers to a void *
+ /// Get native window handle [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr GetWindowHandle(); + public static extern void* GetWindowHandle(); /// Get current screen width [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -483,15 +482,15 @@ namespace Raylib_cs /// Internal memory allocator [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr MemAlloc(int size); + public static extern void* MemAlloc(int size); /// Internal memory reallocator [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr MemRealloc(IntPtr ptr, int size); + public static extern void* MemRealloc(void* ptr, int size); /// Internal memory free [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void MemFree(IntPtr ptr); + public static extern void MemFree(void* ptr); // Set custom callbacks @@ -520,19 +519,17 @@ namespace Raylib_cs // Files management functions - /// Load file data as byte array (read)
- /// IntPtr refers to unsigned char *
+ /// Load file data as byte array (read) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr LoadFileData(string fileName, ref int bytesRead); + public static extern byte* LoadFileData(string fileName, ref int bytesRead); - /// Unload file data allocated by LoadFileData()
- /// data refers to a unsigned char *
+ /// Unload file data allocated by LoadFileData() [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void UnloadFileData(IntPtr data); + public static extern void UnloadFileData(byte* data); /// Save data to file from byte array (write) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern CBool SaveFileData(string fileName, IntPtr data, int bytesToWrite); + public static extern CBool SaveFileData(string fileName, void* data, int bytesToWrite); /// Check file extension [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -556,11 +553,11 @@ namespace Raylib_cs /// Compress data (DEFLATE algorythm) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr CompressData(byte[] data, int dataLength, ref int compDataLength); + public static extern byte* CompressData(byte[] data, int dataLength, ref int compDataLength); /// Decompress data (DEFLATE algorythm) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr DecompressData(byte[] compData, int compDataLength, ref int dataLength); + public static extern byte* DecompressData(byte[] compData, int compDataLength, ref int dataLength); // Persistent storage management @@ -1025,10 +1022,9 @@ namespace Raylib_cs [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Image LoadImageAnim(string fileName, ref int frames); - /// Load image from memory buffer, fileType refers to extension: i.e. "png"
- /// fileData refers to const unsigned char *
+ /// Load image from memory buffer, fileType refers to extension: i.e. "png" [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern Image LoadImageFromMemory(string fileType, IntPtr fileData, int dataSize); + public static extern Image LoadImageFromMemory(string fileType, byte* fileData, int dataSize); /// Load image from GPU texture data [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -1188,25 +1184,21 @@ namespace Raylib_cs [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void ImageColorReplace(ref Image image, Color color, Color replace); - /// Load color data from image as a Color array (RGBA - 32bit)
- /// IntPtr refers to Color *
+ /// Load color data from image as a Color array (RGBA - 32bit) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr LoadImageColors(Image image); + public static extern Color* LoadImageColors(Image image); - /// Load colors palette from image as a Color array (RGBA - 32bit)
- /// IntPtr refers to Color *
+ /// Load colors palette from image as a Color array (RGBA - 32bit) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr LoadImagePaletee(Image image, int maxPaletteSize, ref int colorsCount); + public static extern Color* LoadImagePalette(Image image, int maxPaletteSize, ref int colorsCount); - /// Unload color data loaded with LoadImageColors()
- /// colors refers to Color *
+ /// Unload color data loaded with LoadImageColors() [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void UnloadImageColors(IntPtr colors); + public static extern void UnloadImageColors(Color* colors); - /// Unload colors palette loaded with LoadImagePalette() - /// colors refers to Color * + /// Unload colors palette loaded with LoadImagePalette() [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void UnloadImagePaletee(IntPtr colors); + public static extern void UnloadImagePalette(Color* colors); /// Get image alpha border rectangle [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -1304,15 +1296,13 @@ namespace Raylib_cs [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void UnloadRenderTexture(RenderTexture2D target); - /// Update GPU texture with new data
- /// pixels refers to a const void *
+ /// Update GPU texture with new data [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void UpdateTexture(Texture2D texture, IntPtr pixels); + public static extern void UpdateTexture(Texture2D texture, void* pixels); - /// Update GPU texture rectangle with new data - /// pixels refers to a const void * + /// Update GPU texture rectangle with new data [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void UpdateTextureRec(Texture2D texture, Rectangle rec, IntPtr pixels); + public static extern void UpdateTextureRec(Texture2D texture, Rectangle rec, void* pixels); // Texture configuration functions @@ -1405,11 +1395,11 @@ namespace Raylib_cs /// Get Color from a source pixel pointer of certain format [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern Color GetPixelColor(IntPtr srcPtr, PixelFormat format); + public static extern Color GetPixelColor(void* srcPtr, PixelFormat format); /// Set color formatted into destination pixel pointer [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void SetPixelColor(IntPtr dstPtr, Color color, PixelFormat format); + public static extern void SetPixelColor(void* dstPtr, Color color, PixelFormat format); /// Get pixel data size in bytes for certain format [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -1441,22 +1431,19 @@ namespace Raylib_cs /// Load font from memory buffer, fileType refers to extension: i.e. "ttf"
/// fileData refers to const unsigned char *
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern Font LoadFontFromMemory(string fileType, IntPtr fileData, int dataSize, int fontSize, int[] fontChars, int charsCount); + public static extern Font LoadFontFromMemory(string fileType, byte* fileData, int dataSize, int fontSize, int[] fontChars, int charsCount); - /// Load font data for further use
- /// fileData refers to const unsigned char *
- /// IntPtr refers to GlyphInfo *
+ /// Load font data for further use [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr LoadFontData(IntPtr fileData, int dataSize, int fontSize, int[] fontChars, int charsCount, FontType type); + public static extern GlyphInfo* LoadFontData(byte* fileData, int dataSize, int fontSize, int[] fontChars, int charsCount, FontType type); /// Generate image font atlas using chars info [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern Image GenImageFontAtlas(IntPtr chars, ref IntPtr recs, int charsCount, int fontSize, int padding, int packMethod); + public static extern Image GenImageFontAtlas(GlyphInfo* chars, Rectangle** recs, int charsCount, int fontSize, int padding, int packMethod); - /// Unload font chars info data (RAM)
- /// chars refers to GlpyhInfo *
+ /// Unload font chars info data (RAM) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void UnloadFontData(IntPtr chars, int charsCount); + public static extern void UnloadFontData(GlyphInfo* chars, int charsCount); /// Unload Font from GPU memory (VRAM) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -1538,10 +1525,9 @@ namespace Raylib_cs // UTF8 text strings management functions - /// Get all codepoints in a string, codepoints count returned by parameters
- /// IntPtr refers to a int *
+ /// Get all codepoints in a string, codepoints count returned by parameters [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr GetCodepoints(string text, ref int count); + public static extern int* GetCodepoints(string text, ref int count); /// Get total number of characters (codepoints) in a UTF8 encoded string [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -1679,10 +1665,9 @@ namespace Raylib_cs [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void UploadMesh(ref Mesh mesh, CBool dynamic); - /// Update mesh vertex data in GPU for a specific buffer index
- /// data refers to a void *
+ /// Update mesh vertex data in GPU for a specific buffer index [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void UpdateMeshBuffer(Mesh mesh, int index, IntPtr data, int dataSize, int offset); + public static extern void UpdateMeshBuffer(Mesh mesh, int index, void* data, int dataSize, int offset); /// Unload mesh from memory (RAM and/or VRAM) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -1715,10 +1700,9 @@ namespace Raylib_cs // Material loading/unloading functions - /// Load materials from model file
- /// IntPtr refers to Material *
+ /// Load materials from model file [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr LoadMaterials(string fileName, ref int materialCount); + public static extern Material* LoadMaterials(string fileName, ref int materialCount); /// Load default material (Supports: DIFFUSE, SPECULAR, NORMAL maps) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -1819,10 +1803,9 @@ namespace Raylib_cs // Model animations loading/unloading functions - /// Load model animations from file
- /// IntPtr refers to ModelAnimation *
+ /// Load model animations from file [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr LoadModelAnimations(string fileName, ref int animsCount); + public static extern ModelAnimation* LoadModelAnimations(string fileName, ref int animsCount); /// Update model animation pose [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -1911,7 +1894,7 @@ namespace Raylib_cs /// Load wave from memory buffer, fileType refers to extension: i.e. "wav"
/// fileData refers to a const unsigned char *
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern Wave LoadWaveFromMemory(string fileType, IntPtr fileData, int dataSize); + public static extern Wave LoadWaveFromMemory(string fileType, byte* fileData, int dataSize); /// Load sound from file [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -1921,10 +1904,9 @@ namespace Raylib_cs [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Sound LoadSoundFromWave(Wave wave); - /// Update sound buffer with new data
- /// refers to a const void *
+ /// Update sound buffer with new data [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void UpdateSound(Sound sound, IntPtr data, int samplesCount); + public static extern void UpdateSound(Sound sound, void* data, int samplesCount); /// Unload wave data [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -1997,15 +1979,13 @@ namespace Raylib_cs [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void WaveCrop(ref Wave wave, int initSample, int finalSample); - /// Get samples data from wave as a floats array
- /// IntPtr refers to float *
+ /// Get samples data from wave as a floats array [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr LoadWaveSamples(Wave wave); + public static extern float* LoadWaveSamples(Wave wave); - /// Unload samples data loaded with LoadWaveSamples()
- /// samples refers to float *
+ /// Unload samples data loaded with LoadWaveSamples() [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void UnloadWaveSamples(IntPtr samples); + public static extern void UnloadWaveSamples(float* samples); // Music management functions @@ -2015,7 +1995,7 @@ namespace Raylib_cs /// Load music stream from data [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern Music LoadMusicStreamFromMemory(string fileType, IntPtr data, int dataSize); + public static extern Music LoadMusicStreamFromMemory(string fileType, byte* data, int dataSize); /// Unload music stream [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -2076,10 +2056,9 @@ namespace Raylib_cs [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void UnloadAudioStream(AudioStream stream); - /// Update audio stream buffers with data
- /// data refers to a const void *
+ /// Update audio stream buffers with data [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void UpdateAudioStream(AudioStream stream, IntPtr data, int samplesCount); + public static extern void UpdateAudioStream(AudioStream stream, void* data, int samplesCount); /// Check if any audio stream buffers requires refill [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] diff --git a/Raylib-cs/Raymath.cs b/Raylib-cs/Raymath.cs index b72ba71..d3c03ea 100644 --- a/Raylib-cs/Raymath.cs +++ b/Raylib-cs/Raymath.cs @@ -16,333 +16,392 @@ namespace Raylib_cs } [SuppressUnmanagedCodeSecurity] - public static class Raymath + public static unsafe class Raymath { - // Used by DllImport to load the native library. + /// + /// Used by DllImport to load the native library + /// public const string nativeLibName = "raylib"; - // Clamp float value + /// Clamp float value [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern float Clamp(float value, float min, float max); - // Calculate linear interpolation between two vectors + /// Calculate linear interpolation between two vectors [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern float Lerp(float start, float end, float amount); - // Vector with components value 0.0f + /// Normalize input value within input range + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern float Normalize(float value, float start, float end); + + /// Remap input value within input range to output range + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern float Remap(float value, float inputStart, float inputEnd, float outputStart, float outputEnd); + + + /// Vector with components value 0.0f [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Vector2 Vector2Zero(); - // Vector with components value 1.0f + /// Vector with components value 1.0f [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Vector2 Vector2One(); - // Add two vectors (v1 + v2) + /// Add two vectors (v1 + v2) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Vector2 Vector2Add(Vector2 v1, Vector2 v2); - // Subtract two vectors (v1 - v2) + /// Add vector and float value + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern Vector2 Vector2AddValue(Vector2 v, float add); + + /// Subtract two vectors (v1 - v2) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Vector2 Vector2Subtract(Vector2 v1, Vector2 v2); - // Calculate vector length + /// Subtract vector by float value + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern Vector2 Vector2SubtractValue(Vector2 v, float sub); + + /// Calculate vector length [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern float Vector2Length(Vector2 v); - // Calculate two vectors dot product + /// Calculate vector square length + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern float Vector2LengthSqr(Vector2 v); + + /// Calculate two vectors dot product [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern float Vector2DotProduct(Vector2 v1, Vector2 v2); - // Calculate distance between two vectors + /// Calculate distance between two vectors [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern float Vector2Distance(Vector2 v1, Vector2 v2); - // Calculate angle from two vectors in X-axis + /// Calculate angle from two vectors in X-axis [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern float Vector2Angle(Vector2 v1, Vector2 v2); - // Scale vector (multiply by value) + /// Scale vector (multiply by value) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Vector2 Vector2Scale(Vector2 v, float scale); - // Multiply vector by vector + /// Multiply vector by vector [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern Vector2 Vector2MultiplyV(Vector2 v1, Vector2 v2); + public static extern Vector2 Vector2Multiply(Vector2 v1, Vector2 v2); - // Negate vector + /// Negate vector [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Vector2 Vector2Negate(Vector2 v); - // Divide vector by a float value + /// Divide vector by vector [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern Vector2 Vector2Divide(Vector2 v, float div); + public static extern Vector2 Vector2Divide(Vector2 v1, Vector2 v2); - // Divide vector by vector - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern Vector2 Vector2DivideV(Vector2 v1, Vector2 v2); - - // Normalize provided vector + /// Normalize provided vector [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Vector2 Vector2Normalize(Vector2 v); - // Calculate linear interpolation between two vectors + /// Calculate linear interpolation between two vectors [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Vector2 Vector2Lerp(Vector2 v1, Vector2 v2, float amount); - // Calculate linear interpolation between two vectors + /// Calculate linear interpolation between two vectors [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Vector2 Vector2Rotate(Vector2 v, float degs); - // Vector with components value 0.0f + + /// Vector with components value 0.0f [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Vector3 Vector3Zero(); - // Vector with components value 1.0f + /// Vector with components value 1.0f [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Vector3 Vector3One(); - // Add two vectors + /// Add two vectors [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Vector3 Vector3Add(Vector3 v1, Vector3 v2); - // Subtract two vectors + /// Add vector and float value + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern Vector3 Vector3AddValue(Vector3 v, float add); + + /// Subtract two vectors [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Vector3 Vector3Subtract(Vector3 v1, Vector3 v2); - // Multiply vector by scalar + /// Subtract vector and float value + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern Vector3 Vector3SubtractValue(Vector3 v, float sub); + + /// Multiply vector by scalar [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Vector3 Vector3Scale(Vector3 v, float scalar); - // Multiply vector by vector + /// Multiply vector by vector [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Vector3 Vector3Multiply(Vector3 v1, Vector3 v2); - // Calculate two vectors cross product + /// Calculate two vectors cross product [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Vector3 Vector3CrossProduct(Vector3 v1, Vector3 v2); - // Calculate one vector perpendicular vector + /// Calculate one vector perpendicular vector [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Vector3 Vector3Perpendicular(Vector3 v); - // Calculate vector length + /// Calculate vector length [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern float Vector3Length(Vector3 v); - // Calculate two vectors dot product + /// Calculate vector square length + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern float Vector3LengthSqr(Vector3 v); + /// Calculate two vectors dot product [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern float Vector3DotProduct(Vector3 v1, Vector3 v2); - // Calculate distance between two vectors + /// Calculate distance between two vectors [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern float Vector3Distance(Vector3 v1, Vector3 v2); - // Negate provided vector (invert direction) + /// Calculate angle between two vectors in XY and XZ + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern Vector2 Vector3Angle(Vector3 v1, Vector3 v2); + + /// Negate provided vector (invert direction) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Vector3 Vector3Negate(Vector3 v); - // Divide vector by a float value + /// Divide vector by vector [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern Vector3 Vector3Divide(Vector3 v, float div); + public static extern Vector3 Vector3Divide(Vector3 v1, Vector3 v2); - // Divide vector by vector - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern Vector3 Vector3DivideV(Vector3 v1, Vector3 v2); - - // Normalize provided vector + /// Normalize provided vector [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Vector3 Vector3Normalize(Vector3 v); - // Orthonormalize provided vectors - // Makes vectors normalized and orthogonal to each other - // Gram-Schmidt function implementation + /// Orthonormalize provided vectors
+ /// Makes vectors normalized and orthogonal to each other
+ /// Gram-Schmidt function implementation
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void Vector3OrthoNormalize(ref Vector3 v1, ref Vector3 v2); + public static extern void Vector3OrthoNormalize(Vector3* v1, Vector3* v2); - // Transforms a Vector3 by a given Matrix + /// Transforms a Vector3 by a given Matrix [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Vector3 Vector3Transform(Vector3 v, Matrix4x4 mat); - // Transform a vector by quaternion rotation + /// Transform a vector by quaternion rotation [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Vector3 Vector3RotateByQuaternion(Vector3 v, Quaternion q); - // Calculate linear interpolation between two vectors + /// Calculate linear interpolation between two vectors [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Vector3 Vector3Lerp(Vector3 v1, Vector3 v2, float amount); - // Calculate reflected vector to normal + /// Calculate reflected vector to normal [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Vector3 Vector3Reflect(Vector3 v, Vector3 normal); - // Return min value for each pair of components + /// Return min value for each pair of components [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Vector3 Vector3Min(Vector3 v1, Vector3 v2); - // Return max value for each pair of components + /// Return max value for each pair of components [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Vector3 Vector3Max(Vector3 v1, Vector3 v2); - // Compute barycenter coordinates (u, v, w) for point p with respect to triangle (a, b, c) - // NOTE: Assumes P is on the plane of the triangle + /// Compute barycenter coordinates (u, v, w) for point p with respect to triangle (a, b, c)
+ /// NOTE: Assumes P is on the plane of the triangle
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Vector3 Vector3Barycenter(Vector3 p, Vector3 a, Vector3 b, Vector3 c); - // Returns Vector3 as float array + /// Projects a Vector3 from screen space into object space
+ /// NOTE: We are avoiding calling other raymath functions despite available
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern float3 Vector3ToFloatV(Vector3 v); + public static extern Vector3 Vector3Unproject(Vector3 source, Matrix4x4 projection, Matrix4x4 view); - // Compute matrix determinant + + /// Compute matrix determinant [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern float MatrixDeterminant(Matrix4x4 mat); - // Returns the trace of the matrix (sum of the values along the diagonal) + /// Get the trace of the matrix (sum of the values along the diagonal) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern float MatrixTrace(Matrix4x4 mat); - // Transposes provided matrix + /// Transposes provided matrix [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Matrix4x4 MatrixTranspose(Matrix4x4 mat); - // Invert provided matrix + /// Invert provided matrix [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Matrix4x4 MatrixInvert(Matrix4x4 mat); - // Normalize provided matrix + /// Normalize provided matrix [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Matrix4x4 MatrixNormalize(Matrix4x4 mat); - // Returns identity matrix + /// Get identity matrix [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Matrix4x4 MatrixIdentity(); - // Add two matrices + /// Add two matrices [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Matrix4x4 MatrixAdd(Matrix4x4 left, Matrix4x4 right); - // Subtract two matrices (left - right) + /// Subtract two matrices (left - right) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Matrix4x4 MatrixSubtract(Matrix4x4 left, Matrix4x4 right); - // Returns translation matrix - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern Matrix4x4 MatrixTranslate(float x, float y, float z); - - // Create rotation matrix from axis and angle - // NOTE: Angle should be provided in radians - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern Matrix4x4 MatrixRotate(Vector3 axis, float angle); - - // Returns xyz-rotation matrix (angles in radians) - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern Matrix4x4 MatrixRotateXYZ(Vector3 ang); - - // Returns x-rotation matrix (angle in radians) - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern Matrix4x4 MatrixRotateX(float angle); - - // Returns y-rotation matrix (angle in radians) - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern Matrix4x4 MatrixRotateY(float angle); - - // Returns z-rotation matrix (angle in radians) - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern Matrix4x4 MatrixRotateZ(float angle); - - // Returns scaling matrix - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern Matrix4x4 MatrixScale(float x, float y, float z); - - // Returns two matrix multiplication - // NOTE: When multiplying matrices... the order matters! + /// Get two matrix multiplication
+ /// NOTE: When multiplying matrices... the order matters!
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Matrix4x4 MatrixMultiply(Matrix4x4 left, Matrix4x4 right); - // Returns perspective projection matrix + /// Get translation matrix + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern Matrix4x4 MatrixTranslate(float x, float y, float z); + + /// Create rotation matrix from axis and angle
+ /// NOTE: Angle should be provided in radians
+ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern Matrix4x4 MatrixRotate(Vector3 axis, float angle); + + /// Get x-rotation matrix (angle in radians) + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern Matrix4x4 MatrixRotateX(float angle); + + /// Get y-rotation matrix (angle in radians) + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern Matrix4x4 MatrixRotateY(float angle); + + /// Get z-rotation matrix (angle in radians) + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern Matrix4x4 MatrixRotateZ(float angle); + + /// Get xyz-rotation matrix (angles in radians) + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern Matrix4x4 MatrixRotateXYZ(Vector3 ang); + + /// Get zyx-rotation matrix (angles in radians) + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern Matrix4x4 MatrixRotateZYX(Vector3 ang); + + /// Get scaling matrix + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern Matrix4x4 MatrixScale(float x, float y, float z); + + /// Get perspective projection matrix [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Matrix4x4 MatrixFrustum(double left, double right, double bottom, double top, double near, double far); - // Returns perspective projection matrix - // NOTE: Angle should be provided in radians + /// Get perspective projection matrix
+ /// NOTE: Angle should be provided in radians
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Matrix4x4 MatrixPerspective(double fovy, double aspect, double near, double far); - // Returns orthographic projection matrix + /// Get orthographic projection matrix [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Matrix4x4 MatrixOrtho(double left, double right, double bottom, double top, double near, double far); - // Returns camera look-at matrix (view matrix) + /// Get camera look-at matrix (view matrix) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Matrix4x4 MatrixLookAt(Vector3 eye, Vector3 target, Vector3 up); - // Returns float array of matrix data - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern float16 MatrixToFloatV(Matrix4x4 mat); - // Returns identity quaternion + /// Add 2 quaternions + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern Quaternion QuaternionAdd(Quaternion q1, Quaternion q2); + + /// Add quaternion and float value + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern Quaternion QuaternionAddValue(Quaternion q, float add); + + /// Subtract 2 quaternions + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern Quaternion QuaternionSubtract(Quaternion q1, Quaternion q2); + + /// Subtract quaternion and float value + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern Quaternion QuaternionSubtractValue(Quaternion q, float add); + + /// Get identity quaternion [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Quaternion QuaternionIdentity(); - // Computes the length of a quaternion + /// Computes the length of a quaternion [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern float QuaternionLength(Quaternion q); - // Normalize provided quaternion + /// Normalize provided quaternion [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Quaternion QuaternionNormalize(Quaternion q); - // Invert provided quaternion + /// Invert provided quaternion [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Quaternion QuaternionInvert(Quaternion q); - // Calculate two quaternion multiplication + /// Calculate two quaternion multiplication [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Quaternion QuaternionMultiply(Quaternion q1, Quaternion q2); - // Calculate linear interpolation between two quaternions + /// Scale quaternion by float value + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern Quaternion QuaternionScale(Quaternion q, float mul); + + /// Divide two quaternions + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern Quaternion QuaternionDivide(Quaternion q1, Quaternion q2); + + /// Calculate linear interpolation between two quaternions [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Quaternion QuaternionLerp(Quaternion q1, Quaternion q2, float amount); - // Calculate slerp-optimized interpolation between two quaternions + /// Calculate slerp-optimized interpolation between two quaternions [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Quaternion QuaternionNlerp(Quaternion q1, Quaternion q2, float amount); - // Calculates spherical linear interpolation between two quaternions + /// Calculates spherical linear interpolation between two quaternions [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Quaternion QuaternionSlerp(Quaternion q1, Quaternion q2, float amount); - // Calculate quaternion based on the rotation from one vector to another + /// Calculate quaternion based on the rotation from one vector to another [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Quaternion QuaternionFromVector3ToVector3(Vector3 from, Vector3 to); - // Returns a quaternion for a given rotation matrix + /// Get a quaternion for a given rotation matrix [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Quaternion QuaternionFromMatrix(Matrix4x4 mat); - // Returns a matrix for a given quaternion + /// Get a matrix for a given quaternion [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Matrix4x4 QuaternionToMatrix(Quaternion q); - // Returns rotation quaternion for an angle and axis - // NOTE: angle must be provided in radians + /// Get rotation quaternion for an angle and axis
+ /// NOTE: angle must be provided in radians
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Quaternion QuaternionFromAxisAngle(Vector3 axis, float angle); - // Returns the rotation angle and axis for a given quaternion + /// Get the rotation angle and axis for a given quaternion [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void QuaternionToAxisAngle(Quaternion q, ref Vector3 outAxis, ref float outAngle); + public static extern void QuaternionToAxisAngle(Quaternion q, Vector3* outAxis, float* outAngle); - // Returns he quaternion equivalent to Euler angles + /// Get the quaternion equivalent to Euler angles
+ /// NOTE: Rotation order is ZYX
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern Quaternion QuaternionFromEuler(float roll, float pitch, float yaw); + public static extern Quaternion QuaternionFromEuler(float pitch, float yaw, float roll); - // Return the Euler angles equivalent to quaternion (roll, pitch, yaw) - // NOTE: Angles are returned in a Vector3 struct in degrees + /// Get the Euler angles equivalent to quaternion (roll, pitch, yaw)
+ /// NOTE: Angles are returned in a Vector3 struct in radians
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Vector3 QuaternionToEuler(Quaternion q); - // Transform a quaternion given a transformation matrix + /// Transform a quaternion given a transformation matrix [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Quaternion QuaternionTransform(Quaternion q, Matrix4x4 mat); } diff --git a/Raylib-cs/Rlgl.cs b/Raylib-cs/Rlgl.cs index dffbbcd..be4c78f 100644 --- a/Raylib-cs/Rlgl.cs +++ b/Raylib-cs/Rlgl.cs @@ -6,9 +6,11 @@ using System.Security; namespace Raylib_cs { [SuppressUnmanagedCodeSecurity] - public static class Rlgl + public static unsafe class Rlgl { - // Used by DllImport to load the native library. + /// + /// Used by DllImport to load the native library + /// public const string nativeLibName = "raylib"; public const int DEFAULT_BATCH_BUFFER_ELEMENTS = 8192; @@ -200,10 +202,9 @@ namespace Raylib_cs public static extern void rlDisableVertexAttribute(uint index); /// Enable attribute state pointer
- /// buffer refers to a void *
/// NOTE: Only available for GRAPHICS_API_OPENGL_11
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void rlEnableStatePointer(int vertexAttribType, IntPtr buffer); + public static extern void rlEnableStatePointer(int vertexAttribType, void* buffer); /// Disable attribute state pointer
/// NOTE: Only available for GRAPHICS_API_OPENGL_11
@@ -379,10 +380,9 @@ namespace Raylib_cs [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void rlglClose(); - /// Load OpenGL extensions
- /// loader refers to a void *
+ /// Load OpenGL extensions [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void rlLoadExtensions(IntPtr loader); + public static extern void rlLoadExtensions(void* loader); /// Get current OpenGL version [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -406,7 +406,7 @@ namespace Raylib_cs /// Get default shader locations [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static unsafe extern int* rlGetShaderLocsDefault(); + public static extern int* rlGetShaderLocsDefault(); // Render batch management @@ -449,15 +449,15 @@ namespace Raylib_cs /// Load a vertex buffer attribute [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern uint rlLoadVertexBuffer(IntPtr buffer, int size, CBool dynamic); + public static extern uint rlLoadVertexBuffer(void* buffer, int size, CBool dynamic); /// Load a new attributes element buffer [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern uint rlLoadVertexBufferElement(IntPtr buffer, int size, CBool dynamic); + public static extern uint rlLoadVertexBufferElement(void* buffer, int size, CBool dynamic); /// Update GPU buffer with new data [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void rlUpdateVertexBuffer(uint bufferId, IntPtr data, int dataSize, int offset); + public static extern void rlUpdateVertexBuffer(uint bufferId, void* data, int dataSize, int offset); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void rlUnloadVertexArray(uint vaoId); @@ -466,48 +466,45 @@ namespace Raylib_cs public static extern void rlUnloadVertexBuffer(uint vboId); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void rlSetVertexAttribute(uint index, int compSize, int type, CBool normalized, int stride, IntPtr pointer); + public static extern void rlSetVertexAttribute(uint index, int compSize, int type, CBool normalized, int stride, void* pointer); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void rlSetVertexAttributeDivisor(uint index, int divisor); /// Set vertex attribute default value [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void rlSetVertexAttributeDefault(int locIndex, IntPtr value, int attribType, int count); + public static extern void rlSetVertexAttributeDefault(int locIndex, void* value, int attribType, int count); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void rlDrawVertexArray(int offset, int count); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void rlDrawVertexArrayElements(int offset, int count, IntPtr buffer); + public static extern void rlDrawVertexArrayElements(int offset, int count, void* buffer); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void rlDrawVertexArrayInstanced(int offset, int count, int instances); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void rlDrawVertexArrayElementsInstanced(int offset, int count, IntPtr buffer, int instances); + public static extern void rlDrawVertexArrayElementsInstanced(int offset, int count, void* buffer, int instances); // Textures data management - /// Load texture in GPU
- /// data refers to a void *
+ /// Load texture in GPU [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern uint rlLoadTexture(IntPtr data, int width, int height, PixelFormat format, int mipmapCount); + public static extern uint rlLoadTexture(void* data, int width, int height, PixelFormat format, int mipmapCount); /// Load depth texture/renderbuffer (to be attached to fbo) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern uint rlLoadTextureDepth(int width, int height, CBool useRenderBuffer); - /// Load texture cubemap
- /// data refers to a void *
+ /// Load texture cubemap [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern uint rlLoadTextureCubemap(IntPtr data, int size, PixelFormat format); + public static extern uint rlLoadTextureCubemap(void* data, int size, PixelFormat format); - /// Update GPU texture with new data
- /// data refers to a const void *
+ /// Update GPU texture with new data [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void rlUpdateTexture(uint id, int width, int height, PixelFormat format, IntPtr data); + public static extern void rlUpdateTexture(uint id, int width, int height, PixelFormat format, void* data); /// Get OpenGL internal formats [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -515,7 +512,7 @@ namespace Raylib_cs /// Get OpenGL internal formats [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr rlGetPixelFormatName(PixelFormat format); + public static extern sbyte* rlGetPixelFormatName(PixelFormat format); /// Unload texture from GPU memory [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -525,15 +522,13 @@ namespace Raylib_cs [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void rlGenTextureMipmaps(uint id, int width, int height, PixelFormat format, ref int[] mipmaps); - /// Read texture pixel data
- /// IntPtr refers to a void *
+ /// Read texture pixel data [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr rlReadTexturePixels(uint id, int width, int height, PixelFormat format); + public static extern void* rlReadTexturePixels(uint id, int width, int height, PixelFormat format); - /// Read screen pixel data (color buffer)
- /// IntPtr refers to a unsigned char *
+ /// Read screen pixel data (color buffer) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr rlReadScreenPixels(int width, int height); + public static extern byte* rlReadScreenPixels(int width, int height); // Framebuffer management (fbo) @@ -584,7 +579,7 @@ namespace Raylib_cs /// Set shader value uniform [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void rlSetUniform(int locIndex, IntPtr value, int uniformType, int count); + public static extern void rlSetUniform(int locIndex, void* value, int uniformType, int count); /// Set shader value matrix [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -611,7 +606,7 @@ namespace Raylib_cs /// Load shader storage buffer object (SSBO) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern unsafe uint rlLoadShaderBuffer(ulong size, void* data, int usageHint); + public static extern uint rlLoadShaderBuffer(ulong size, void* data, int usageHint); /// Unload shader storage buffer object (SSBO) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -623,11 +618,11 @@ namespace Raylib_cs /// Get SSBO buffer size [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern unsafe ulong rlGetShaderBufferSize(uint id, void* dest, ulong count, ulong offset); + public static extern ulong rlGetShaderBufferSize(uint id, void* dest, ulong count, ulong offset); /// Bind SSBO buffer [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern unsafe void rlReadShaderBufferElements(uint id, void* dest, ulong count, ulong offset); + public static extern void rlReadShaderBufferElements(uint id, void* dest, ulong count, ulong offset); /// Copy SSBO buffer data [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] From 7fe5c22e8cb6b13205b811acb3e7589071b97511 Mon Sep 17 00:00:00 2001 From: ChrisDill Date: Sun, 28 Nov 2021 09:30:52 +0000 Subject: [PATCH 11/14] Test logging fix --- Raylib-cs/LoggingUtils.cs | 166 ++++++++++++++++++++++++++++++++++++++ Raylib-cs/Raylib.cs | 15 +++- 2 files changed, 178 insertions(+), 3 deletions(-) create mode 100644 Raylib-cs/LoggingUtils.cs diff --git a/Raylib-cs/LoggingUtils.cs b/Raylib-cs/LoggingUtils.cs new file mode 100644 index 0000000..d672079 --- /dev/null +++ b/Raylib-cs/LoggingUtils.cs @@ -0,0 +1,166 @@ +using System; +using System.Runtime.InteropServices; + +namespace Raylib_cs +{ + internal readonly struct Native + { + internal const string Msvcrt = "msvcrt"; + internal const string Libc = "libc"; + internal const string LibSystem = "libSystem"; + + [DllImport(LibSystem, EntryPoint = "vasprintf", CallingConvention = CallingConvention.Cdecl)] + public static extern int vasprintf_apple(ref IntPtr buffer, IntPtr format, IntPtr args); + + [DllImport(Libc, EntryPoint = "vsprintf", CallingConvention = CallingConvention.Cdecl)] + public static extern int vsprintf_linux(IntPtr buffer, IntPtr format, IntPtr args); + + [DllImport(Msvcrt, EntryPoint = "vsprintf", CallingConvention = CallingConvention.Cdecl)] + public static extern int vsprintf_windows(IntPtr buffer, IntPtr format, IntPtr args); + + [DllImport(Libc, EntryPoint = "vsnprintf", CallingConvention = CallingConvention.Cdecl)] + public static extern int vsnprintf_linux(IntPtr buffer, UIntPtr size, IntPtr format, IntPtr args); + + [DllImport(Msvcrt, EntryPoint = "vsnprintf", CallingConvention = CallingConvention.Cdecl)] + public static extern int vsnprintf_windows(IntPtr buffer, UIntPtr size, IntPtr format, IntPtr args); + } + + [StructLayout(LayoutKind.Sequential, Pack = 4)] + struct VaListLinuxX64 + { + uint gp_offset; + uint fp_offset; + IntPtr overflow_arg_area; + IntPtr reg_save_area; + } + + /// + /// Logging workaround for formatting strings from native code + /// + public static class LoggingUtils + { + static LoggingUtils() + { + Raylib.SetTraceLogCallback(LogConsole); + } + + public static void LogConsole(TraceLogLevel msgType, IntPtr text, IntPtr args) + { + var message = LoggingUtils.GetLogMessage(text, args); + Console.WriteLine(message); + } + + public static string GetLogMessage(IntPtr format, IntPtr args) + { + if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) + { + return AppleLogCallback(format, args); + } + + // Special marshalling is needed on Linux desktop 64 bits. + if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && IntPtr.Size == 8) + { + return LinuxX64LogCallback(format, args); + } + + var byteLength = vsnprintf(IntPtr.Zero, UIntPtr.Zero, format, args) + 1; + if (byteLength <= 1) + { + return string.Empty; + } + + var buffer = Marshal.AllocHGlobal(byteLength); + vsprintf(buffer, format, args); + + string result = Marshal.PtrToStringUTF8(buffer); + Marshal.FreeHGlobal(buffer); + + return result; + } + + static string AppleLogCallback(IntPtr format, IntPtr args) + { + IntPtr buffer = IntPtr.Zero; + try + { + var count = Native.vasprintf_apple(ref buffer, format, args); + if (count == -1) + { + return string.Empty; + } + return Marshal.PtrToStringUTF8(buffer) ?? string.Empty; + } + finally + { + Marshal.FreeHGlobal(buffer); + } + } + + static string LinuxX64LogCallback(IntPtr format, IntPtr args) + { + // The args pointer cannot be reused between two calls. We need to make a copy of the underlying structure. + var listStructure = Marshal.PtrToStructure(args); + IntPtr listPointer = IntPtr.Zero; + int byteLength = 0; + string result = ""; + + // Get length of args + listPointer = Marshal.AllocHGlobal(Marshal.SizeOf(listStructure)); + Marshal.StructureToPtr(listStructure, listPointer, false); + byteLength = Native.vsnprintf_linux(IntPtr.Zero, UIntPtr.Zero, format, listPointer) + 1; + + // Allocate buffer for result + // listPointer = Marshal.AllocHGlobal(Marshal.SizeOf(listStructure)); + Marshal.StructureToPtr(listStructure, listPointer, false); + + IntPtr utf8Buffer = IntPtr.Zero; + utf8Buffer = Marshal.AllocHGlobal(byteLength); + + // Print result into buffer + Native.vsprintf_linux(utf8Buffer, format, listPointer); + result = Marshal.PtrToStringUTF8(utf8Buffer); + + Marshal.FreeHGlobal(listPointer); + Marshal.FreeHGlobal(utf8Buffer); + + return result; + } + + // https://github.com/dotnet/runtime/issues/51052 + static int vsnprintf(IntPtr buffer, UIntPtr size, IntPtr format, IntPtr args) + { + var os = Environment.OSVersion; + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + return Native.vsnprintf_windows(buffer, size, format, args); + } + else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + return Native.vsnprintf_linux(buffer, size, format, args); + } + else if (RuntimeInformation.IsOSPlatform(OSPlatform.Create("ANDROID"))) + { + return Native.vsprintf_linux(buffer, format, args); + } + return -1; + } + + // https://github.com/dotnet/runtime/issues/51052 + static int vsprintf(IntPtr buffer, IntPtr format, IntPtr args) + { + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + return Native.vsprintf_windows(buffer, format, args); + } + else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + return Native.vsprintf_linux(buffer, format, args); + } + else if (RuntimeInformation.IsOSPlatform(OSPlatform.Create("ANDROID"))) + { + return Native.vsprintf_linux(buffer, format, args); + } + return -1; + } + } +} diff --git a/Raylib-cs/Raylib.cs b/Raylib-cs/Raylib.cs index 846a592..8687ec4 100644 --- a/Raylib-cs/Raylib.cs +++ b/Raylib-cs/Raylib.cs @@ -26,7 +26,7 @@ namespace Raylib_cs /// WARNING: This callback is intended for advance users ///
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public delegate void TraceLogCallback(TraceLogLevel logLevel, string text, IntPtr args); + public delegate void TraceLogCallback(TraceLogLevel logLevel, IntPtr text, IntPtr args); /// /// FileIO: Load binary data
@@ -58,6 +58,8 @@ namespace Raylib_cs [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate CBool SaveFileTextCallback(string fileName, string text); + private static TraceLogCallback traceLogCallback; + /// /// Returns color with alpha applied, alpha goes from 0.0f to 1.0f
/// NOTE: Added for compatability with previous versions @@ -497,8 +499,15 @@ namespace Raylib_cs // WARNING: Callbacks setup is intended for advance users /// Set custom trace log - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void SetTraceLogCallback(TraceLogCallback callback); + [DllImport(nativeLibName, EntryPoint = "SetTraceLogCallback", CallingConvention = CallingConvention.Cdecl)] + private static extern void SetTraceLogCallbackInternal(TraceLogCallback callback); + + /// Set custom trace log + public static void SetTraceLogCallback(TraceLogCallback callback) + { + SetTraceLogCallbackInternal(callback); + traceLogCallback = callback; + } /// Set custom file binary data loader [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] From 340bfa288d11457a8165d0b747d3c758a62b43af Mon Sep 17 00:00:00 2001 From: ChrisDill Date: Sun, 28 Nov 2021 09:54:01 +0000 Subject: [PATCH 12/14] Fix typos and change refs to pointers in Rlgl --- Raylib-cs/Rlgl.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Raylib-cs/Rlgl.cs b/Raylib-cs/Rlgl.cs index be4c78f..0642c81 100644 --- a/Raylib-cs/Rlgl.cs +++ b/Raylib-cs/Rlgl.cs @@ -104,7 +104,7 @@ namespace Raylib_cs /// Multiply the current matrix by another matrix [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void rlMultMatrixf(float[] matf); + public static extern void rlMultMatrixf(float* matf); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void rlFrustum(double left, double right, double bottom, double top, double znear, double zfar); @@ -422,11 +422,11 @@ namespace Raylib_cs /// Draw render batch data (Update->Draw->Reset) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void rlDrawRenderBatch(ref RenderBatch batch); + public static extern void rlDrawRenderBatch(RenderBatch* batch); /// Set the active render batch for rlgl (NULL for default internal) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void rlSetRenderBatchActive(ref RenderBatch batch); + public static extern void rlSetRenderBatchActive(RenderBatch* batch); /// Update and draw internal render batch [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -508,7 +508,7 @@ namespace Raylib_cs /// Get OpenGL internal formats [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void rlGetGlTextureFormats(PixelFormat format, ref uint glInternalFormat, ref uint glFormat, ref uint glType); + public static extern void rlGetGlTextureFormats(PixelFormat format, int* glInternalFormat, int* glFormat, int* glType); /// Get OpenGL internal formats [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -520,7 +520,7 @@ namespace Raylib_cs /// Generate mipmap data for selected texture [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void rlGenTextureMipmaps(uint id, int width, int height, PixelFormat format, ref int[] mipmaps); + public static extern void rlGenTextureMipmaps(uint id, int width, int height, PixelFormat format, int* mipmaps); /// Read texture pixel data [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -644,7 +644,7 @@ namespace Raylib_cs /// Get internal modelview matrix [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern Matrix4x4 rlGetMatrixModelView(); + public static extern Matrix4x4 rlGetMatrixModelview(); /// Get internal projection matrix [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -668,7 +668,7 @@ namespace Raylib_cs /// Set a custom modelview matrix (replaces internal modelview matrix) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void rlSetMatrixModelView(Matrix4x4 proj); + public static extern void rlSetMatrixModelview(Matrix4x4 proj); /// Set eyes projection matrices for stereo rendering [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] From bb535732cd83fcf4c30ad7701ec14aac332e8467 Mon Sep 17 00:00:00 2001 From: ChrisDill Date: Sun, 28 Nov 2021 18:10:00 +0000 Subject: [PATCH 13/14] Update LoggingUtils and Material --- Raylib-cs/{LoggingUtils.cs => Logging.cs} | 15 +++++++-------- Raylib-cs/types/Material.cs | 2 +- 2 files changed, 8 insertions(+), 9 deletions(-) rename Raylib-cs/{LoggingUtils.cs => Logging.cs} (94%) diff --git a/Raylib-cs/LoggingUtils.cs b/Raylib-cs/Logging.cs similarity index 94% rename from Raylib-cs/LoggingUtils.cs rename to Raylib-cs/Logging.cs index d672079..c74d0ff 100644 --- a/Raylib-cs/LoggingUtils.cs +++ b/Raylib-cs/Logging.cs @@ -28,25 +28,25 @@ namespace Raylib_cs [StructLayout(LayoutKind.Sequential, Pack = 4)] struct VaListLinuxX64 { - uint gp_offset; - uint fp_offset; - IntPtr overflow_arg_area; - IntPtr reg_save_area; + uint gpOffset; + uint fpOffset; + IntPtr overflowArgArea; + IntPtr regSaveArea; } /// /// Logging workaround for formatting strings from native code /// - public static class LoggingUtils + public static class Logging { - static LoggingUtils() + static Logging() { Raylib.SetTraceLogCallback(LogConsole); } public static void LogConsole(TraceLogLevel msgType, IntPtr text, IntPtr args) { - var message = LoggingUtils.GetLogMessage(text, args); + var message = GetLogMessage(text, args); Console.WriteLine(message); } @@ -110,7 +110,6 @@ namespace Raylib_cs byteLength = Native.vsnprintf_linux(IntPtr.Zero, UIntPtr.Zero, format, listPointer) + 1; // Allocate buffer for result - // listPointer = Marshal.AllocHGlobal(Marshal.SizeOf(listStructure)); Marshal.StructureToPtr(listStructure, listPointer, false); IntPtr utf8Buffer = IntPtr.Zero; diff --git a/Raylib-cs/types/Material.cs b/Raylib-cs/types/Material.cs index 1d82983..0f72c8e 100644 --- a/Raylib-cs/types/Material.cs +++ b/Raylib-cs/types/Material.cs @@ -86,6 +86,6 @@ namespace Raylib_cs /// /// Material generic parameters (if required) /// - public float *param; + public fixed float param[4]; } } From 4ce55fba660f1f8fbb9722fe4d505af47d45dd39 Mon Sep 17 00:00:00 2001 From: ChrisDill Date: Sat, 4 Dec 2021 08:32:12 +0000 Subject: [PATCH 14/14] Fix typo in Rlgl --- Raylib-cs/Rlgl.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Raylib-cs/Rlgl.cs b/Raylib-cs/Rlgl.cs index 0642c81..da4f712 100644 --- a/Raylib-cs/Rlgl.cs +++ b/Raylib-cs/Rlgl.cs @@ -365,7 +365,7 @@ namespace Raylib_cs /// Set blending mode factor and equation (using OpenGL factors) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void rlSetBlendModeFactors(int glSrcFactor, int glDstFactor, int glEquation); + public static extern void rlSetBlendFactors(int glSrcFactor, int glDstFactor, int glEquation); // ------------------------------------------------------------------------------------