diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c9d45fc..03f3854 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -4,6 +4,9 @@ on: branches: master pull_request: branches: '*' + paths-ignore: + - 'README.md' + - '.github/ISSUE_TEMPLATE/**' workflow_dispatch: jobs: @@ -18,16 +21,21 @@ 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 + run: dotnet build -c Release -f net6.0 - name: Test project - run: dotnet test + run: dotnet test -c Release -f net6.0 publish: name: Build Release Package runs-on: ubuntu-latest needs: build steps: + - uses: actions/checkout@v2 + - name: Setup dotnet + uses: actions/setup-dotnet@v1 + with: + dotnet-version: 6.0.x - name: Download Repo uses: actions/checkout@v2 @@ -41,12 +49,12 @@ jobs: - name: echo tag run: echo ${{ steps.get-tag.outputs.info }} - - name: Download raylib Release - uses: robinraju/release-downloader@v1.2 + - name: Download win-x64 Raylib Release + uses: robinraju/release-downloader@v1.3 with: repository: "raysan5/raylib" tag: ${{ steps.get-tag.outputs.info }} - fileName: "*" + fileName: "raylib-${{steps.get-tag.outputs.info}}_win64_msvc16.zip" - name: extract win-x64 uses: montudor/action-zip@v1 @@ -58,6 +66,13 @@ jobs: with: source: "raylib-win64/raylib-${{steps.get-tag.outputs.info}}_win64_msvc16/lib/raylib.dll" target: "Raylib-cs/runtimes/win-x64/native/raylib.dll" + + - name: Download win-x86 Raylib Release + uses: robinraju/release-downloader@v1.3 + with: + repository: "raysan5/raylib" + tag: ${{ steps.get-tag.outputs.info }} + fileName: "raylib-${{steps.get-tag.outputs.info}}_win32_msvc16.zip" - name: extract win-x86 uses: montudor/action-zip@v1 @@ -69,6 +84,13 @@ jobs: with: source: "raylib-win86/raylib-${{steps.get-tag.outputs.info}}_win32_msvc16/lib/raylib.dll" target: "Raylib-cs/runtimes/win-x86/native/raylib.dll" + + - name: Download linux-x64 Raylib Release + uses: robinraju/release-downloader@v1.3 + with: + repository: "raysan5/raylib" + tag: ${{ steps.get-tag.outputs.info }} + fileName: "raylib-${{steps.get-tag.outputs.info}}_linux_amd64.tar.gz" - name: extract linux-x64 run: mkdir -p raylib-linux64 && tar -xvf raylib-${{steps.get-tag.outputs.info}}_linux_amd64.tar.gz -C raylib-linux64 @@ -79,6 +101,13 @@ jobs: source: "raylib-linux64/raylib-${{steps.get-tag.outputs.info}}_linux_amd64/lib/libraylib.so.${{steps.get-tag.outputs.info}}" target: "Raylib-cs/runtimes/linux-x64/native/libraylib.so" + - name: Download osx-x64 Raylib Release + uses: robinraju/release-downloader@v1.3 + with: + repository: "raysan5/raylib" + tag: ${{ steps.get-tag.outputs.info }} + fileName: "raylib-${{steps.get-tag.outputs.info}}_macos.tar.gz" + - name: extract osx-x64 run: mkdir -p raylib-osx64 && tar -xvf raylib-${{steps.get-tag.outputs.info}}_macos.tar.gz -C raylib-osx64 @@ -96,7 +125,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 @@ -108,4 +137,4 @@ jobs: uses: softprops/action-gh-release@v1 if: startsWith(github.ref, 'refs/tags/') with: - files: Raylib-cs/bin/Release/Raylib-cs.${{steps.get-nuget-version.outputs.info}}.nupkg \ No newline at end of file + files: Raylib-cs/bin/Release/Raylib-cs.${{steps.get-nuget-version.outputs.info}}.nupkg diff --git a/Physac-cs/Physac-cs.csproj b/Physac-cs/Physac-cs.csproj deleted file mode 100644 index e16b4e7..0000000 --- a/Physac-cs/Physac-cs.csproj +++ /dev/null @@ -1,18 +0,0 @@ - - - netstandard2.1 - false - Physac-cs - Physac_cs - true - false - - - - - - - - - - diff --git a/Physac-cs/Physac.cs b/Physac-cs/Physac.cs deleted file mode 100644 index fbf64f6..0000000 --- a/Physac-cs/Physac.cs +++ /dev/null @@ -1,230 +0,0 @@ -using System; -using System.Numerics; -using System.Runtime.InteropServices; -using System.Security; -using Raylib_cs; - -namespace Physac_cs -{ - public enum PhysicsShapeType - { - PHYSICS_CIRCLE, - PHYSICS_POLYGON - } - - // Matrix2x2 type (used for polygon shape rotation matrix) - [StructLayout(LayoutKind.Sequential)] - public struct Matrix2x2 - { - public float m00; - public float m01; - public float m10; - public float m11; - } - - // @TODO Custom array marshall issue https://github.com/ChrisDill/Raylib-cs/issues/9 - // Hack same as raylib.cs _MaterialMap_e_FixedBuffer - // No easy way to marshall arrays of custom types. no idea why? - public unsafe struct _Polygon_e_FixedBuffer - { - public Vector2 v0; - public Vector2 v1; - public Vector2 v2; - public Vector2 v3; - public Vector2 v4; - public Vector2 v5; - public Vector2 v6; - public Vector2 v7; - public Vector2 v8; - public Vector2 v9; - public Vector2 v10; - public Vector2 v11; - public Vector2 v12; - public Vector2 v13; - public Vector2 v14; - public Vector2 v15; - public Vector2 v16; - public Vector2 v17; - public Vector2 v18; - public Vector2 v19; - public Vector2 v20; - public Vector2 v21; - public Vector2 v22; - public Vector2 v23; - public Vector2 v24; - - public Vector2 this[int index] - { - get - { - fixed (Vector2* e = &v0) - return e[index]; - } - } - } - - [StructLayout(LayoutKind.Sequential)] - public struct PhysicsVertexData - { - public uint vertexCount; // Vertex count (positions and normals) - public _Polygon_e_FixedBuffer positions; // Vertex positions vectors - public _Polygon_e_FixedBuffer normals; // Vertex normals vectors - } - - [StructLayout(LayoutKind.Sequential)] - public struct PhysicsShape - { - public PhysicsShapeType type; // Shape type (circle or polygon) - public IntPtr body; // Shape physics body reference - public PhysicsVertexData vertexData; // Shape vertices data (used for polygon shapes) - public float radius; // Shape radius (used for circle shapes) - public Matrix2x2 transform; // Vertices transform matrix 2x2 - } - - [StructLayout(LayoutKind.Sequential)] - public struct PhysicsBodyData - { - public uint id; // Unique identifier - public byte enabled; // Enabled dynamics state (collisions are calculated anyway) - public Vector2 position; // Physics body shape pivot - public Vector2 velocity; // Current linear velocity applied to position - public Vector2 force; // Current linear force (reset to 0 every step) - public float angularVelocity; // Current angular velocity applied to orient - public float torque; // Current angular force (reset to 0 every step) - public float orient; // Rotation in radians - public float inertia; // Moment of inertia - public float inverseInertia; // Inverse value of inertia - public float mass; // Physics body mass - public float inverseMass; // Inverse value of mass - public float staticFriction; // Friction when the body has not movement (0 to 1) - public float dynamicFriction; // Friction when the body has movement (0 to 1) - public float restitution; // Restitution coefficient of the body (0 to 1) - public byte useGravity; // Apply gravity force to dynamics - public byte isGrounded; // Physics grounded on other body state - public byte freezeOrient; // Physics rotation constraint - public PhysicsShape shape; // Physics body shape information (type, radius, vertices, transform) - } - - [StructLayout(LayoutKind.Sequential)] - public struct PhysicsManifoldData - { - public uint id; // Reference unique identifier - public IntPtr bodyA; // Manifold first physics body reference - public IntPtr bodyB; // Manifold second physics body reference - public float penetration; // Depth of penetration from collision - public Vector2 normal; // Normal direction vector from 'a' to 'b' - public Vector2 contactsA; // Points of contact during collision - public Vector2 contactsB; // Points of contact during collision - public uint contactsCount; // Current collision number of contacts - public float restitution; // Mixed restitution during collision - public float dynamicFriction; // Mixed dynamic friction during collision - public float staticFriction; // Mixed static friction during collision - } - - [SuppressUnmanagedCodeSecurity] - public static class Physac - { - // Used by DllImport to load the native library. - public const string nativeLibName = "physac"; - - public const int PHYSAC_MAX_BODIES = 64; - public const int PHYSAC_MAX_MANIFOLDS = 4096; - public const int PHYSAC_MAX_VERTICES = 24; - public const int PHYSAC_CIRCLE_VERTICES = 24; - - public const int PHYSAC_COLLISION_ITERATIONS = 100; - public const float PHYSAC_PENETRATION_ALLOWANCE = 0.05f; - public const float PHYSAC_PENETRATION_CORRECTION = 0.4f; - - // Physics system management - - // Initializes physics values, pointers and creates physics loop thread - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void InitPhysics(); - - // Update physics system - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void UpdatePhysics(); - - // Reset physics system (global variables) - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void ResetPhysics(); - - // Close physics system and unload used memory - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void ClosePhysics(); - - // Sets physics fixed time step in milliseconds. 1.666666 by default - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void SetPhysicsTimeStep(double delta); - - // Sets physics global gravity force - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void SetPhysicsGravity(float x, float y); - - - // Physic body creation/destroy - - // Creates a new circle physics body with generic parameters - // IntPtr refers to a PhysicsBodyData * - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr CreatePhysicsBodyCircle(Vector2 pos, float radius, float density); - - // Creates a new rectangle physics body with generic parameters - // IntPtr refers to a PhysicsBodyData * - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr CreatePhysicsBodyRectangle(Vector2 pos, float width, float height, float density); - - // Creates a new polygon physics body with generic parameters - // IntPtr refers to a PhysicsBodyData * - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr CreatePhysicsBodyPolygon(Vector2 pos, float radius, int sides, float density); - - // Destroy a physics body - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void DestroyPhysicsBody(PhysicsBodyData body); - - - // Physic body forces - - // Adds a force to a physics body - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void PhysicsAddForce(PhysicsBodyData body, Vector2 force); - - // Adds an angular force to a physics body - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void PhysicsAddTorque(PhysicsBodyData body, float amount); - - // Shatters a polygon shape physics body to little physics bodies with explosion force - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void PhysicsShatter(PhysicsBodyData body, Vector2 position, float force); - - // Sets physics body shape transform based on radians parameter - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void SetPhysicsBodyRotation(PhysicsBodyData body, float radians); - - - // Query physics info - - // Returns a physics body of the bodies pool at a specific index - // IntPtr refers to a PhysicsBodyData * - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr GetPhysicsBody(int index); - - // Returns the current amount of created physics bodies - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern int GetPhysicsBodiesCount(); - - // Returns the physics body shape type (PHYSICS_CIRCLE or PHYSICS_POLYGON) - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern int GetPhysicsShapeType(int index); - - // Returns the amount of vertices of a physics body shape - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern int GetPhysicsShapeVerticesCount(int index); - - // Returns transformed position of a body shape (body position + vertex transformed position) - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern Vector2 GetPhysicsShapeVertex(PhysicsBodyData body, int vertex); - } -} diff --git a/README.md b/README.md index 6182668..5b843de 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ -![Raylib-cs Logo](https://github.com/ChrisDill/Raylib-cs/blob/master/Logo/raylib-cs_256x256.png "Raylib-cs Logo") +![Raylib-cs Logo](https://raw.githubusercontent.com/ChrisDill/Raylib-cs/master/Logo/raylib-cs_256x256.png "Raylib-cs Logo") # Raylib-cs -C# bindings for raylib 3.7.0, a simple and easy-to-use library to learn videogames programming (www.raylib.com) +C# bindings for raylib 4.0.0, a simple and easy-to-use library to learn videogames programming (www.raylib.com) [![GitHub contributors](https://img.shields.io/github/contributors/ChrisDill/Raylib-cs)](https://github.com/ChrisDill/Raylib-cs/graphs/contributors) [![License](https://img.shields.io/badge/license-zlib%2Flibpng-blue.svg)](LICENSE) @@ -12,14 +12,14 @@ C# bindings for raylib 3.7.0, a simple and easy-to-use library to learn videogam [![Build](https://github.com/ChrisDill/Raylib-cs/workflows/Build/badge.svg)](https://github.com/ChrisDill/Raylib-cs/actions?query=workflow%3ABuild) -Raylib-cs targets netstandard2.1 and supports netcoreapp3.0+ and net5.0. +Raylib-cs targets net5.0 and net6.0. ## Installation - NuGet This is the prefered method to get started - The package is still new so please report any [issues](https://github.com/ChrisDill/Raylib-cs/issues). ``` -dotnet add package Raylib-cs --version 3.7.0.1 +dotnet add package Raylib-cs --version 4.0.0 ``` [![NuGet](https://img.shields.io/nuget/dt/raylib-cs)](https://www.nuget.org/packages/Raylib-cs/) @@ -30,9 +30,9 @@ If you need to edit Raylib-cs source then you will need to add the bindings as a 1. Download/Clone this repo -2. Add Raylib-cs/Raylib-cs.csproj to your project as an existing project. +2. Add [Raylib-cs/Raylib-cs.csproj](Raylib-cs/Raylib-cs.csproj) to your project as an existing project. -3. Download the native libraries for the platforms you want to build for using the [official 3.7.0 release](https://github.com/raysan5/raylib/releases/tag/3.7.0). +3. Download the native libraries for the platforms you want to build for using the [official 4.0.0 release](https://github.com/raysan5/raylib/releases/tag/4.0.0). **NOTE: the MSVC version is required for Windows platforms** 4. **(Recommended)** Put the native library for each platform under `Raylib-cs/runtimes/{platform}/native/` @@ -40,6 +40,8 @@ If you need to edit Raylib-cs source then you will need to add the bindings as a 5. Start coding! +## Hello, World! + ```csharp using Raylib_cs; @@ -67,10 +69,6 @@ namespace HelloWorld } ``` -## Physac-cs and Raygui-cs - -There are **UNSUPPORTED & EXPERIMENTAL** bindings to physac and raygui. They are in separate projects not included in releases or via NuGet. Pull requests are welcome and encouraged. - ## Documentation Examples for Raylib-cs can be found at [Raylib-cs-Examples](https://github.com/ChrisDill/Raylib-cs-Examples). diff --git a/Raygui-cs/Raygui-cs.csproj b/Raygui-cs/Raygui-cs.csproj deleted file mode 100644 index aeea437..0000000 --- a/Raygui-cs/Raygui-cs.csproj +++ /dev/null @@ -1,18 +0,0 @@ - - - netstandard2.1 - false - Raygui-cs - Raygui_cs - true - false - - - - - - - - - - diff --git a/Raygui-cs/Raygui.cs b/Raygui-cs/Raygui.cs deleted file mode 100644 index 18a2009..0000000 --- a/Raygui-cs/Raygui.cs +++ /dev/null @@ -1,454 +0,0 @@ -using System; -using System.Numerics; -using System.Runtime.InteropServices; -using System.Security; -using System.Text; -using Raylib_cs; - -namespace Raygui_cs -{ - // Style property - [StructLayout(LayoutKind.Sequential)] - struct GuiStyleProp - { - ushort controlId; - ushort propertyId; - int propertyValue; - } - - // Gui global state enum - public enum GuiControlState - { - GUI_STATE_NORMAL = 0, - GUI_STATE_FOCUSED, - GUI_STATE_PRESSED, - GUI_STATE_DISABLED, - } - - // Gui global text alignment - public enum GuiTextAlignment - { - GUI_TEXT_ALIGN_LEFT = 0, - GUI_TEXT_ALIGN_CENTER, - GUI_TEXT_ALIGN_RIGHT, - } - - // Gui standard controls - public enum GuiControl - { - DEFAULT = 0, - LABEL, // LABELBUTTON - BUTTON, // IMAGEBUTTON - TOGGLE, // TOGGLEGROUP - SLIDER, // SLIDERBAR - PROGRESSBAR, - CHECKBOX, - COMBOBOX, - DROPDOWNBOX, - TEXTBOX, // TEXTBOXMULTI - VALUEBOX, - SPINNER, - LISTVIEW, - COLORPICKER, - SCROLLBAR, - STATUSBAR - } - - // Gui default properties for every control - public enum GuiControlProperty - { - BORDER_COLOR_NORMAL = 0, - BASE_COLOR_NORMAL, - TEXT_COLOR_NORMAL, - BORDER_COLOR_FOCUSED, - BASE_COLOR_FOCUSED, - TEXT_COLOR_FOCUSED, - BORDER_COLOR_PRESSED, - BASE_COLOR_PRESSED, - TEXT_COLOR_PRESSED, - BORDER_COLOR_DISABLED, - BASE_COLOR_DISABLED, - TEXT_COLOR_DISABLED, - BORDER_WIDTH, - TEXT_PADDING, - TEXT_ALIGNMENT, - RESERVED - } - - // Gui extended properties depending on control type - // NOTE: We reserve a fixed size of additional properties per control - - // Default properties - public enum GuiDefaultProperty - { - TEXT_SIZE = 16, - TEXT_SPACING, - LINE_COLOR, - BACKGROUND_COLOR, - } - - // Toggle / ToggleGroup - public enum GuiToggleProperty - { - GROUP_PADDING = 16, - } - - // Slider / SliderBar - public enum GuiSliderProperty - { - SLIDER_WIDTH = 16, - TEXT_PADDING - } - - // ProgressBar - public enum GuiProgressBarProperty - { - PROGRESS_PADDING = 16, - } - - // CheckBox - public enum GuiCheckBoxProperty - { - CHECK_PADDING = 16 - } - - // ComboBox - public enum GuiComboBoxProperty - { - SELECTOR_WIDTH = 16, - SELECTOR_PADDING - } - - // DropdownBox - public enum GuiDropdownBoxProperty - { - ARROW_PADDING = 16, - DROPDOWN_ITEMS_PADDING - } - - // TextBox / TextBoxMulti / ValueBox / Spinner - public enum GuiTextBoxProperty - { - TEXT_INNER_PADDING = 16, - TEXT_LINES_PADDING, - COLOR_SELECTED_FG, - COLOR_SELECTED_BG - } - - // Spinner - public enum GuiSpinnerProperty - { - SPIN_BUTTON_WIDTH = 16, - SPIN_BUTTON_PADDING, - } - - // ScrollBar - public enum GuiScrollBarProperty - { - ARROWS_SIZE = 16, - ARROWS_VISIBLE, - SCROLL_SLIDER_PADDING, - SCROLL_SLIDER_SIZE, - SCROLL_PADDING, - SCROLL_SPEED, - } - - // ScrollBar side - public enum GuiScrollBarSide - { - SCROLLBAR_LEFT_SIDE = 0, - SCROLLBAR_RIGHT_SIDE - } - - // ListView - public enum GuiListViewProperty - { - LIST_ITEMS_HEIGHT = 16, - LIST_ITEMS_PADDING, - SCROLLBAR_WIDTH, - SCROLLBAR_SIDE, - } - - // ColorPicker - public enum GuiColorPickerProperty - { - COLOR_SELECTOR_SIZE = 16, - HUEBAR_WIDTH, // Right hue bar width - HUEBAR_PADDING, // Right hue bar separation from panel - HUEBAR_SELECTOR_HEIGHT, // Right hue bar selector height - HUEBAR_SELECTOR_OVERFLOW // Right hue bar selector overflow - } - - [SuppressUnmanagedCodeSecurity] - public static class Raygui - { - // Used by DllImport to load the native library. - public const string nativeLibName = "raygui"; - - public const string RAYGUI_VERSION = "2.9-dev"; - - public const int NUM_CONTROLS = 16; // Number of standard controls - public const int NUM_PROPS_DEFAULT = 16; // Number of standard properties - public const int NUM_PROPS_EXTENDED = 8; // Number of extended properties - - public const int TEXTEDIT_CURSOR_BLINK_FRAMES = 20; // Text edit controls cursor blink timming - - // State modification functions - - // Enable gui controls (global state) - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void GuiEnable(); - - // Disable gui controls (global state) - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void GuiDisable(); - - // Lock gui controls (global state) - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void GuiLock(); - - // Unlock gui controls (global state) - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void GuiUnlock(); - - // Set gui controls alpha (global state), alpha goes from 0.0f to 1.0f - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void GuiFade(float alpha); - - // Set gui state (global state) - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void GuiSetState(int state); - - // Get gui state (global state) - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern int GuiGetState(); - - - // Font set/get functions - - // Get gui custom font (global state) - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void GuiSetFont(Font font); - - // Set gui custom font (global state) - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern Font GuiGetFont(); - - - // Style set/get functions - - // Set one style property - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void GuiSetStyle(GuiControl control, GuiControlProperty property, int value); - - // Get one style property - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern int GuiGetStyle(GuiControl control, GuiControlProperty property); - - - // Container/separator controls, useful for controls organization - - // Window Box control, shows a window that can be closed - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - [return: MarshalAs(UnmanagedType.I1)] - public static extern bool GuiWindowBox(Rectangle bounds, string text); - - // Group Box control with title name - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void GuiGroupBox(Rectangle bounds, string text); - - // Line separator control - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void GuiLine(Rectangle bounds, string text); - - // Panel control, useful to group controls - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void GuiPanel(Rectangle bounds); - - // Scroll Panel control - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern Rectangle GuiScrollPanel(Rectangle bounds, Rectangle content, ref Vector2 scroll); - - - // Basic controls set - - // Label control, shows text - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void GuiLabel(Rectangle bounds, string text); - - // Button control, returns true when clicked - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - [return: MarshalAs(UnmanagedType.I1)] - public static extern bool GuiButton(Rectangle bounds, string text); - - // Label button control, show true when clicked - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - [return: MarshalAs(UnmanagedType.I1)] - public static extern bool GuiLabelButton(Rectangle bounds, string text); - - // Image button control, returns true when clicked - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - [return: MarshalAs(UnmanagedType.I1)] - public static extern bool GuiImageButton(Rectangle bounds, string text, Texture2D texture); - - // Image button extended control, returns true when clicked - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - [return: MarshalAs(UnmanagedType.I1)] - public static extern bool GuiImageButtonEx(Rectangle bounds, string text, Texture2D texture, Rectangle texSource); - - // Toggle Button control, returns true when active - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - [return: MarshalAs(UnmanagedType.I1)] - public static extern bool GuiToggle(Rectangle bounds, string text, bool active); - - // Toggle Group control, returns active toggle index - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern int GuiToggleGroup(Rectangle bounds, string text, int active); - - // Check Box control, returns true when active - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - [return: MarshalAs(UnmanagedType.I1)] - public static extern bool GuiCheckBox(Rectangle bounds, string text, bool isChecked); - - // Combo Box control, returns selected item index - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern int GuiComboBox(Rectangle bounds, string text, int active); - - // Dropdown Box control, returns selected item - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - [return: MarshalAs(UnmanagedType.I1)] - public static extern bool GuiDropdownBox(Rectangle bounds, string text, ref int active, bool editMode); - - // Spinner control, returns selected value - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - [return: MarshalAs(UnmanagedType.I1)] - public static extern bool GuiSpinner(Rectangle bounds, string text, ref int value, int minValue, int maxValue, bool editMode); - - // Value Box control, updates input text with numbers - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - [return: MarshalAs(UnmanagedType.I1)] - public static extern bool GuiValueBox(Rectangle bounds, string text, ref int value, int minValue, int maxValue, bool editMode); - - // Text Box control, updates input text - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - [return: MarshalAs(UnmanagedType.I1)] - public static extern bool GuiTextBox(Rectangle bounds, StringBuilder text, int textSize, bool freeEdit); - - // Text Box control with multiple lines - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - [return: MarshalAs(UnmanagedType.I1)] - public static extern bool GuiTextBoxMulti(Rectangle bounds, StringBuilder text, int textSize, bool editMode); - - // Slider control, returns selected value - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern float GuiSlider(Rectangle bounds, string textLeft, string textRight, float value, float minValue, float maxValue); - - // Slider Bar control, returns selected value - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern float GuiSliderBar(Rectangle bounds, float value, float minValue, float maxValue); - - // Progress Bar control, shows current progress value - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern float GuiProgressBar(Rectangle bounds, float value, float minValue, float maxValue); - - // Status Bar control, shows info text - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void GuiStatusBar(Rectangle bounds, string text); - - // Dummy control for placeholders - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void GuiDummyRec(Rectangle bounds, string text); - - // Scroll Bar control - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern int GuiScrollBar(Rectangle bounds, int value, int minValue, int maxValue); - - // Grid - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern Vector2 GuiGrid(Rectangle bounds, float spacing, int subdivs); - - - // Advance controls set - - // List View control, returns selected list element index - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern int GuiListView(Rectangle bounds, string text, ref int scrollIndex, ref int active); - - // List View with extended parameters - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern int GuiListViewEx(Rectangle bounds, string text, int count, ref int focus, ref int scrollIndex, ref int active); - - // Message Box control, displays a message - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern int GuiMessageBox(Rectangle bounds, string title, string message); - - // Text Input Box control, ask for text - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern int GuiTextInputBox(Rectangle bounds, string windowTitle, string message, string buttons, string text); - - // Color Picker control - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern Color GuiColorPicker(Rectangle bounds, Color color); - - // Color Panel control - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern Color GuiColorPanel(Rectangle bounds, Color color); - - // Color Bar Alpha control - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern float GuiColorBarAlpha(Rectangle bounds, float alpha); - - // Color Bar Hue control - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern float GuiColorBarHue(Rectangle bounds, float value); - - - // Styles loading functions - - // Load style file (.rgs) - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void GuiLoadStyle(string fileName); - - // Load style default over global style - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void GuiLoadStyleDefault(); - - // Get text with icon id prepended (if supported) - [DllImport(nativeLibName, EntryPoint = "GetMonitorName", CallingConvention = CallingConvention.Cdecl)] - private static extern IntPtr INTERNAL_GuiIconText(int iconId, string text); - public static string GuiIconText(int iconId, string text) - { - return Marshal.PtrToStringUTF8(INTERNAL_GuiIconText(iconId, text)); - } - - - // Gui icons functionality - - // Get full icons data pointer - // IntPtr refers to a unsigned int * - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr GuiGetIcons(); - - // Get icon bit data - // IntPtr refers to a unsigned int * - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr GuiGetIconData(int iconId, string text); - - // Set icon bit data - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void GuiSetIconData(int iconId, uint[] data); - - // Set icon pixel value - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void GuiSetIconPixel(int iconId, int x, int y); - - // Clear icon pixel value - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void GuiClearIconPixel(int iconId, int x, int y); - - // Check icon pixel value - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - [return: MarshalAs(UnmanagedType.I1)] - public static extern bool GuiCheckIconPixel(int iconId, int x, int y); - } -} diff --git a/Raylib-cs.Tests/Raylib-cs.Tests.csproj b/Raylib-cs.Tests/Raylib-cs.Tests.csproj index 1b23439..d9469c1 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 @@ -13,6 +13,6 @@ - + \ No newline at end of file diff --git a/Raylib-cs.Tests/RaylibTests.cs b/Raylib-cs.Tests/RaylibTests.cs index 2203cea..e23651a 100644 --- a/Raylib-cs.Tests/RaylibTests.cs +++ b/Raylib-cs.Tests/RaylibTests.cs @@ -1,43 +1,95 @@ using System; using Xunit; +using Raylib_cs; namespace Raylib_cs.Tests { public class RaylibTests { - // Test if binding structs are blittable. - [Fact] - public void IsBlittable() + private unsafe void CheckType() where T : unmanaged { - Assert.True(BlittableHelper.IsBlittable()); - Assert.True(BlittableHelper.IsBlittable()); - Assert.True(BlittableHelper.IsBlittable()); - Assert.True(BlittableHelper.IsBlittable()); - Assert.True(BlittableHelper.IsBlittable()); - Assert.True(BlittableHelper.IsBlittable()); - Assert.True(BlittableHelper.IsBlittable()); - Assert.True(BlittableHelper.IsBlittable()); - Assert.True(BlittableHelper.IsBlittable()); - Assert.True(BlittableHelper.IsBlittable()); - Assert.True(BlittableHelper.IsBlittable()); - Assert.True(BlittableHelper.IsBlittable()); - Assert.True(BlittableHelper.IsBlittable()); - Assert.True(BlittableHelper.IsBlittable()); - Assert.True(BlittableHelper.IsBlittable()); - Assert.True(BlittableHelper.IsBlittable()); - Assert.True(BlittableHelper.IsBlittable()); - Assert.True(BlittableHelper.IsBlittable()); - Assert.True(BlittableHelper.IsBlittable()); - Assert.True(BlittableHelper.IsBlittable()); - Assert.True(BlittableHelper.IsBlittable()); - Assert.True(BlittableHelper.IsBlittable()); - Assert.True(BlittableHelper.IsBlittable()); - Assert.True(BlittableHelper.IsBlittable()); - Assert.True(BlittableHelper.IsBlittable()); - Assert.True(BlittableHelper.IsBlittable()); - Assert.True(BlittableHelper.IsBlittable()); - Assert.True(BlittableHelper.IsBlittable()); - Assert.True(BlittableHelper.IsBlittable()); + Assert.True(BlittableHelper.IsBlittable()); + } + + [Fact] + public void CheckTypes() + { + CheckType(); + CheckType(); + CheckType(); + CheckType(); + CheckType(); + CheckType(); + CheckType(); + CheckType(); + CheckType(); + CheckType(); + CheckType(); + CheckType(); + CheckType(); + CheckType(); + CheckType(); + CheckType(); + CheckType(); + CheckType(); + CheckType(); + CheckType(); + CheckType(); + CheckType(); + CheckType(); + CheckType(); + CheckType(); + CheckType(); + CheckType(); + CheckType(); + } + + [Fact] + public void TextToInteger() + { + int value = Raylib.TextToInteger("99999"); + Assert.Equal(99999, value); + } + + [Fact] + public void TextToPascal() + { + string input = "hello_world"; + string text = Raylib.TextToPascal(input).ToString(); + Assert.Equal("HelloWorld", text); + } + + [Fact] + public void LoadCodepoints() + { + int count = 0; + string input = "aàáâãäāăąȧXǎȁȃeèéêẽëē"; + int[] codepoints1 = Raylib.LoadCodepoints(input, ref count); + + for (int i = 0; i < input.Length; i++) + { + Assert.Equal(input[i], codepoints1[i]); + } + } + + [Fact] + public void CodepointToUTF8() + { + int byteSize = 0; + string text = Raylib.CodepointToUTF8(224, ref byteSize).ToString(); + Assert.Equal("à", text); + } + + [Fact] + public void TextCodepointsToUTF8() + { + string input = "aàáâãäāăąȧXǎȁȃeèéêẽëē"; + + int count = 0; + int[] codepoints1 = Raylib.LoadCodepoints(input, ref count); + + string text = Raylib.TextCodepointsToUTF8(codepoints1, codepoints1.Length).ToString(); + Assert.Equal(input, text); } } } 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); - } - } -} diff --git a/Raylib-cs/Raylib-cs.csproj b/Raylib-cs/Raylib-cs.csproj index cc4816b..372dd04 100644 --- a/Raylib-cs/Raylib-cs.csproj +++ b/Raylib-cs/Raylib-cs.csproj @@ -1,26 +1,26 @@ - netstandard2.1 + net5.0;net6.0 false Raylib-cs Raylib_cs true false $(NoWarn);1591 - + 10.0 - 3.7.0 - 3.7.0.1 - 3.7.0.1 - Chris Dill, Raysan5 & Others + 4.0.0 + 4.0.0 + 4.0.0 + Chris Dill, Raysan5 true Zlib Raylib-cs C# bindings for raylib - A simple and easy-to-use library to learn videogames programming raylib-cs_64x64.png - Raylib;Raysan;Gamedev;Binding + raylib;bindings;gamedev git https://github.com/ChrisDill/Raylib-cs/ https://www.raylib.com/ @@ -28,15 +28,12 @@ - - - - - + + - + @@ -46,4 +43,11 @@ PreserveNewest - \ No newline at end of file + + + + + + + + diff --git a/Raylib-cs/Raylib.cs b/Raylib-cs/interop/Raylib.cs similarity index 56% rename from Raylib-cs/Raylib.cs rename to Raylib-cs/interop/Raylib.cs index f82720b..8f848c8 100644 --- a/Raylib-cs/Raylib.cs +++ b/Raylib-cs/interop/Raylib.cs @@ -5,1738 +5,25 @@ using System.Security; namespace Raylib_cs { - /// - /// Color type, RGBA (32bit) - /// - [StructLayout(LayoutKind.Sequential)] - public struct Color - { - public byte r; - public byte g; - public byte b; - public byte a; - - // Example - Color.RED instead of RED - // Custom raylib color palette for amazing visuals - public static Color LIGHTGRAY = new Color(200, 200, 200, 255); - public static Color GRAY = new Color(130, 130, 130, 255); - public static Color DARKGRAY = new Color(80, 80, 80, 255); - public static Color YELLOW = new Color(253, 249, 0, 255); - public static Color GOLD = new Color(255, 203, 0, 255); - public static Color ORANGE = new Color(255, 161, 0, 255); - public static Color PINK = new Color(255, 109, 194, 255); - public static Color RED = new Color(230, 41, 55, 255); - public static Color MAROON = new Color(190, 33, 55, 255); - public static Color GREEN = new Color(0, 228, 48, 255); - public static Color LIME = new Color(0, 158, 47, 255); - public static Color DARKGREEN = new Color(0, 117, 44, 255); - public static Color SKYBLUE = new Color(102, 191, 255, 255); - public static Color BLUE = new Color(0, 121, 241, 255); - public static Color DARKBLUE = new Color(0, 82, 172, 255); - public static Color PURPLE = new Color(200, 122, 255, 255); - public static Color VIOLET = new Color(135, 60, 190, 255); - public static Color DARKPURPLE = new Color(112, 31, 126, 255); - public static Color BEIGE = new Color(211, 176, 131, 255); - public static Color BROWN = new Color(127, 106, 79, 255); - public static Color DARKBROWN = new Color(76, 63, 47, 255); - public static Color WHITE = new Color(255, 255, 255, 255); - public static Color BLACK = new Color(0, 0, 0, 255); - public static Color BLANK = new Color(0, 0, 0, 0); - public static Color MAGENTA = new Color(255, 0, 255, 255); - public static Color RAYWHITE = new Color(245, 245, 245, 255); - - public Color(byte r, byte g, byte b, byte a) - { - this.r = r; - this.g = g; - this.b = b; - this.a = a; - } - - public Color(int r, int g, int b, int a) - { - this.r = Convert.ToByte(r); - this.g = Convert.ToByte(g); - this.b = Convert.ToByte(b); - this.a = Convert.ToByte(a); - } - - public override string ToString() - { - return string.Concat(r.ToString(), " ", g.ToString(), " ", b.ToString(), " ", a.ToString()); - } - } - - /// - /// Rectangle type - /// - [StructLayout(LayoutKind.Sequential)] - public struct Rectangle - { - public float x; - public float y; - public float width; - public float height; - - public Rectangle(float x, float y, float width, float height) - { - this.x = x; - this.y = y; - this.width = width; - this.height = height; - } - } - - /// - /// Image type, bpp always RGBA (32bit) - ///
- /// NOTE: Data stored in CPU memory (RAM) - ///
- [StructLayout(LayoutKind.Sequential)] - public struct Image - { - /// - /// Image raw data (void *) - /// - public IntPtr data; - - /// - /// Image base width - /// - public int width; - - /// - /// Image base height - /// - public int height; - - /// - /// Mipmap levels, 1 by default - /// - public int mipmaps; - - /// - /// Data format (PixelFormat type) - /// - public PixelFormat format; - } - - /// - /// Texture2D type - ///
- /// NOTE: Data stored in GPU memory - ///
- [StructLayout(LayoutKind.Sequential)] - public struct Texture2D - { - /// - /// OpenGL texture id - /// - public uint id; - - /// - /// Texture base width - /// - public int width; - - /// - /// Texture base height - /// - public int height; - - /// - /// Mipmap levels, 1 by default - /// - public int mipmaps; - - /// - /// Data format (PixelFormat type) - /// - public PixelFormat format; - } - - /// - /// RenderTexture2D type, for texture rendering - /// - [StructLayout(LayoutKind.Sequential)] - public struct RenderTexture2D - { - /// - /// OpenGL Framebuffer Object (FBO) id - /// - public uint id; - - /// - /// Color buffer attachment texture - /// - public Texture2D texture; - - /// - /// Depth buffer attachment texture - /// - public Texture2D depth; - } - - /// - /// N-Patch layout info - /// - [StructLayout(LayoutKind.Sequential)] - public struct NPatchInfo - { - /// - /// Region in the texture - /// - public Rectangle sourceRec; - - /// - /// left border offset - /// - public int left; - - /// - /// top border offset - /// - public int top; - - /// - /// right border offset - /// - public int right; - - /// - /// bottom border offset - /// - public int bottom; - - /// - /// layout of the n-patch: 3x3, 1x3 or 3x1 - /// - public NPatchLayout layout; - } - - /// - /// Font character info - /// - [StructLayout(LayoutKind.Sequential)] - public struct CharInfo - { - /// - /// Character value (Unicode) - /// - public int value; - - /// - /// Character offset X when drawing - /// - public int offsetX; - - /// - /// Character offset Y when drawing - /// - public int offsetY; - - /// - /// Character advance position X - /// - public int advanceX; - - /// - /// Character image data - /// - public Image image; - } - - /// - /// Font type, includes texture and charSet array data - /// - [StructLayout(LayoutKind.Sequential)] - public struct Font - { - /// - /// Base size (default chars height) - /// - public int baseSize; - - /// - /// Number of characters - /// - public int charsCount; - - /// - /// Padding around the chars - /// - public int charsPadding; - - /// - /// Characters texture atals - /// - public Texture2D texture; - - /// - /// Characters rectangles in texture (Rectangle *) - /// - public IntPtr recs; - - /// - /// Characters info data (CharInfo *) - /// - public IntPtr chars; - } - - /// - /// Camera type, defines a camera position/orientation in 3d space - /// - [StructLayout(LayoutKind.Sequential)] - public struct Camera3D - { - /// - /// Camera position - /// - public Vector3 position; - - /// - /// Camera target it looks-at - /// - public Vector3 target; - - /// - /// Camera up vector (rotation over its axis) - /// - public Vector3 up; - - /// - /// Camera field-of-view apperture in Y (degrees) in perspective, used as near plane width in orthographic - /// - public float fovy; - - /// - /// Camera type, defines projection type: CAMERA_PERSPECTIVE or CAMERA_ORTHOGRAPHIC - /// - public CameraProjection projection; - - public Camera3D(Vector3 position, Vector3 target, Vector3 up, float fovy, CameraProjection projection) - { - this.position = position; - this.target = target; - this.up = up; - this.fovy = fovy; - this.projection = projection; - } - } - - /// Camera2D type, defines a 2d camera - [StructLayout(LayoutKind.Sequential)] - public struct Camera2D - { - /// - /// Camera offset (displacement from target) - /// - public Vector2 offset; - - /// - /// Camera target (rotation and zoom origin) - /// - public Vector2 target; - - /// - /// Camera rotation in degrees - /// - public float rotation; - - /// - /// Camera zoom (scaling), should be 1.0f by default - /// - public float zoom; - - public Camera2D(Vector2 offset, Vector2 target, float rotation, float zoom) - { - this.offset = offset; - this.target = target; - this.rotation = rotation; - this.zoom = zoom; - } - } - - /// - /// Vertex data definning a mesh - /// NOTE: Data stored in CPU memory (and GPU) - /// - [StructLayout(LayoutKind.Sequential)] - public struct Mesh - { - /// - /// Number of vertices stored in arrays - /// - public int vertexCount; - - /// - /// Number of triangles stored (indexed or not) - /// - public int triangleCount; - -#region Default vertex data - - /// - /// 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 second texture coordinates (useful for lightmaps) (shader-location = 5, float *) - /// - public IntPtr texcoords2; - - /// - /// Vertex normals (XYZ - 3 components per vertex) (shader-location = 2, float *) - /// - public IntPtr normals; - - /// - /// Vertex tangents (XYZW - 4 components per vertex) (shader-location = 4, float *) - /// - public IntPtr tangents; - - /// - /// Vertex colors (RGBA - 4 components per vertex) (shader-location = 3, unsigned char *) - /// - public IntPtr colors; - - /// - /// Vertex indices (in case vertex data comes indexed, unsigned short *) - /// - public IntPtr indices; - -#endregion - -#region Animation vertex data - - /// - /// Animated vertex positions (after bones transformations, float *) - /// - public IntPtr animVertices; - - /// - /// Animated normals (after bones transformations, float *) - /// - public IntPtr animNormals; - - /// - /// Vertex bone ids, up to 4 bones influence by vertex (skinning, int *) - /// - public IntPtr boneIds; - - /// - /// Vertex bone weight, up to 4 bones influence by vertex (skinning, float *) - /// - public IntPtr boneWeights; - -#endregion - -#region OpenGL identifiers - - /// - /// OpenGL Vertex Array Object id - /// - public uint vaoId; - - /// - /// OpenGL Vertex Buffer Objects id (default vertex data, uint[]) - /// - public IntPtr vboId; - -#endregion - } - - /// - /// Shader type (generic) - /// - [StructLayout(LayoutKind.Sequential)] - public struct Shader - { - /// - /// Shader program id - /// - public uint id; - - /// - /// Shader locations array (MAX_SHADER_LOCATIONS, int *) - /// - public IntPtr locs; - } - - /// - /// Material texture map - /// - [StructLayout(LayoutKind.Sequential)] - public struct MaterialMap - { - /// - /// Material map texture - /// - public Texture2D texture; - - /// - /// Material map color - /// - public Color color; - - /// - /// Material map value - /// - public float value; - } - - /// - /// Material type (generic) - /// - [StructLayout(LayoutKind.Sequential)] - public struct Material - { - /// - /// Material shader - /// - public Shader shader; - - /// - /// Material maps (MaterialMap *) - /// - public IntPtr maps; - - /// - /// Material generic parameters (if required, float *) - /// - public IntPtr param; - } - - /// - /// Transformation properties - /// - [StructLayout(LayoutKind.Sequential)] - public struct Transform - { - /// - /// Translation - /// - public Vector3 translation; - - /// - /// Rotation - /// - public Vector4 rotation; - - /// - /// Scale - /// - public Vector3 scale; - } - - /// - /// Bone information - /// - [StructLayout(LayoutKind.Sequential)] - public struct BoneInfo - { - /// - /// Bone name (char[32]) - /// - public IntPtr name; - - /// - /// Bone parent - /// - public int parent; - } - - /// - /// Model type - /// - [StructLayout(LayoutKind.Sequential)] - public struct Model - { - /// - /// Local transform matrix - /// - public Matrix4x4 transform; - - /// - /// Number of meshes - /// - public int meshCount; - - /// - /// Number of materials - /// - public int materialCount; - - /// - /// Meshes array (Mesh *) - /// - public IntPtr meshes; - - /// - /// Materials array (Material *) - /// - public IntPtr materials; - - /// - /// Mesh material number (int *) - /// - public IntPtr meshMaterial; - - /// - /// Number of bones - /// - public int boneCount; - - /// - /// Bones information (skeleton, BoneInfo *) - /// - public IntPtr bones; - - /// - /// Bones base transformation (pose, Transform *) - /// - public IntPtr bindPose; - } - - /// Model animation - [StructLayout(LayoutKind.Sequential)] - public struct ModelAnimation - { - - /// - /// Number of bones - /// - public int boneCount; - - /// - /// Number of animation frames - /// - public int frameCount; - - /// - /// Bones information (skeleton, BoneInfo *) - /// - public IntPtr bones; - - /// - /// Poses array by frame (Transform **) - /// - public IntPtr framePoses; - } - - /// Ray type (useful for raycast) - [StructLayout(LayoutKind.Sequential)] - public struct Ray - { - - /// - /// Ray position (origin) - /// - public Vector3 position; - - /// - /// Ray direction - /// - public Vector3 direction; - - public Ray(Vector3 position, Vector3 direction) - { - this.position = position; - this.direction = direction; - } - } - - /// Raycast hit information - [StructLayout(LayoutKind.Sequential)] - public struct RayHitInfo - { - - /// - /// Did the ray hit something? - /// - public byte hit; - - /// - /// Distance to nearest hit - /// - public float distance; - - /// - /// Position of nearest hit - /// - public Vector3 position; - - /// - /// Surface normal of hit - /// - public Vector3 normal; - } - - /// Bounding box type - [StructLayout(LayoutKind.Sequential)] - public struct BoundingBox - { - - /// - /// Minimum vertex box-corner - /// - public Vector3 min; - - /// - /// Maximum vertex box-corner - /// - public Vector3 max; - - public BoundingBox(Vector3 min, Vector3 max) - { - this.min = min; - this.max = max; - } - } - - /// Wave type, defines audio wave data - [StructLayout(LayoutKind.Sequential)] - public struct Wave - { - - /// - /// Number of samples - /// - public uint sampleCount; - - /// - /// Frequency (samples per second) - /// - public uint sampleRate; - - /// - /// Bit depth (bits per sample): 8, 16, 32 (24 not supported) - /// - public uint sampleSize; - - /// - /// Number of channels (1-mono, 2-stereo) - /// - public uint channels; - - /// - /// Buffer data pointer (void *) - /// - public IntPtr data; - } - - /// Audio stream type - /// NOTE: Useful to create custom audio streams not bound to a specific file - [StructLayout(LayoutKind.Sequential)] - public struct AudioStream - { - - /// - /// Pointer to internal data(rAudioBuffer *) used by the audio system - /// - public IntPtr audioBuffer; - - /// - /// Frequency (samples per second) - /// - public uint sampleRate; - - /// - /// Bit depth (bits per sample): 8, 16, 32 (24 not supported) - /// - public uint sampleSize; - - /// - /// Number of channels (1-mono, 2-stereo) - /// - public uint channels; - } - - /// Sound source type - [StructLayout(LayoutKind.Sequential)] - public struct Sound - { - - /// - /// Audio stream - /// - public AudioStream stream; - - /// - /// Total number of samples - /// - public uint sampleCount; - } - - /// Music stream type (audio file streaming from memory) - /// NOTE: Anything longer than ~10 seconds should be streamed - [StructLayout(LayoutKind.Sequential)] - public struct Music - { - - /// - /// Audio stream - /// - public AudioStream stream; - - /// - /// Total number of samples - /// - public uint sampleCount; - - /// - /// Music looping enable - /// - public byte looping; - - /// - /// Type of music context (audio filetype) - /// - public int ctxType; - - /// - /// Audio context data, depends on type (void *) - /// - public IntPtr ctxData; - } - - /// Head-Mounted-Display device parameters - [StructLayout(LayoutKind.Sequential)] - public unsafe struct VrDeviceInfo - { - - /// - /// HMD horizontal resolution in pixels - /// - public int hResolution; - - /// - /// HMD vertical resolution in pixels - /// - public int vResolution; - - /// - /// HMD horizontal size in meters - /// - public float hScreenSize; - - /// - /// HMD vertical size in meters - /// - public float vScreenSize; - - /// - /// HMD screen center in meters - /// - public float vScreenCenter; - - /// - /// HMD distance between eye and display in meters - /// - public float eyeToScreenDistance; - - /// - /// HMD lens separation distance in meters - /// - public float lensSeparationDistance; - - /// - /// HMD IPD (distance between pupils) in meters - /// - public float interpupillaryDistance; - - /// - /// HMD lens distortion constant parameters - /// - public fixed float lensDistortionValues[4]; - - /// - /// HMD chromatic aberration correction parameters - /// - public fixed float chromaAbCorrection[4]; - } - - /// VR Stereo rendering configuration for simulator - [StructLayout(LayoutKind.Sequential)] - public struct VrStereoConfig - { - - /// - /// VR projection matrices (per eye) - /// - public Matrix4x4 projection1; - - /// - /// VR projection matrices (per eye) - /// - public Matrix4x4 projection2; - - /// - /// VR view offset matrices (per eye) - /// - public Matrix4x4 viewOffset1; - - /// - /// VR view offset matrices (per eye) - /// - public Matrix4x4 viewOffset2; - - /// - /// VR left lens center - /// - public Vector2 leftLensCenter; - - /// - /// VR right lens center - /// - public Vector2 rightLensCenter; - - /// - /// VR left screen center - /// - public Vector2 leftScreenCenter; - - /// - /// VR right screen center - /// - public Vector2 rightScreenCenter; - - /// - /// VR distortion scale - /// - public Vector2 scale; - - /// - /// VR distortion scale in - /// - public Vector2 scaleIn; - } - - /// 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 - { - - /// - /// Set to try enabling V-Sync on GPU - /// - FLAG_VSYNC_HINT = 0x00000040, - - /// - /// Set to run program in fullscreen - /// - FLAG_FULLSCREEN_MODE = 0x00000002, - - /// - /// Set to allow resizable window - /// - FLAG_WINDOW_RESIZABLE = 0x00000004, - - /// - /// Set to disable window decoration (frame and buttons) - /// - FLAG_WINDOW_UNDECORATED = 0x00000008, - - /// - /// Set to hide window - /// - FLAG_WINDOW_HIDDEN = 0x00000080, - - /// - /// Set to minimize window (iconify) - /// - FLAG_WINDOW_MINIMIZED = 0x00000200, - - /// - /// Set to maximize window (expanded to monitor) - /// - FLAG_WINDOW_MAXIMIZED = 0x00000400, - - /// - /// Set to window non focused - /// - FLAG_WINDOW_UNFOCUSED = 0x00000800, - - /// - /// Set to window always on top - /// - FLAG_WINDOW_TOPMOST = 0x00001000, - - /// - /// Set to allow windows running while minimized - /// - FLAG_WINDOW_ALWAYS_RUN = 0x00000100, - - /// - /// Set to allow transparent framebuffer - /// - FLAG_WINDOW_TRANSPARENT = 0x00000010, - - /// - /// Set to support HighDPI - /// - FLAG_WINDOW_HIGHDPI = 0x00002000, - - /// - /// Set to try enabling MSAA 4X - /// - FLAG_MSAA_4X_HINT = 0x00000020, - - /// - /// Set to try enabling interlaced video format (for V3D) - /// - FLAG_INTERLACED_HINT = 0x00010000, - } - - /// Trace log level - public enum TraceLogLevel - { - - /// - /// Display all logs - /// - LOG_ALL = 0, - LOG_TRACE, - LOG_DEBUG, - LOG_INFO, - LOG_WARNING, - LOG_ERROR, - LOG_FATAL, - - /// - /// Disable logging - /// - LOG_NONE - } - - /// Keyboard keys (US keyboard layout) - /// NOTE: Use GetKeyPressed() to allow redefining - /// required keys for alternative layouts - public enum KeyboardKey - { - KEY_NULL = 0, - - // Alphanumeric keys - KEY_APOSTROPHE = 39, - KEY_COMMA = 44, - KEY_MINUS = 45, - KEY_PERIOD = 46, - KEY_SLASH = 47, - KEY_ZERO = 48, - KEY_ONE = 49, - KEY_TWO = 50, - KEY_THREE = 51, - KEY_FOUR = 52, - KEY_FIVE = 53, - KEY_SIX = 54, - KEY_SEVEN = 55, - KEY_EIGHT = 56, - KEY_NINE = 57, - KEY_SEMICOLON = 59, - KEY_EQUAL = 61, - KEY_A = 65, - KEY_B = 66, - KEY_C = 67, - KEY_D = 68, - KEY_E = 69, - KEY_F = 70, - KEY_G = 71, - KEY_H = 72, - KEY_I = 73, - KEY_J = 74, - KEY_K = 75, - KEY_L = 76, - KEY_M = 77, - KEY_N = 78, - KEY_O = 79, - KEY_P = 80, - KEY_Q = 81, - KEY_R = 82, - KEY_S = 83, - KEY_T = 84, - KEY_U = 85, - KEY_V = 86, - KEY_W = 87, - KEY_X = 88, - KEY_Y = 89, - KEY_Z = 90, - - // Function keys - KEY_SPACE = 32, - KEY_ESCAPE = 256, - KEY_ENTER = 257, - KEY_TAB = 258, - KEY_BACKSPACE = 259, - KEY_INSERT = 260, - KEY_DELETE = 261, - KEY_RIGHT = 262, - KEY_LEFT = 263, - KEY_DOWN = 264, - KEY_UP = 265, - KEY_PAGE_UP = 266, - KEY_PAGE_DOWN = 267, - KEY_HOME = 268, - KEY_END = 269, - KEY_CAPS_LOCK = 280, - KEY_SCROLL_LOCK = 281, - KEY_NUM_LOCK = 282, - KEY_PRINT_SCREEN = 283, - KEY_PAUSE = 284, - KEY_F1 = 290, - KEY_F2 = 291, - KEY_F3 = 292, - KEY_F4 = 293, - KEY_F5 = 294, - KEY_F6 = 295, - KEY_F7 = 296, - KEY_F8 = 297, - KEY_F9 = 298, - KEY_F10 = 299, - KEY_F11 = 300, - KEY_F12 = 301, - KEY_LEFT_SHIFT = 340, - KEY_LEFT_CONTROL = 341, - KEY_LEFT_ALT = 342, - KEY_LEFT_SUPER = 343, - KEY_RIGHT_SHIFT = 344, - KEY_RIGHT_CONTROL = 345, - KEY_RIGHT_ALT = 346, - KEY_RIGHT_SUPER = 347, - KEY_KB_MENU = 348, - KEY_LEFT_BRACKET = 91, - KEY_BACKSLASH = 92, - KEY_RIGHT_BRACKET = 93, - KEY_GRAVE = 96, - - // Keypad keys - KEY_KP_0 = 320, - KEY_KP_1 = 321, - KEY_KP_2 = 322, - KEY_KP_3 = 323, - KEY_KP_4 = 324, - KEY_KP_5 = 325, - KEY_KP_6 = 326, - KEY_KP_7 = 327, - KEY_KP_8 = 328, - KEY_KP_9 = 329, - KEY_KP_DECIMAL = 330, - KEY_KP_DIVIDE = 331, - KEY_KP_MULTIPLY = 332, - KEY_KP_SUBTRACT = 333, - KEY_KP_ADD = 334, - KEY_KP_ENTER = 335, - KEY_KP_EQUAL = 336, - - // Android key buttons - KEY_BACK = 4, - KEY_MENU = 82, - KEY_VOLUME_UP = 24, - KEY_VOLUME_DOWN = 25 - } - - /// Mouse buttons - public enum MouseButton - { - MOUSE_LEFT_BUTTON = 0, - MOUSE_RIGHT_BUTTON = 1, - MOUSE_MIDDLE_BUTTON = 2 - } - - /// Mouse cursor - public enum MouseCursor - { - MOUSE_CURSOR_DEFAULT = 0, - MOUSE_CURSOR_ARROW = 1, - MOUSE_CURSOR_IBEAM = 2, - MOUSE_CURSOR_CROSSHAIR = 3, - MOUSE_CURSOR_POINTING_HAND = 4, - - /// - /// The horizontal resize/move arrow shape - /// - MOUSE_CURSOR_RESIZE_EW = 5, - - /// - /// The vertical resize/move arrow shape - /// - MOUSE_CURSOR_RESIZE_NS = 6, - - /// - /// The top-left to bottom-right diagonal resize/move arrow shape - /// - MOUSE_CURSOR_RESIZE_NWSE = 7, - - /// - /// The top-right to bottom-left diagonal resize/move arrow shape - /// - MOUSE_CURSOR_RESIZE_NESW = 8, - - /// - /// The omni-directional resize/move cursor shape - /// - MOUSE_CURSOR_RESIZE_ALL = 9, - - /// - /// The operation-not-allowed shape - /// - MOUSE_CURSOR_NOT_ALLOWED = 10 - } - - /// Gamepad buttons - public enum GamepadButton - { - // This is here just for error checking - GAMEPAD_BUTTON_UNKNOWN = 0, - - // This is normally a DPAD - GAMEPAD_BUTTON_LEFT_FACE_UP, - GAMEPAD_BUTTON_LEFT_FACE_RIGHT, - GAMEPAD_BUTTON_LEFT_FACE_DOWN, - GAMEPAD_BUTTON_LEFT_FACE_LEFT, - - // This normally corresponds with PlayStation and Xbox controllers - // XBOX: [Y,X,A,B] - // PS3: [Triangle,Square,Cross,Circle] - // No support for 6 button controllers though.. - GAMEPAD_BUTTON_RIGHT_FACE_UP, - GAMEPAD_BUTTON_RIGHT_FACE_RIGHT, - GAMEPAD_BUTTON_RIGHT_FACE_DOWN, - GAMEPAD_BUTTON_RIGHT_FACE_LEFT, - - // Triggers - GAMEPAD_BUTTON_LEFT_TRIGGER_1, - GAMEPAD_BUTTON_LEFT_TRIGGER_2, - GAMEPAD_BUTTON_RIGHT_TRIGGER_1, - GAMEPAD_BUTTON_RIGHT_TRIGGER_2, - - // These are buttons in the center of the gamepad - - /// - /// PS3 Select - /// - GAMEPAD_BUTTON_MIDDLE_LEFT, - - /// - /// PS Button/XBOX Button - /// - GAMEPAD_BUTTON_MIDDLE, - - /// - /// PS3 Start - /// - GAMEPAD_BUTTON_MIDDLE_RIGHT, - - /// - /// Left joystick press button - /// - GAMEPAD_BUTTON_LEFT_THUMB, - - /// - /// Right joystick press button - /// - GAMEPAD_BUTTON_RIGHT_THUMB - } - - /// Gamepad axis - public enum GamepadAxis - { - - /// - /// Gamepad left stick X axis - /// - GAMEPAD_AXIS_LEFT_X = 0, - - /// - /// Gamepad left stick Y axis - /// - GAMEPAD_AXIS_LEFT_Y = 1, - - /// - /// Gamepad right stick X axis - /// - GAMEPAD_AXIS_RIGHT_X = 2, - - /// - /// Gamepad right stick Y axis - /// - GAMEPAD_AXIS_RIGHT_Y = 3, - - /// - /// Gamepad back trigger left, pressure level: [1..-1] - /// - GAMEPAD_AXIS_LEFT_TRIGGER = 4, - - /// - /// Gamepad back trigger right, pressure level: [1..-1] - /// - GAMEPAD_AXIS_RIGHT_TRIGGER = 5 - } - - /// Material map index - public enum MaterialMapIndex - { - - /// - /// MAP_DIFFUSE - /// - MATERIAL_MAP_ALBEDO = 0, - - /// - /// MAP_SPECULAR - /// - MATERIAL_MAP_METALNESS = 1, - MATERIAL_MAP_NORMAL = 2, - MATERIAL_MAP_ROUGHNESS = 3, - MATERIAL_MAP_OCCLUSION, - MATERIAL_MAP_EMISSION, - MATERIAL_MAP_HEIGHT, - MATERIAL_MAP_BRDF, - /// - /// NOTE: Uses GL_TEXTURE_CUBE_MAP - /// - MATERIAL_MAP_CUBEMAP, - - /// - /// NOTE: Uses GL_TEXTURE_CUBE_MAP - /// - MATERIAL_MAP_IRRADIANCE, - - /// - /// NOTE: Uses GL_TEXTURE_CUBE_MAP - /// - MATERIAL_MAP_PREFILTER, - - MATERIAL_MAP_DIFFUSE = MATERIAL_MAP_ALBEDO, - MATERIAL_MAP_SPECULAR = MATERIAL_MAP_METALNESS, - } - - /// Shader location index - public enum ShaderLocationIndex - { - SHADER_LOC_VERTEX_POSITION = 0, - SHADER_LOC_VERTEX_TEXCOORD01, - SHADER_LOC_VERTEX_TEXCOORD02, - SHADER_LOC_VERTEX_NORMAL, - SHADER_LOC_VERTEX_TANGENT, - SHADER_LOC_VERTEX_COLOR, - SHADER_LOC_MATRIX_MVP, - SHADER_LOC_MATRIX_VIEW, - SHADER_LOC_MATRIX_PROJECTION, - SHADER_LOC_MATRIX_MODEL, - SHADER_LOC_MATRIX_NORMAL, - SHADER_LOC_VECTOR_VIEW, - SHADER_LOC_COLOR_DIFFUSE, - SHADER_LOC_COLOR_SPECULAR, - SHADER_LOC_COLOR_AMBIENT, - - /// - /// SHADER_LOC_MAP_DIFFUSE - /// - SHADER_LOC_MAP_ALBEDO, - - /// - /// SHADER_LOC_MAP_SPECULAR - /// - SHADER_LOC_MAP_METALNESS, - SHADER_LOC_MAP_NORMAL, - SHADER_LOC_MAP_ROUGHNESS, - SHADER_LOC_MAP_OCCLUSION, - SHADER_LOC_MAP_EMISSION, - SHADER_LOC_MAP_HEIGHT, - SHADER_LOC_MAP_CUBEMAP, - SHADER_LOC_MAP_IRRADIANCE, - SHADER_LOC_MAP_PREFILTER, - SHADER_LOC_MAP_BRDF, - - SHADER_LOC_MAP_DIFFUSE = SHADER_LOC_MAP_ALBEDO, - SHADER_LOC_MAP_SPECULAR = SHADER_LOC_MAP_METALNESS, - } - - /// Shader uniform data type - public enum ShaderUniformDataType - { - SHADER_UNIFORM_FLOAT = 0, - SHADER_UNIFORM_VEC2, - SHADER_UNIFORM_VEC3, - SHADER_UNIFORM_VEC4, - SHADER_UNIFORM_INT, - SHADER_UNIFORM_IVEC2, - SHADER_UNIFORM_IVEC3, - SHADER_UNIFORM_IVEC4, - SHADER_UNIFORM_SAMPLER2D - } - - /// Pixel formats - /// NOTE: Support depends on OpenGL version and platform - public enum PixelFormat - { - - /// - /// 8 bit per pixel (no alpha) - /// - PIXELFORMAT_UNCOMPRESSED_GRAYSCALE = 1, - - /// - /// 8*2 bpp (2 channels) - /// - PIXELFORMAT_UNCOMPRESSED_GRAY_ALPHA, - - /// - /// 16 bpp - /// - PIXELFORMAT_UNCOMPRESSED_R5G6B5, - - /// - /// 24 bpp - /// - PIXELFORMAT_UNCOMPRESSED_R8G8B8, - - /// - /// 16 bpp (1 bit alpha) - /// - PIXELFORMAT_UNCOMPRESSED_R5G5B5A1, - - /// - /// 16 bpp (4 bit alpha) - /// - PIXELFORMAT_UNCOMPRESSED_R4G4B4A4, - - /// - /// 32 bpp - /// - PIXELFORMAT_UNCOMPRESSED_R8G8B8A8, - - /// - /// 32 bpp (1 channel - float) - /// - PIXELFORMAT_UNCOMPRESSED_R32, - - /// - /// 32*3 bpp (3 channels - float) - /// - PIXELFORMAT_UNCOMPRESSED_R32G32B32, - - /// - /// 32*4 bpp (4 channels - float) - /// - PIXELFORMAT_UNCOMPRESSED_R32G32B32A32, - - /// - /// 4 bpp (no alpha) - /// - PIXELFORMAT_COMPRESSED_DXT1_RGB, - - /// - /// 4 bpp (1 bit alpha) - /// - PIXELFORMAT_COMPRESSED_DXT1_RGBA, - - /// - /// 8 bpp - /// - PIXELFORMAT_COMPRESSED_DXT3_RGBA, - - /// - /// 8 bpp - /// - PIXELFORMAT_COMPRESSED_DXT5_RGBA, - - /// - /// 4 bpp - /// - PIXELFORMAT_COMPRESSED_ETC1_RGB, - - /// - /// 4 bpp - /// - PIXELFORMAT_COMPRESSED_ETC2_RGB, - - /// - /// 8 bpp - /// - PIXELFORMAT_COMPRESSED_ETC2_EAC_RGBA, - - /// - /// 4 bpp - /// - PIXELFORMAT_COMPRESSED_PVRT_RGB, - - /// - /// 4 bpp - /// - PIXELFORMAT_COMPRESSED_PVRT_RGBA, - - /// - /// 8 bpp - /// - PIXELFORMAT_COMPRESSED_ASTC_4x4_RGBA, - - /// - /// 2 bpp - /// - PIXELFORMAT_COMPRESSED_ASTC_8x8_RGBA - } - - /// 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 - { - - /// - /// No filter, just pixel aproximation - /// - TEXTURE_FILTER_POINT = 0, - - /// - /// Linear filtering - /// - TEXTURE_FILTER_BILINEAR, - - /// - /// Trilinear filtering (linear with mipmaps) - /// - TEXTURE_FILTER_TRILINEAR, - - /// - /// Anisotropic filtering 4x - /// - TEXTURE_FILTER_ANISOTROPIC_4X, - - /// - /// Anisotropic filtering 8x - /// - TEXTURE_FILTER_ANISOTROPIC_8X, - - /// - /// Anisotropic filtering 16x - /// - TEXTURE_FILTER_ANISOTROPIC_16X, - } - - /// Texture parameters: wrap mode - public enum TextureWrap - { - - /// - /// Repeats texture in tiled mode - /// - TEXTURE_WRAP_REPEAT = 0, - - /// - /// Clamps texture to edge pixel in tiled mode - /// - TEXTURE_WRAP_CLAMP, - - /// - /// Mirrors and repeats the texture in tiled mode - /// - TEXTURE_WRAP_MIRROR_REPEAT, - - /// - /// Mirrors and clamps to border the texture in tiled mode - /// - TEXTURE_WRAP_MIRROR_CLAMP - } - - /// Cubemap layouts - public enum CubemapLayout - { - - /// - /// Automatically detect layout type - /// - CUBEMAP_LAYOUT_AUTO_DETECT = 0, - - /// - /// Layout is defined by a vertical line with faces - /// - CUBEMAP_LAYOUT_LINE_VERTICAL, - - /// - /// Layout is defined by an horizontal line with faces - /// - CUBEMAP_LAYOUT_LINE_HORIZONTAL, - - /// - /// Layout is defined by a 3x4 cross with cubemap faces - /// - CUBEMAP_LAYOUT_CROSS_THREE_BY_FOUR, - - /// - /// Layout is defined by a 4x3 cross with cubemap faces - /// - CUBEMAP_LAYOUT_CROSS_FOUR_BY_THREE, - - /// - /// Layout is defined by a panorama image (equirectangular map) - /// - CUBEMAP_LAYOUT_PANORAMA - } - - /// Font type, defines generation method - public enum FontType - { - - /// - /// Default font generation, anti-aliased - /// - FONT_DEFAULT = 0, - - /// - /// Bitmap font generation, no anti-aliasing - /// - FONT_BITMAP, - - /// - /// SDF font generation, requires external shader - /// - FONT_SDF - } - - /// Color blending modes (pre-defined) - public enum BlendMode - { - - /// - /// Blend textures considering alpha (default) - /// - BLEND_ALPHA = 0, - - /// - /// Blend textures adding colors - /// - BLEND_ADDITIVE, - - /// - /// Blend textures multiplying colors - /// - BLEND_MULTIPLIED, - - /// - /// Blend textures adding colors (alternative) - /// - BLEND_ADD_COLORS, - - /// - /// Blend textures subtracting colors (alternative) - /// - BLEND_SUBTRACT_COLORS, - - /// - /// Belnd textures using custom src/dst factors (use rlSetBlendMode()) - /// - BLEND_CUSTOM - } - - /// Gestures - /// NOTE: It could be used as flags to enable only some gestures - [Flags] - public enum Gestures - { - GESTURE_NONE = 0, - GESTURE_TAP = 1, - GESTURE_DOUBLETAP = 2, - GESTURE_HOLD = 4, - GESTURE_DRAG = 8, - GESTURE_SWIPE_RIGHT = 16, - GESTURE_SWIPE_LEFT = 32, - GESTURE_SWIPE_UP = 64, - GESTURE_SWIPE_DOWN = 128, - GESTURE_PINCH_IN = 256, - GESTURE_PINCH_OUT = 512 - } - - /// Camera system modes - public enum CameraMode - { - CAMERA_CUSTOM = 0, - CAMERA_FREE, - CAMERA_ORBITAL, - CAMERA_FIRST_PERSON, - CAMERA_THIRD_PERSON - } - - /// Camera projection - public enum CameraProjection - { - CAMERA_PERSPECTIVE = 0, - CAMERA_ORTHOGRAPHIC - } - - /// N-patch layout - public enum NPatchLayout - { - - /// - /// Npatch defined by 3x3 tiles - /// - NPATCH_NINE_PATCH = 0, - - /// - /// Npatch defined by 1x3 tiles - /// - NPATCH_THREE_PATCH_VERTICAL, - - /// - /// Npatch defined by 3x1 tiles - /// - NPATCH_THREE_PATCH_HORIZONTAL - } - [SuppressUnmanagedCodeSecurity] - public static class Raylib + public static unsafe partial class Raylib { - // Used by DllImport to load the native library. + /// + /// Used by DllImport to load the native library + /// public const string nativeLibName = "raylib"; - public const string RAYLIB_VERSION = "3.7"; + public const string RAYLIB_VERSION = "4.0"; public const float DEG2RAD = MathF.PI / 180.0f; public const float RAD2DEG = 180.0f / MathF.PI; - public const int MAX_SHADER_LOCATIONS = 32; - public const int MAX_MATERIAL_MAPS = 12; - public const int MAX_TOUCH_POINTS = 10; - - // Callbacks to hook some internal functions - // WARNING: This callbacks are intended for advance users - - // Logging: Redirect trace log messages - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public delegate void TraceLogCallback(TraceLogLevel logLevel, string text, IntPtr args); - - // FileIO: Load binary data - // IntPtr refers to a unsigned char * - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public delegate IntPtr LoadFileDataCallback(string fileName, ref int bytesRead); - - // FileIO: Save binary data - // IntPtr refers to a void * - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public delegate bool SaveFileDataCallback(string fileName, IntPtr data, ref int bytesToWrite); - - // FileIO: Load text data - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public delegate string LoadFileTextCallback(string fileName); - - // FileIO: Save text data - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public delegate bool SaveFileTextCallback(string fileName, string text); - - // Returns color with alpha applied, alpha goes from 0.0f to 1.0f - // NOTE: Added for compatability with previous versions + /// + /// 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); - //------------------------------------------------------------------------------------ // Window and Graphics Device Functions (Module: core) //------------------------------------------------------------------------------------ @@ -1745,12 +32,11 @@ namespace Raylib_cs /// Initialize window and OpenGL context [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void InitWindow(int width, int height, [MarshalAs(UnmanagedType.LPUTF8Str)] string title); + public static extern void InitWindow(int width, int height, sbyte* title); /// 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)] @@ -1758,48 +44,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)] @@ -1827,7 +104,7 @@ namespace Raylib_cs /// Set title for window (only PLATFORM_DESKTOP) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void SetWindowTitle([MarshalAs(UnmanagedType.LPUTF8Str)] string title); + public static extern void SetWindowTitle(sbyte* title); /// Set window position on screen (only PLATFORM_DESKTOP) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -1845,10 +122,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)] @@ -1899,29 +175,33 @@ namespace Raylib_cs public static extern Vector2 GetWindowScaleDPI(); /// Get the human-readable, UTF-8 encoded name of the primary monitor - [DllImport(nativeLibName, EntryPoint = "GetMonitorName", CallingConvention = CallingConvention.Cdecl)] - private static extern IntPtr INTERNAL_GetMonitorName(int monitor); - - /// Get the human-readable, UTF-8 encoded name of the primary monitor - public static string GetMonitorName(int monitor) - { - return Marshal.PtrToStringUTF8(INTERNAL_GetMonitorName(monitor)); - } + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern sbyte* GetMonitorName(int monitor); /// Get clipboard text content - [DllImport(nativeLibName, EntryPoint = "GetClipboardText", CallingConvention = CallingConvention.Cdecl)] - private static extern IntPtr INTERNAL_GetClipboardText(); - - /// Get clipboard text content - public static string GetClipboardText() - { - return Marshal.PtrToStringUTF8(INTERNAL_GetClipboardText()); - } + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern sbyte* GetClipboardText(); /// Set clipboard text content [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void SetClipboardText([MarshalAs(UnmanagedType.LPUTF8Str)] string text); + public static extern void SetClipboardText(sbyte* text); + // Custom frame control functions + // NOTE: Those functions are intended for advance users that want full control over the frame processing + // By default EndDrawing() does this job: draws everything + SwapScreenBuffer() + manage frame timming + PollInputEvents() + // To avoid that behaviour and control frame processes manually, enable in config.h: SUPPORT_CUSTOM_FRAME_CONTROL + + /// Swap back buffer with front buffer (screen drawing) + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern void SwapScreenBuffer(); + + /// Register all input events + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern void PollInputEvents(); + + /// Wait for some milliseconds (halt program execution) + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern void WaitTime(float ms); // Cursor-related functions @@ -1935,8 +215,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)] @@ -1948,8 +227,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 @@ -2038,39 +316,27 @@ namespace Raylib_cs /// Load shader from files and bind default locations [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern Shader LoadShader(string vsFileName, string fsFileName); + public static extern Shader LoadShader(sbyte* vsFileName, sbyte* fsFileName); /// Load shader from code strings and bind default locations [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern Shader LoadShaderFromMemory(string vsCode, string fsCode); + public static extern Shader LoadShaderFromMemory(sbyte* vsCode, sbyte* fsCode); /// Get shader uniform location [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern int GetShaderLocation(Shader shader, string uniformName); + public static extern int GetShaderLocation(Shader shader, sbyte* uniformName); /// Get shader attribute location [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern int GetShaderLocationAttrib(Shader shader, string attribName); + public static extern int GetShaderLocationAttrib(Shader shader, sbyte* attribName); - /// Set shader uniform value - /// 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 - /// value refers to a const void * + /// Set shader uniform value vector [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void SetShaderValue(Shader shader, int uniformLoc, ref int value, ShaderUniformDataType uniformType); - - /// Set shader uniform value - /// value refers to a const void * - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void SetShaderValue(Shader shader, int uniformLoc, ref float value, ShaderUniformDataType uniformType); - - /// 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); + 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)] @@ -2141,9 +407,13 @@ namespace Raylib_cs [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int GetRandomValue(int min, int max); + /// Set the seed for the random number generator + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern int SetRandomSeed(uint seed); + /// Takes a screenshot of current screen (saved a .png) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void TakeScreenshot(string fileName); + public static extern void TakeScreenshot(sbyte* fileName); /// Setup window configuration flags (view FLAGS) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -2151,7 +421,7 @@ namespace Raylib_cs /// Show trace log messages (LOG_DEBUG, LOG_INFO, LOG_WARNING, LOG_ERROR) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void TraceLog(TraceLogLevel logLevel, string text); + public static extern void TraceLog(TraceLogLevel logLevel, sbyte* text); /// Set the current threshold (minimum) log level [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -2159,15 +429,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 @@ -2175,55 +445,106 @@ namespace Raylib_cs /// Set custom trace log [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void SetTraceLogCallback(TraceLogCallback callback); + public static extern void SetTraceLogCallback(delegate* unmanaged[Cdecl] callback); /// Set custom file binary data loader [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void SetLoadFileDataCallback(LoadFileDataCallback callback); + public static extern void SetLoadFileDataCallback(delegate* unmanaged[Cdecl] callback); /// Set custom file binary data saver [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void SetSaveFileDataCallback(SaveFileDataCallback callback); + public static extern void SetSaveFileDataCallback(delegate* unmanaged[Cdecl] callback); /// Set custom file text data loader [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void SetLoadFileTextCallback(LoadFileTextCallback callback); + public static extern void SetLoadFileTextCallback(delegate* unmanaged[Cdecl] callback); /// Set custom file text data saver [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void SetSaveFileTextCallback(SaveFileTextCallback callback); + public static extern void SetSaveFileTextCallback(delegate* unmanaged[Cdecl] callback); // 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(sbyte* fileName, uint* 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)] - [return: MarshalAs(UnmanagedType.I1)] - public static extern bool SaveFileData(string fileName, IntPtr data, int bytesToWrite); + public static extern CBool SaveFileData(sbyte* fileName, void* data, uint bytesToWrite); + + // Load text data from file (read), returns a '\0' terminated string + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern char* LoadFileText(sbyte* fileName); + + // Unload file text data allocated by LoadFileText() + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern void UnloadFileText(char* text); + + // Save text data to file (write), string must be '\0' terminated, returns true on success + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern CBool SaveFileText(sbyte* fileName, char* text); + + // Check if file exists + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern CBool FileExists(sbyte* fileName); + + // Check if a directory path exists + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern CBool DirectoryExists(sbyte* dirPath); /// 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(sbyte* fileName, sbyte* ext); + + /// Get pointer to extension for a filename string (includes dot: '.png') + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern sbyte* GetFileExtension(sbyte* fileName); + + /// Get pointer to filename for a path string + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern sbyte* GetFileName(sbyte* filePath); + + /// Get filename string without extension (uses static string) + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern sbyte* GetFileNameWithoutExt(sbyte* filePath); + + /// Get full path for a given fileName with path (uses static string) + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern sbyte* GetDirectoryPath(sbyte* filePath); + + /// Get previous directory path for a given path (uses static string) + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern sbyte* GetPrevDirectoryPath(sbyte* dirPath); + + /// Get current working directory (uses static string) + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern sbyte* GetWorkingDirectory(); + + /// Get filenames in a directory path (memory should be freed) + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern char** GetDirectoryFiles(sbyte* dirPath, int* count); + + /// Clear directory files paths buffers (free memory) + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern void ClearDirectoryFiles(); + + /// Change working directory, return true on success + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern CBool ChangeDirectory(sbyte* dir); /// 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)] - public static extern IntPtr GetDroppedFiles(ref int count); + public static extern sbyte** GetDroppedFiles(int* count); /// Clear dropped files paths buffer (free memory) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -2231,23 +552,33 @@ namespace Raylib_cs /// Get file modification time (last write time) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern int GetFileModTime(string fileName); + public static extern int GetFileModTime(sbyte* fileName); - /// Compress data (DEFLATE algorythm) - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr CompressData(byte[] data, int dataLength, ref int compDataLength); - /// Decompress data (DEFLATE algorythm) + // Compression/Encoding functionality + + /// Compress data (DEFLATE algorithm) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr DecompressData(byte[] compData, int compDataLength, ref int dataLength); + public static extern byte* CompressData(byte* data, int dataLength, int* compDataLength); + + /// Decompress data (DEFLATE algorithm) + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern byte* DecompressData(byte* compData, int compDataLength, int* dataLength); + + /// Encode data to Base64 string + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern sbyte* EncodeDataBase64(byte* data, int dataLength, int* outputLength); + + /// Decode Base64 string data + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern byte* DecodeDataBase64(byte* data, int* outputLength); // Persistent storage management /// 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)] @@ -2255,7 +586,7 @@ namespace Raylib_cs /// Open URL with default system browser (if available) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void OpenURL(string url); + public static extern void OpenURL(sbyte* url); //------------------------------------------------------------------------------------ // Input Handling Functions (Module: core) @@ -2265,23 +596,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)] @@ -2300,43 +627,27 @@ 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); - /// Check gamepad name (if available) + /// Return gamepad internal name id [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - [return: MarshalAs(UnmanagedType.I1)] - public static extern bool IsGamepadName(int gamepad, string name); - - /// Return gamepad internal name id - [DllImport(nativeLibName, EntryPoint = "GetGamepadName", CallingConvention = CallingConvention.Cdecl)] - private static extern IntPtr INTERNAL_GetGamepadName(int gamepad); - - /// Return gamepad internal name id - public static string GetGamepadName(int gamepad) - { - return Marshal.PtrToStringUTF8(INTERNAL_GetGamepadName(gamepad)); - } + public static extern sbyte* GetGamepadName(int gamepad); /// 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)] @@ -2352,30 +663,26 @@ namespace Raylib_cs /// Set internal gamepad mappings (SDL_GameControllerDB) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern int SetGamepadMappings(string mappings); + public static extern int SetGamepadMappings(sbyte* mappings); // Input-related functions: mouse /// 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)] @@ -2389,6 +696,10 @@ namespace Raylib_cs [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Vector2 GetMousePosition(); + /// Get mouse delta between frames + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern Vector2 GetMouseDelta(); + /// Set mouse position XY [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SetMousePosition(int x, int y); @@ -2424,22 +735,30 @@ namespace Raylib_cs [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Vector2 GetTouchPosition(int index); + /// Get touch point identifier for given index + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern int GetTouchPointId(int index); + + /// Get number of touch points + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern int GetTouchPointCount(); + //------------------------------------------------------------------------------------ // Gestures and Touch Handling Functions (Module: gestures) //------------------------------------------------------------------------------------ /// 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 CBool 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)] @@ -2475,7 +794,7 @@ namespace Raylib_cs /// Update camera position for selected mode [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void UpdateCamera(ref Camera3D camera); + public static extern void UpdateCamera(Camera3D* camera); /// Set camera pan key to combine with mouse movement (free camera) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -2497,9 +816,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); @@ -2533,9 +852,14 @@ namespace Raylib_cs [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void DrawLineBezierQuad(Vector2 startPos, Vector2 endPos, Vector2 controlPos, float thick, Color color); + /// Draw line using cubic bezier curves with 2 control points + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern void DrawLineBezierCubic(Vector2 startPos, Vector2 endPos, Vector2 startControlPos, Vector2 endControlPos, float thick, Color color); + + /// Draw lines sequence [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void DrawLineStrip(Vector2[] points, int numPoints, Color color); + public static extern void DrawLineStrip(Vector2* points, int numPoints, Color color); /// Draw a color-filled circle [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -2631,11 +955,11 @@ namespace Raylib_cs /// Draw a triangle fan defined by points (first vertex is the center) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void DrawTriangleFan(Vector2[] points, int numPoints, Color color); + public static extern void DrawTriangleFan(Vector2* points, int numPoints, Color color); /// Draw a triangle strip defined by points [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void DrawTriangleStrip(Vector2[] points, int pointsCount, Color color); + public static extern void DrawTriangleStrip(Vector2* points, int pointsCount, Color color); /// Draw a regular polygon (Vector version) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -2645,43 +969,43 @@ namespace Raylib_cs [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void DrawPolyLines(Vector2 center, int sides, float radius, float rotation, Color color); + /// Draw a polygon outline of n sides with extended parameters + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern void DrawPolyLinesEx(Vector2 center, int sides, float radius, float rotation, float lineThick, Color color); // Basic shapes collision detection functions /// 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, 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 CBool CheckCollisionPointLine(Vector2 point, Vector2 p1, Vector2 p2, int threshold); /// Get collision rectangle for two rectangles collision [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -2697,20 +1021,27 @@ namespace Raylib_cs /// Load image from file into CPU memory (RAM) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern Image LoadImage(string fileName); + public static extern Image LoadImage(sbyte* fileName); /// Load image from RAW file data [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern Image LoadImageRaw(string fileName, int width, int height, PixelFormat format, int headerSize); + public static extern Image LoadImageRaw(sbyte* fileName, int width, int height, PixelFormat format, int headerSize); /// Load image sequence from file (frames appended to image.data) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern Image LoadImageAnim(string fileName, ref int frames); + public static extern Image LoadImageAnim(sbyte* fileName, 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(sbyte* fileType, byte* fileData, int dataSize); + + /// Load image from GPU texture data + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern Image LoadImageFromTexture(Texture2D texture); + + /// Load image from screen buffer and (screenshot) + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern Image LoadImageFromScreen(); /// Unload image from CPU memory (RAM) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -2718,11 +1049,11 @@ namespace Raylib_cs /// Export image data to file [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void ExportImage(Image image, string fileName); + public static extern void ExportImage(Image image, sbyte* fileName); /// Export image as code file defining an array of bytes [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void ExportImageAsCode(Image image, string fileName); + public static extern void ExportImageAsCode(Image image, sbyte* fileName); // Image generation functions @@ -2751,10 +1082,6 @@ namespace Raylib_cs [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Image GenImageWhiteNoise(int width, int height, float factor); - /// Generate image: perlin noise - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern Image GenImagePerlinNoise(int width, int height, int offsetX, int offsetY, float scale); - /// Generate image: cellular algorithm. Bigger tileSize means bigger cells [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Image GenImageCellular(int width, int height, int tileSize); @@ -2772,183 +1099,183 @@ namespace Raylib_cs /// Create an image from text (default font) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern Image ImageText([MarshalAs(UnmanagedType.LPUTF8Str)] string text, int fontSize, Color color); + public static extern Image ImageText(sbyte* text, int fontSize, Color color); /// Create an image from text (custom sprite font) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern Image ImageTextEx(Font font, [MarshalAs(UnmanagedType.LPUTF8Str)] string text, float fontSize, float spacing, Color tint); + public static extern Image ImageTextEx(Font font, sbyte* text, float fontSize, float spacing, Color tint); /// Convert image to POT (power-of-two) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void ImageToPOT(ref Image image, Color fill); + public static extern void ImageToPOT(Image* image, Color fill); /// Convert image data to desired format [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void ImageFormat(ref Image image, PixelFormat newFormat); + public static extern void ImageFormat(Image* image, PixelFormat newFormat); /// Apply alpha mask to image [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void ImageAlphaMask(ref Image image, Image alphaMask); + public static extern void ImageAlphaMask(Image* image, Image alphaMask); /// Clear alpha channel to desired color [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void ImageAlphaClear(ref Image image, Color color, float threshold); + public static extern void ImageAlphaClear(Image* image, Color color, float threshold); /// Crop image depending on alpha value [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void ImageAlphaCrop(ref Image image, float threshold); + public static extern void ImageAlphaCrop(Image* image, float threshold); /// Premultiply alpha channel [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void ImageAlphaPremultiply(ref Image image); + public static extern void ImageAlphaPremultiply(Image* image); /// Crop an image to a defined rectangle [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void ImageCrop(ref Image image, Rectangle crop); + public static extern void ImageCrop(Image* image, Rectangle crop); /// Resize image (Bicubic scaling algorithm) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void ImageResize(ref Image image, int newWidth, int newHeight); + public static extern void ImageResize(Image* image, int newWidth, int newHeight); /// Resize image (Nearest-Neighbor scaling algorithm) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void ImageResizeNN(ref Image image, int newWidth, int newHeight); + public static extern void ImageResizeNN(Image* image, int newWidth, int newHeight); /// Resize canvas and fill with color [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void ImageResizeCanvas(ref Image image, int newWidth, int newHeight, int offsetX, int offsetY, Color color); + public static extern void ImageResizeCanvas(Image* image, int newWidth, int newHeight, int offsetX, int offsetY, Color color); /// Generate all mipmap levels for a provided image [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void ImageMipmaps(ref Image image); + public static extern void ImageMipmaps(Image* image); /// Dither image data to 16bpp or lower (Floyd-Steinberg dithering) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void ImageDither(ref Image image, int rBpp, int gBpp, int bBpp, int aBpp); + public static extern void ImageDither(Image* image, int rBpp, int gBpp, int bBpp, int aBpp); /// Flip image vertically [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void ImageFlipVertical(ref Image image); + public static extern void ImageFlipVertical(Image* image); /// Flip image horizontally [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void ImageFlipHorizontal(ref Image image); + public static extern void ImageFlipHorizontal(Image* image); /// Rotate image clockwise 90deg [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void ImageRotateCW(ref Image image); + public static extern void ImageRotateCW(Image* image); /// Rotate image counter-clockwise 90deg [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void ImageRotateCCW(ref Image image); + public static extern void ImageRotateCCW(Image* image); /// Modify image color: tint [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void ImageColorTint(ref Image image, Color color); + public static extern void ImageColorTint(Image* image, Color color); /// Modify image color: invert [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void ImageColorInvert(ref Image image); + public static extern void ImageColorInvert(Image* image); /// Modify image color: grayscale [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void ImageColorGrayscale(ref Image image); + public static extern void ImageColorGrayscale(Image* image); /// Modify image color: contrast (-100 to 100) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void ImageColorContrast(ref Image image, float contrast); + public static extern void ImageColorContrast(Image* image, float contrast); /// Modify image color: brightness (-255 to 255) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void ImageColorBrightness(ref Image image, int brightness); + public static extern void ImageColorBrightness(Image* image, int brightness); /// Modify image color: replace color [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void ImageColorReplace(ref Image image, Color color, Color replace); + public static extern void ImageColorReplace(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, 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)] public static extern Rectangle GetImageAlphaBorder(Image image, float threshold); + /// Get image pixel color at (x, y) position + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern Color GetImageColor(Image image, int x, int y); + // Image drawing functions // NOTE: Image software-rendering functions (CPU) /// Clear image background with given color [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void ImageClearBackground(ref Image dst, Color color); + public static extern void ImageClearBackground(Image* dst, Color color); /// Draw pixel within an image [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void ImageDrawPixel(ref Image dst, int posX, int posY, Color color); + public static extern void ImageDrawPixel(Image* dst, int posX, int posY, Color color); /// Draw pixel within an image (Vector version) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void ImageDrawPixelV(ref Image dst, Vector2 position, Color color); + public static extern void ImageDrawPixelV(Image* dst, Vector2 position, Color color); /// Draw line within an image [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void ImageDrawLine(ref Image dst, int startPosX, int startPosY, int endPosX, int endPosY, Color color); + public static extern void ImageDrawLine(Image* dst, int startPosX, int startPosY, int endPosX, int endPosY, Color color); /// Draw line within an image (Vector version) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void ImageDrawLineV(ref Image dst, Vector2 start, Vector2 end, Color color); + public static extern void ImageDrawLineV(Image* dst, Vector2 start, Vector2 end, Color color); /// Draw circle within an image [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void ImageDrawCircle(ref Image dst, int centerX, int centerY, int radius, Color color); + public static extern void ImageDrawCircle(Image* dst, int centerX, int centerY, int radius, Color color); /// Draw circle within an image (Vector version) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void ImageDrawCircleV(ref Image dst, Vector2 center, int radius, Color color); + public static extern void ImageDrawCircleV(Image* dst, Vector2 center, int radius, Color color); /// Draw rectangle within an image [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void ImageDrawRectangle(ref Image dst, int posX, int posY, int width, int height, Color color); + public static extern void ImageDrawRectangle(Image* dst, int posX, int posY, int width, int height, Color color); /// Draw rectangle within an image (Vector version) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void ImageDrawRectangleV(ref Image dst, Vector2 position, Vector2 size, Color color); + public static extern void ImageDrawRectangleV(Image* dst, Vector2 position, Vector2 size, Color color); /// Draw rectangle within an image [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void ImageDrawRectangleRec(ref Image dst, Rectangle rec, Color color); + public static extern void ImageDrawRectangleRec(Image* dst, Rectangle rec, Color color); /// Draw rectangle lines within an image [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void ImageDrawRectangleLines(ref Image dst, Rectangle rec, int thick, Color color); + public static extern void ImageDrawRectangleLines(Image* dst, Rectangle rec, int thick, Color color); /// Draw a source image within a destination image (tint applied to source) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void ImageDraw(ref Image dst, Image src, Rectangle srcRec, Rectangle dstRec, Color tint); + public static extern void ImageDraw(Image* dst, Image src, Rectangle srcRec, Rectangle dstRec, Color tint); /// Draw text (using default font) within an image (destination) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void ImageDrawText(ref Image dst, [MarshalAs(UnmanagedType.LPUTF8Str)] string text, int x, int y, int fontSize, Color color); + public static extern void ImageDrawText(Image* dst, sbyte* text, int x, int y, int fontSize, Color color); /// Draw text (custom sprite font) within an image (destination) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void ImageDrawTextEx(ref Image dst, Font font, [MarshalAs(UnmanagedType.LPUTF8Str)] string text, Vector2 position, float fontSize, float spacing, Color tint); + public static extern void ImageDrawTextEx(Image* dst, Font font, sbyte* text, Vector2 position, float fontSize, float spacing, Color tint); // Texture loading functions @@ -2956,7 +1283,7 @@ namespace Raylib_cs /// Load texture from file into GPU memory (VRAM) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern Texture2D LoadTexture(string fileName); + public static extern Texture2D LoadTexture(sbyte* fileName); /// Load texture from image data [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -2978,30 +1305,20 @@ 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); - - /// Get pixel data from GPU texture and return an Image - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern Image GetTextureData(Texture2D texture); - - /// Get pixel data from screen buffer and return an Image (screenshot) - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern Image GetScreenData(); + public static extern void UpdateTextureRec(Texture2D texture, Rectangle rec, void* pixels); // Texture configuration functions /// Generate GPU mipmaps for a texture [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void GenTextureMipmaps(ref Texture2D texture); + public static extern void GenTextureMipmaps(Texture2D* texture); /// Set texture scaling filter mode [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -3028,27 +1345,27 @@ namespace Raylib_cs /// Draw a part of a texture defined by a rectangle [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void DrawTextureRec(Texture2D texture, Rectangle sourceRec, Vector2 position, Color tint); + public static extern void DrawTextureRec(Texture2D texture, Rectangle source, Vector2 position, Color tint); /// Draw texture quad with tiling and offset parameters [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void DrawTextureQuad(Texture2D texture, Vector2 tiling, Vector2 offset, Rectangle quad, Color tint); - /// Draw part of a texture (defined by a rectangle) with rotation and scale tiled into dest. + /// Draw part of a texture (defined by a rectangle) with rotation and scale tiled into dest [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void DrawTextureTiled(Texture2D texture, Rectangle source, Rectangle dest, Vector2 origin, float rotation, float scale, Color tint); /// Draw a part of a texture defined by a rectangle with 'pro' parameters [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void DrawTexturePro(Texture2D texture, Rectangle sourceRec, Rectangle destRec, Vector2 origin, float rotation, Color tint); + public static extern void DrawTexturePro(Texture2D texture, Rectangle source, Rectangle dest, Vector2 origin, float rotation, Color tint); /// Draws a texture (or part of it) that stretches or shrinks nicely [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void DrawTextureNPatch(Texture2D texture, NPatchInfo nPatchInfo, Rectangle destRec, Vector2 origin, float rotation, Color tint); + public static extern void DrawTextureNPatch(Texture2D texture, NPatchInfo nPatchInfo, Rectangle dest, Vector2 origin, float rotation, Color tint); /// Draw a textured polygon [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void DrawTexturePoly(Texture2D texture, Vector2 center, Vector2[] points, Vector2[] texcoords, int pointsCount, Color tint); + public static extern void DrawTexturePoly(Texture2D texture, Vector2 center, Vector2* points, Vector2* texcoords, int pointsCount, Color tint); // Color/pixel related functions @@ -3083,15 +1400,15 @@ namespace Raylib_cs /// Get Color structure from hexadecimal value [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern Color GetColor(int hexValue); + public static extern Color GetColor(uint hexValue); /// 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 srcPtr, 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)] @@ -3110,35 +1427,32 @@ namespace Raylib_cs /// Load font from file into GPU memory (VRAM) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern Font LoadFont(string fileName); + public static extern Font LoadFont(sbyte* fileName); /// Load font from file with extended parameters [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern Font LoadFontEx(string fileName, int fontSize, int[] fontChars, int charsCount); + public static extern Font LoadFontEx(sbyte* fileName, int fontSize, int[] fontChars, int charsCount); /// Load font from Image (XNA style) [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); + public static extern Font LoadFontFromMemory(sbyte* 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 CharInfo * + /// 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 CharInfo * + /// 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)] @@ -3153,85 +1467,133 @@ namespace Raylib_cs /// Draw text (using default font) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void DrawText([MarshalAs(UnmanagedType.LPUTF8Str)] string text, int posX, int posY, int fontSize, Color color); + public static extern void DrawText(sbyte* text, int posX, int posY, int fontSize, Color color); /// Draw text using font and additional parameters [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void DrawTextEx(Font font, [MarshalAs(UnmanagedType.LPUTF8Str)] string text, Vector2 position, float fontSize, float spacing, Color tint); + public static extern void DrawTextEx(Font font, sbyte* text, Vector2 position, float fontSize, float spacing, Color tint); - /// Draw text using font inside rectangle limits + /// Draw text using Font and pro parameters (rotation) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void DrawTextRec(Font font, [MarshalAs(UnmanagedType.LPUTF8Str)] string text, Rectangle rec, float fontSize, float spacing, bool wordWrap, Color tint); - - /// Draw text using font inside rectangle limits with support for text selection - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void DrawTextRecEx(Font font, [MarshalAs(UnmanagedType.LPUTF8Str)] string text, Rectangle rec, float fontSize, float spacing, bool wordWrap, Color tint, int selectStart, int selectLength, Color selectText, Color selectBack); + public static extern void DrawTextPro(Font font, sbyte* text, Vector2 position, Vector2 origin, float rotation, float fontSize, float spacing, Color tint); /// Draw one character (codepoint) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void DrawTextCodepoint(Font font, int codepoint, Vector2 position, float scale, Color tint); - // Text misc. functions + // Text font info functions /// Measure string width for default font [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern int MeasureText([MarshalAs(UnmanagedType.LPUTF8Str)] string text, int fontSize); + public static extern int MeasureText(sbyte* text, int fontSize); /// Measure string size for Font [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern Vector2 MeasureTextEx(Font font, [MarshalAs(UnmanagedType.LPUTF8Str)] string text, float fontSize, float spacing); + public static extern Vector2 MeasureTextEx(Font font, sbyte* text, float fontSize, float spacing); - /// Get index position for a unicode character on font + /// Get glyph index position in font for a codepoint (unicode character), fallback to '?' if not found [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int GetGlyphIndex(Font font, int character); - // Text strings management functions - // NOTE: Some strings allocate memory internally for returned strings, just be careful! - - /// Text formatting with variables (sprintf style) + /// Get glyph font info data for a codepoint (unicode character), fallback to '?' if not found [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern string TextFormat(string text); + public static extern GlyphInfo GetGlyphInfo(Font font, int codepoint); - /// Get a piece of a text string + /// Get glyph rectangle in font atlas for a codepoint (unicode character), fallback to '?' if not found [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern string TextSubtext(string text, int position, int length); + public static extern Rectangle GetGlyphAtlasRec(Font font, int codepoint); - /// Append text at specific position and move cursor! + + // Text codepoints management functions (unicode characters) + + /// Get all codepoints in a string, codepoints count returned by parameters [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void TextAppend(ref char text, string append, ref int position); + public static extern int* LoadCodepoints(sbyte* text, int* count); - /// Get Pascal case notation version of provided string + /// Unload codepoints data from memory [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern string TextToPascal(string text); - - /// Get integer value from text (negative values not supported) - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern int TextToInteger(string text); - - /// Encode text codepoint into utf8 text (memory must be freed!) - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern string TextToUtf8(string text, int length); - - - // UTF8 text strings management functions - - /// 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); + public static extern void UnloadCodepoints(int* codepoints); /// Get total number of characters (codepoints) in a UTF8 encoded string [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern int GetCodepointsCount(string text); + public static extern int GetCodepointCount(sbyte* text); /// Returns next codepoint in a UTF8 encoded string; 0x3f('?') is returned on failure [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern int GetNextCodepoint(string text, ref int bytesProcessed); + public static extern int GetCodepoint(sbyte* text, int* bytesProcessed); /// Encode codepoint into utf8 text (char array length returned as parameter) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern string CodepointToUtf8(string text, ref int byteLength); + public static extern sbyte* CodepointToUTF8(int codepoint, int* byteSize); + + /// Encode text as codepoints array into UTF-8 text string (WARNING: memory must be freed!) + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern sbyte* TextCodepointsToUTF8(int* codepoints, int length); + + + // Text strings management functions (no UTF-8 strings, only byte chars) + // NOTE: Some strings allocate memory internally for returned strings, just be careful! + + // Copy one string to another, returns bytes copied + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern int TextCopy(char* dst, sbyte* src); + + /// Check if two text string are equal + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern bool TextIsEqual(sbyte* text1, sbyte* text2); + + /// Get text length, checks for '\0' ending + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern uint TextLength(sbyte* text); + + /// Text formatting with variables (sprintf style) + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern sbyte* TextFormat(sbyte* text); + + /// Get a piece of a text string + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern sbyte* TextSubtext(sbyte* text, int position, int length); + + /// Replace text string (WARNING: memory must be freed!) + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern char* TextReplace(char* text, sbyte* replace, sbyte* by); + + /// Insert text in a position (WARNING: memory must be freed!) + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern char* TextInsert(sbyte* text, sbyte* insert, int position); + + /// Join text strings with delimiter + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern sbyte* TextJoin(sbyte** textList, int count, sbyte* delimiter); + + /// Split text into multiple strings + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern sbyte** TextSplit(sbyte* text, char delimiter, int* count); + + /// Append text at specific position and move cursor! + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern void TextAppend(sbyte* text, sbyte* append, int* position); + + /// Find first text occurrence within a string + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern int TextFindIndex(sbyte* text, sbyte* find); + + /// Get upper case version of provided string + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern sbyte* TextToUpper(sbyte* text); + + /// Get lower case version of provided string + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern sbyte* TextToLower(sbyte* text); + + /// Get Pascal case notation version of provided string + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern sbyte* TextToPascal(sbyte* text); + + /// Get integer value from text (negative values not supported) + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern int TextToInteger(sbyte* text); //------------------------------------------------------------------------------------ @@ -3258,7 +1620,7 @@ namespace Raylib_cs /// Draw a triangle strip defined by points [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void DrawTriangleStrip3D(Vector3[] points, int pointsCount, Color color); + public static extern void DrawTriangleStrip3D(Vector3* points, int pointsCount, Color color); /// Draw cube [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -3280,6 +1642,10 @@ namespace Raylib_cs [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void DrawCubeTexture(Texture2D texture, Vector3 position, float width, float height, float length, Color color); + /// Draw cube with a region of a texture + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern void DrawCubeTextureRec(Texture2D texture, Vector3 position, float width, float height, float length, Color color); + /// Draw sphere [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void DrawSphere(Vector3 centerPos, float radius, Color color); @@ -3296,10 +1662,18 @@ namespace Raylib_cs [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void DrawCylinder(Vector3 position, float radiusTop, float radiusBottom, float height, int slices, Color color); + /// Draw a cylinder with base at startPos and top at endPos + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern void DrawCylinderEx(Vector3 startPos, Vector3 endPos, float startRadius, float endRadius, int sides, Color color); + /// Draw a cylinder/cone wires [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void DrawCylinderWires(Vector3 position, float radiusTop, float radiusBottom, float height, int slices, Color color); + /// Draw a cylinder wires with base at startPos and top at endPos + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern void DrawCylinderWiresEx(Vector3 startPos, Vector3 endPos, float startRadius, float endRadius, int sides, Color color); + /// Draw a plane XZ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void DrawPlane(Vector3 centerPos, Vector2 size, Color color); @@ -3321,7 +1695,7 @@ namespace Raylib_cs /// Load model from files (meshes and materials) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern Model LoadModel(string fileName); + public static extern Model LoadModel(sbyte* fileName); /// Load model from generated mesh (default material) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -3335,17 +1709,23 @@ namespace Raylib_cs [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void UnloadModelKeepMeshes(Model model); + /// Compute model bounding box limits (considers all meshes) + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern BoundingBox GetModelBoundingBox(Model model); // Mesh loading/unloading functions /// 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(Mesh* mesh, CBool dynamic); /// 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); + 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)] + public static extern void UnloadMesh(Mesh* mesh); /// Draw a 3d mesh with material and transform [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -3353,24 +1733,31 @@ namespace Raylib_cs /// Draw multiple mesh instances with material and different transforms [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void DrawMeshInstanced(Mesh mesh, Material material, Matrix4x4[] transforms, int instances); - - /// Unload mesh from memory (RAM and/or VRAM) - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void UnloadMesh(ref Mesh mesh); + public static extern void DrawMeshInstanced(Mesh mesh, Material material, Matrix4x4* transforms, int instances); /// Export mesh data to file, returns true on success [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - [return: MarshalAs(UnmanagedType.I1)] - public static extern bool ExportMesh(Mesh mesh, string fileName); + public static extern CBool ExportMesh(Mesh mesh, sbyte* fileName); + + /// Compute mesh bounding box limits + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern BoundingBox GetMeshBoundingBox(Mesh mesh); + + /// Compute mesh tangents + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern void GenMeshTangents(Mesh* mesh); + + /// Compute mesh binormals + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern void GenMeshBinormals(Mesh* mesh); // Material loading/unloading functions + //TODO: safe Helper method /// Load materials from model file - /// IntPtr refers to Material * [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr LoadMaterials(string fileName, ref int materialCount); + public static extern Material* LoadMaterials(sbyte* fileName, int* materialCount); /// Load default material (Supports: DIFFUSE, SPECULAR, NORMAL maps) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -3382,36 +1769,11 @@ namespace Raylib_cs /// Set texture for a material map type (MAP_DIFFUSE, MAP_SPECULAR...) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void SetMaterialTexture(ref Material material, int mapType, Texture2D texture); + public static extern void SetMaterialTexture(Material* material, MaterialMapIndex mapType, Texture2D texture); /// Set material for a mesh [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void SetModelMeshMaterial(ref Model model, int meshId, int materialId); - - - // Model animations loading/unloading functions - - /// Load model animations from file - /// IntPtr refers to ModelAnimation * - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr LoadModelAnimations(string fileName, ref int animsCount); - - /// Update model animation pose - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void UpdateModelAnimation(Model model, ModelAnimation anim, int frame); - - /// Unload animation data - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void UnloadModelAnimation(ModelAnimation anim); - - /// Unload animation array data - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void UnloadModelAnimations(ModelAnimation[] animations, int count); - - /// 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 void SetModelMeshMaterial(Model* model, int meshId, int materialId); // Mesh generation functions @@ -3440,6 +1802,10 @@ namespace Raylib_cs [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Mesh GenMeshCylinder(float radius, float height, int slices); + /// Generate cone/pyramid mesh + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern Mesh GenMeshCone(float radius, float height, int slices); + /// Generate torus mesh [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Mesh GenMeshTorus(float radius, float size, int radSeg, int sides); @@ -3456,22 +1822,6 @@ namespace Raylib_cs [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Mesh GenMeshCubicmap(Image cubicmap, Vector3 cubeSize); - - // Mesh manipulation functions - - /// Compute mesh bounding box limits - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern BoundingBox MeshBoundingBox(Mesh mesh); - - /// Compute mesh tangents - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void MeshTangents(ref Mesh mesh); - - /// Compute mesh binormals - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void MeshBinormals(ref Mesh mesh); - - // Model drawing functions /// Draw a model (with texture if set) @@ -3498,54 +1848,73 @@ namespace Raylib_cs [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void DrawBillboard(Camera3D camera, Texture2D texture, Vector3 center, float size, Color tint); - /// Draw a billboard texture defined by sourceRec + /// Draw a billboard texture defined by source [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void DrawBillboardRec(Camera3D camera, Texture2D texture, Rectangle sourceRec, Vector3 center, float size, Color tint); + 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 + [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); + + // Model animations loading/unloading functions + + /// Load model animations from file + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern ModelAnimation* LoadModelAnimations(sbyte* fileName, uint* animsCount); + + /// Update model animation pose + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern void UpdateModelAnimation(Model model, ModelAnimation anim, int frame); + + /// Unload animation data + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern void UnloadModelAnimation(ModelAnimation anim); + + /// Unload animation array data + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern void UnloadModelAnimations(ModelAnimation[] animations, uint count); + + /// Check model animation skeleton match + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + 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 centerA, float radiusA, Vector3 centerB, float radiusB); + 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 centerSphere, float radiusSphere); + 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 CheckCollisionRaySphere(Ray ray, Vector3 spherePosition, float sphereRadius); - - /// Detect collision between ray and sphere, returns collision point - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - [return: MarshalAs(UnmanagedType.I1)] - public static extern bool CheckCollisionRaySphereEx(Ray ray, Vector3 spherePosition, float sphereRadius, ref Vector3 collisionPoint); + public static extern CBool GetRayCollisionSphere(Ray ray, Vector3 center, float radius); /// Detect collision between ray and box [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - [return: MarshalAs(UnmanagedType.I1)] - public static extern bool CheckCollisionRayBox(Ray ray, BoundingBox box); + public static extern RayCollision GetRayCollisionBox(Ray ray, BoundingBox box); /// Get collision info between ray and model [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern RayHitInfo GetCollisionRayModel(Ray ray, Model model); + public static extern RayCollision GetRayCollisionModel(Ray ray, Model model); + + /// Get collision info between ray and mesh + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern RayCollision GetRayCollisionMesh(Ray ray, Mesh mesh, Matrix4x4 transform); /// Get collision info between ray and triangle [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern RayHitInfo GetCollisionRayTriangle(Ray ray, Vector3 p1, Vector3 p2, Vector3 p3); + public static extern RayCollision GetRayCollisionTriangle(Ray ray, Vector3 p1, Vector3 p2, Vector3 p3); - /// Get collision info between ray and ground plane (Y-normal plane) + /// Get collision info between ray and quad [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern RayHitInfo GetCollisionRayGround(Ray ray, float groundHeight); + public static extern RayCollision GetRayCollisionQuad(Ray ray, Vector3 p1, Vector3 p2, Vector3 p3, Vector3 p4); //------------------------------------------------------------------------------------ @@ -3564,8 +1933,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)] @@ -3576,25 +1944,24 @@ namespace Raylib_cs /// Load wave data from file [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern Wave LoadWave(string fileName); + public static extern Wave LoadWave(sbyte* 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); + public static extern Wave LoadWaveFromMemory(sbyte* fileType, byte* fileData, int dataSize); /// Load sound from file [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern Sound LoadSound(string fileName); + public static extern Sound LoadSound(sbyte* fileName); /// Load sound from wave data [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Sound LoadSoundFromWave(Wave wave); /// Update sound buffer with new data - /// data refers to a const void * [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)] @@ -3606,11 +1973,11 @@ namespace Raylib_cs /// Export wave data to file [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void ExportWave(Wave wave, string fileName); + public static extern void ExportWave(Wave wave, sbyte* fileName); /// Export wave sample data to code (.h) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void ExportWaveAsCode(Wave wave, string fileName); + public static extern void ExportWaveAsCode(Wave wave, sbyte* fileName); // Wave/Sound management functions @@ -3645,8 +2012,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)] @@ -3658,7 +2024,7 @@ namespace Raylib_cs /// Convert wave data to desired format [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void WaveFormat(ref Wave wave, int sampleRate, int sampleSize, int channels); + public static extern void WaveFormat(Wave* wave, int sampleRate, int sampleSize, int channels); /// Copy a wave to a new wave [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -3666,27 +2032,28 @@ namespace Raylib_cs /// Crop a wave to defined samples range [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void WaveCrop(ref Wave wave, int initSample, int finalSample); + public static extern void WaveCrop(Wave* wave, int initSample, int finalSample); - /// Get samples data from wave as a floats array - /// IntPtr refers to float * + //TODO: Span + /// 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 * + //TODO: Span + /// 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 /// Load music stream from file [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern Music LoadMusicStream(string fileName); + public static extern Music LoadMusicStream(sbyte* fileName); + //TODO: Span/Helper method /// 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(sbyte* fileType, byte* data, int dataSize); /// Unload music stream [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -3696,6 +2063,10 @@ namespace Raylib_cs [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void PlayMusicStream(Music music); + /// Check if music is playing + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern CBool IsMusicStreamPlaying(Music music); + /// Updates buffers for music streaming [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void UpdateMusicStream(Music music); @@ -3712,10 +2083,9 @@ namespace Raylib_cs [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void ResumeMusicStream(Music music); - /// Check if music is playing + /// Seek music to a position (in seconds) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - [return: MarshalAs(UnmanagedType.I1)] - public static extern bool IsMusicPlaying(Music music); + public static extern void SeekMusicStream(Music music, float position); /// Set volume for music (1.0 is max level) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -3738,21 +2108,19 @@ namespace Raylib_cs /// Init audio stream (to stream raw audio pcm data) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern AudioStream InitAudioStream(uint sampleRate, uint sampleSize, uint channels); + public static extern AudioStream LoadAudioStream(uint sampleRate, uint sampleSize, uint channels); - /// Update audio stream buffers with data - /// data refers to a const void * + /// Unload audio stream and free memory [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void UpdateAudioStream(AudioStream stream, IntPtr data, int samplesCount); + public static extern void UnloadAudioStream(AudioStream stream); - /// Close audio stream and free memory + /// Update audio stream buffers with data [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void CloseAudioStream(AudioStream stream); + public static extern void UpdateAudioStream(AudioStream stream, void* data, int samplesCount); /// 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)] @@ -3768,8 +2136,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/Raymath.cs b/Raylib-cs/interop/Raymath.cs similarity index 53% rename from Raylib-cs/Raymath.cs rename to Raylib-cs/interop/Raymath.cs index b72ba71..99a49c7 100644 --- a/Raylib-cs/Raymath.cs +++ b/Raylib-cs/interop/Raymath.cs @@ -16,333 +16,400 @@ namespace Raylib_cs } [SuppressUnmanagedCodeSecurity] - public static class Raymath + public static unsafe partial 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 Vector3 Vector3Unproject(Vector3 source, Matrix4x4 projection, Matrix4x4 view); + + /// Get Vector3 as float array [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern float3 Vector3ToFloatV(Vector3 v); - // 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); + /// Get float array of matrix data + [DllImport(Raylib.nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern float16 MatrixToFloatV(Matrix4x4 m); - // 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/interop/Rlgl.cs similarity index 75% rename from Raylib-cs/Rlgl.cs rename to Raylib-cs/interop/Rlgl.cs index f0bb0d8..cdf0d5d 100644 --- a/Raylib-cs/Rlgl.cs +++ b/Raylib-cs/interop/Rlgl.cs @@ -1,61 +1,15 @@ -using System; using System.Numerics; using System.Runtime.InteropServices; 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 + public static unsafe partial 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; @@ -85,20 +39,23 @@ namespace Raylib_cs public const int RL_TEXTURE_WRAP_MIRROR_REPEAT = 0x8370; public const int RL_TEXTURE_WRAP_MIRROR_CLAMP = 0x8742; - // Matrix modes (equivalent to OpenGL) - public const int RL_MODELVIEW = 0x1700; - public const int RL_PROJECTION = 0x1701; - public const int RL_TEXTURE = 0x1702; - - // Primitive assembly draw modes - public const int RL_LINES = 0x0001; - public const int RL_TRIANGLES = 0x0004; - public const int RL_QUADS = 0x0007; // GL equivalent data types 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; + + // ------------------------------------------------------------------------------------ // Functions Declaration - Matrix operations // ------------------------------------------------------------------------------------ @@ -107,6 +64,11 @@ namespace Raylib_cs [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void rlMatrixMode(int mode); + public static void rlMatrixMode(MatrixMode mode) + { + rlMatrixMode((int)mode); + } + /// Push the current matrix to stack [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void rlPushMatrix(); @@ -125,15 +87,26 @@ 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)] public static extern void rlScalef(float x, float y, float z); - /// Multiply the current matrix by another matrix + /// + /// Multiply the current matrix by another matrix + ///
+ /// Current Matrix can be set via + ///
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void rlMultMatrixf(ref float[] matf); + public static extern void rlMultMatrixf(float* matf); + + /// + public static void rlMultMatrixf(Matrix4x4 matf) + { + float16 f = Raymath.MatrixToFloatV(matf); + rlMultMatrixf(f.v); + } [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void rlFrustum(double left, double right, double bottom, double top, double znear, double zfar); @@ -154,6 +127,11 @@ namespace Raylib_cs [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void rlBegin(int mode); + public static void rlBegin(DrawMode mode) + { + rlBegin((int)mode); + } + /// Finish vertex providing [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void rlEnd(); @@ -200,8 +178,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)] @@ -231,6 +208,16 @@ namespace Raylib_cs [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void rlDisableVertexAttribute(uint index); + /// Enable attribute state pointer
+ /// NOTE: Only available for GRAPHICS_API_OPENGL_11
+ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern void rlEnableStatePointer(int vertexAttribType, void* 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 @@ -280,9 +267,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(); @@ -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)] @@ -370,11 +368,11 @@ 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)] - public static extern void rlSetBlendModeFactors(int glSrcFactor, int glDstFactor, int glEquation); + public static extern void rlSetBlendFactors(int glSrcFactor, int glDstFactor, int glEquation); // ------------------------------------------------------------------------------------ @@ -390,11 +388,10 @@ namespace Raylib_cs public static extern void rlglClose(); /// Load OpenGL extensions - /// loader refers to a void * [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void rlLoadExtensions(IntPtr loader); + public static extern void rlLoadExtensions(void* loader); - /// Returns current OpenGL version + /// Get current OpenGL version [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern GlVersion rlGetVersion(); @@ -406,18 +403,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 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); @@ -427,11 +429,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)] @@ -439,8 +441,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,15 +456,15 @@ 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(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, bool 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(int 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); @@ -472,52 +473,53 @@ 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, 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, bool useRenderBuffer); + 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)] - 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)] + public static extern sbyte* rlGetPixelFormatName(PixelFormat format); /// Unload texture from GPU memory [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -525,17 +527,15 @@ namespace Raylib_cs /// 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, 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(Texture2D texture); + 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) @@ -550,24 +550,23 @@ 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 /// Load shader from code strings [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern uint rlLoadShaderCode(string vsCode, string fsCode); + public static extern uint rlLoadShaderCode(sbyte* vsCode, sbyte* 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); + public static extern uint rlCompileShader(sbyte* shaderCode, int type); /// Load custom shader program [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -579,15 +578,15 @@ namespace Raylib_cs /// Get shader location uniform [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern int rlGetLocationUniform(uint shaderId, string uniformName); + public static extern int rlGetLocationUniform(uint shaderId, sbyte* uniformName); /// Get shader location attribute [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern int rlGetLocationAttrib(uint shaderId, string attribName); + public static extern int rlGetLocationAttrib(uint shaderId, sbyte* attribName); /// 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)] @@ -602,11 +601,57 @@ 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 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 ulong rlGetShaderBufferSize(uint id, void* dest, ulong count, ulong offset); + + /// Bind SSBO buffer + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern 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 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern Matrix4x4 rlGetMatrixModelView(); + public static extern Matrix4x4 rlGetMatrixModelview(); /// Get internal projection matrix [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -630,7 +675,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)] diff --git a/Raylib-cs/types/Audio.cs b/Raylib-cs/types/Audio.cs new file mode 100644 index 0000000..1000b42 --- /dev/null +++ b/Raylib-cs/types/Audio.cs @@ -0,0 +1,118 @@ +using System; +using System.Runtime.InteropServices; + +namespace Raylib_cs +{ + /// + /// Wave type, defines audio wave data + /// + [StructLayout(LayoutKind.Sequential)] + public unsafe partial struct Wave + { + /// + /// Number of samples + /// + public uint sampleCount; + + /// + /// Frequency (samples per second) + /// + public uint sampleRate; + + /// + /// Bit depth (bits per sample): 8, 16, 32 (24 not supported) + /// + public uint sampleSize; + + /// + /// Number of channels (1-mono, 2-stereo) + /// + public uint channels; + + //TODO: SPAN ? + /// + /// Buffer data pointer + /// + public void* data; + } + + /// + /// Audio stream type
+ /// NOTE: Useful to create custom audio streams not bound to a specific file + ///
+ [StructLayout(LayoutKind.Sequential)] + public partial struct AudioStream + { + //TODO: convert + /// + /// Pointer to internal data(rAudioBuffer *) used by the audio system + /// + public IntPtr buffer; + + /// + /// Frequency (samples per second) + /// + public uint sampleRate; + + /// + /// Bit depth (bits per sample): 8, 16, 32 (24 not supported) + /// + public uint sampleSize; + + /// + /// Number of channels (1-mono, 2-stereo) + /// + public uint channels; + } + + /// + /// Sound source type + /// + [StructLayout(LayoutKind.Sequential)] + public partial struct Sound + { + /// + /// Audio stream + /// + public AudioStream stream; + + /// + /// Total number of frames (considering channels) + /// + public uint frameCount; + } + + /// + /// Music stream type (audio file streaming from memory)
+ /// NOTE: Anything longer than ~10 seconds should be streamed + ///
+ [StructLayout(LayoutKind.Sequential)] + public unsafe partial struct Music + { + /// + /// Audio stream + /// + public AudioStream stream; + + /// + /// Total number of samples + /// + public uint frameCount; + + /// + /// Music looping enable + /// + public CBool looping; + + /// + /// Type of music context (audio filetype) + /// + public int ctxType; + + //TODO span + /// + /// Audio context data, depends on type + /// + public void* ctxData; + } +} diff --git a/Raylib-cs/types/BoundingBox.cs b/Raylib-cs/types/BoundingBox.cs new file mode 100644 index 0000000..0bea2a7 --- /dev/null +++ b/Raylib-cs/types/BoundingBox.cs @@ -0,0 +1,26 @@ +using System.Numerics; +using System.Runtime.InteropServices; + +namespace Raylib_cs +{ + /// Bounding box type + [StructLayout(LayoutKind.Sequential)] + public partial struct BoundingBox + { + /// + /// Minimum vertex box-corner + /// + public Vector3 min; + + /// + /// Maximum vertex box-corner + /// + public Vector3 max; + + public BoundingBox(Vector3 min, Vector3 max) + { + this.min = min; + this.max = max; + } + } +} diff --git a/Raylib-cs/types/Camera2D.cs b/Raylib-cs/types/Camera2D.cs new file mode 100644 index 0000000..76ad5bd --- /dev/null +++ b/Raylib-cs/types/Camera2D.cs @@ -0,0 +1,40 @@ +using System.Numerics; +using System.Runtime.InteropServices; + +namespace Raylib_cs +{ + /// + /// Camera2D, defines position/orientation in 2d space + /// + [StructLayout(LayoutKind.Sequential)] + public partial struct Camera2D + { + /// + /// Camera offset (displacement from target) + /// + public Vector2 offset; + + /// + /// Camera target (rotation and zoom origin) + /// + public Vector2 target; + + /// + /// Camera rotation in degrees + /// + public float rotation; + + /// + /// Camera zoom (scaling), should be 1.0f by default + /// + public float zoom; + + public Camera2D(Vector2 offset, Vector2 target, float rotation, float zoom) + { + this.offset = offset; + this.target = target; + this.rotation = rotation; + this.zoom = zoom; + } + } +} diff --git a/Raylib-cs/types/Camera3D.cs b/Raylib-cs/types/Camera3D.cs new file mode 100644 index 0000000..e4b5299 --- /dev/null +++ b/Raylib-cs/types/Camera3D.cs @@ -0,0 +1,67 @@ +using System.Numerics; +using System.Runtime.InteropServices; + +namespace Raylib_cs +{ + /// + /// Camera system modes + /// + public enum CameraMode + { + CAMERA_CUSTOM = 0, + CAMERA_FREE, + CAMERA_ORBITAL, + CAMERA_FIRST_PERSON, + CAMERA_THIRD_PERSON + } + + /// + /// Camera projection + /// + public enum CameraProjection + { + CAMERA_PERSPECTIVE = 0, + CAMERA_ORTHOGRAPHIC + } + + /// + /// Camera3D, defines position/orientation in 3d space + /// + [StructLayout(LayoutKind.Sequential)] + public partial struct Camera3D + { + /// + /// Camera position + /// + public Vector3 position; + + /// + /// Camera target it looks-at + /// + public Vector3 target; + + /// + /// Camera up vector (rotation over its axis) + /// + public Vector3 up; + + /// + /// Camera field-of-view apperture in Y (degrees) in perspective, used as near plane width in orthographic + /// + public float fovy; + + /// + /// Camera type, defines projection type: CAMERA_PERSPECTIVE or CAMERA_ORTHOGRAPHIC + /// + public CameraProjection projection; + + public Camera3D(Vector3 position, Vector3 target, Vector3 up, float fovy, CameraProjection projection) + { + this.position = position; + this.target = target; + this.up = up; + this.fovy = fovy; + this.projection = projection; + } + } +} diff --git a/Raylib-cs/types/Color.cs b/Raylib-cs/types/Color.cs new file mode 100644 index 0000000..3ed0f41 --- /dev/null +++ b/Raylib-cs/types/Color.cs @@ -0,0 +1,67 @@ +using System; +using System.Runtime.InteropServices; + +namespace Raylib_cs +{ + /// + /// Color type, RGBA (32bit) + /// + [StructLayout(LayoutKind.Sequential)] + public partial struct Color + { + public byte r; + public byte g; + public byte b; + public byte a; + + // Example - Color.RED instead of RED + // Custom raylib color palette for amazing visuals + public static Color LIGHTGRAY = new Color(200, 200, 200, 255); + public static Color GRAY = new Color(130, 130, 130, 255); + public static Color DARKGRAY = new Color(80, 80, 80, 255); + public static Color YELLOW = new Color(253, 249, 0, 255); + public static Color GOLD = new Color(255, 203, 0, 255); + public static Color ORANGE = new Color(255, 161, 0, 255); + public static Color PINK = new Color(255, 109, 194, 255); + public static Color RED = new Color(230, 41, 55, 255); + public static Color MAROON = new Color(190, 33, 55, 255); + public static Color GREEN = new Color(0, 228, 48, 255); + public static Color LIME = new Color(0, 158, 47, 255); + public static Color DARKGREEN = new Color(0, 117, 44, 255); + public static Color SKYBLUE = new Color(102, 191, 255, 255); + public static Color BLUE = new Color(0, 121, 241, 255); + public static Color DARKBLUE = new Color(0, 82, 172, 255); + public static Color PURPLE = new Color(200, 122, 255, 255); + public static Color VIOLET = new Color(135, 60, 190, 255); + public static Color DARKPURPLE = new Color(112, 31, 126, 255); + public static Color BEIGE = new Color(211, 176, 131, 255); + public static Color BROWN = new Color(127, 106, 79, 255); + public static Color DARKBROWN = new Color(76, 63, 47, 255); + public static Color WHITE = new Color(255, 255, 255, 255); + public static Color BLACK = new Color(0, 0, 0, 255); + public static Color BLANK = new Color(0, 0, 0, 0); + public static Color MAGENTA = new Color(255, 0, 255, 255); + public static Color RAYWHITE = new Color(245, 245, 245, 255); + + public Color(byte r, byte g, byte b, byte a) + { + this.r = r; + this.g = g; + this.b = b; + this.a = a; + } + + public Color(int r, int g, int b, int a) + { + this.r = Convert.ToByte(r); + this.g = Convert.ToByte(g); + this.b = Convert.ToByte(b); + this.a = Convert.ToByte(a); + } + + public override string ToString() + { + return $"{{R:{r} G:{g} B:{b} A:{a}}}"; + } + } +} diff --git a/Raylib-cs/types/Core.cs b/Raylib-cs/types/Core.cs new file mode 100644 index 0000000..63d4a43 --- /dev/null +++ b/Raylib-cs/types/Core.cs @@ -0,0 +1,166 @@ +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 + ///
+ [Flags] + public enum ConfigFlags : uint + { + /// + /// Set to try enabling V-Sync on GPU + /// + FLAG_VSYNC_HINT = 0x00000040, + + /// + /// Set to run program in fullscreen + /// + FLAG_FULLSCREEN_MODE = 0x00000002, + + /// + /// Set to allow resizable window + /// + FLAG_WINDOW_RESIZABLE = 0x00000004, + + /// + /// Set to disable window decoration (frame and buttons) + /// + FLAG_WINDOW_UNDECORATED = 0x00000008, + + /// + /// Set to hide window + /// + FLAG_WINDOW_HIDDEN = 0x00000080, + + /// + /// Set to minimize window (iconify) + /// + FLAG_WINDOW_MINIMIZED = 0x00000200, + + /// + /// Set to maximize window (expanded to monitor) + /// + FLAG_WINDOW_MAXIMIZED = 0x00000400, + + /// + /// Set to window non focused + /// + FLAG_WINDOW_UNFOCUSED = 0x00000800, + + /// + /// Set to window always on top + /// + FLAG_WINDOW_TOPMOST = 0x00001000, + + /// + /// Set to allow windows running while minimized + /// + FLAG_WINDOW_ALWAYS_RUN = 0x00000100, + + /// + /// Set to allow transparent framebuffer + /// + FLAG_WINDOW_TRANSPARENT = 0x00000010, + + /// + /// Set to support HighDPI + /// + FLAG_WINDOW_HIGHDPI = 0x00002000, + + /// + /// Set to try enabling MSAA 4X + /// + FLAG_MSAA_4X_HINT = 0x00000020, + + /// + /// Set to try enabling interlaced video format (for V3D) + /// + FLAG_INTERLACED_HINT = 0x00010000, + } + + /// + /// Trace log level
+ /// NOTE: Organized by priority level + ///
+ public enum TraceLogLevel + { + /// + /// Display all logs + /// + LOG_ALL = 0, + + /// + /// Trace logging, intended for internal use only + /// + LOG_TRACE, + + /// + /// Debug logging, used for internal debugging, it should be disabled on release builds + /// + LOG_DEBUG, + + /// + /// Info logging, used for program execution info + /// + LOG_INFO, + + /// + /// Warning logging, used on recoverable failures + /// + LOG_WARNING, + + /// + /// Error logging, used on unrecoverable failures + /// + LOG_ERROR, + + /// + /// Fatal logging, used to abort program: exit(EXIT_FAILURE) + /// + LOG_FATAL, + + /// + /// Disable logging + /// + LOG_NONE + } + + /// + /// Color blending modes (pre-defined) + /// + public enum BlendMode + { + /// + /// Blend textures considering alpha (default) + /// + BLEND_ALPHA = 0, + + /// + /// Blend textures adding colors + /// + BLEND_ADDITIVE, + + /// + /// Blend textures multiplying colors + /// + BLEND_MULTIPLIED, + + /// + /// Blend textures adding colors (alternative) + /// + BLEND_ADD_COLORS, + + /// + /// Blend textures subtracting colors (alternative) + /// + BLEND_SUBTRACT_COLORS, + + /// + /// Blend textures using custom src/dst factors (use rlSetBlendMode()) + /// + BLEND_CUSTOM + } +} diff --git a/Raylib-cs/types/Font.cs b/Raylib-cs/types/Font.cs new file mode 100644 index 0000000..8bf95f3 --- /dev/null +++ b/Raylib-cs/types/Font.cs @@ -0,0 +1,95 @@ +using System; +using System.Runtime.InteropServices; + +namespace Raylib_cs +{ + /// + /// Font type, defines generation method + /// + public enum FontType + { + /// + /// Default font generation, anti-aliased + /// + FONT_DEFAULT = 0, + + /// + /// Bitmap font generation, no anti-aliasing + /// + FONT_BITMAP, + + /// + /// SDF font generation, requires external shader + /// + FONT_SDF + } + + /// + /// GlyphInfo, font characters glyphs info + /// + [StructLayout(LayoutKind.Sequential)] + public partial struct GlyphInfo + { + /// + /// Character value (Unicode) + /// + public int value; + + /// + /// Character offset X when drawing + /// + public int offsetX; + + /// + /// Character offset Y when drawing + /// + public int offsetY; + + /// + /// Character advance position X + /// + public int advanceX; + + /// + /// Character image data + /// + public Image image; + } + + /// + /// Font, font texture and GlyphInfo array data + /// + [StructLayout(LayoutKind.Sequential)] + public unsafe partial struct Font + { + /// + /// Base size (default chars height) + /// + public int baseSize; + + /// + /// Number of characters + /// + public int glyphCount; + + /// + /// Padding around the glyph characters + /// + public int glyphPadding; + + /// + /// Texture atlas containing the glyphs + /// + public Texture2D texture; + + /// + /// Rectangles in texture for the glyphs + /// + public Rectangle* recs; + + /// + /// Glyphs info data + /// + public GlyphInfo* glyphs; + } +} diff --git a/Raylib-cs/types/Image.cs b/Raylib-cs/types/Image.cs new file mode 100644 index 0000000..3480fc5 --- /dev/null +++ b/Raylib-cs/types/Image.cs @@ -0,0 +1,149 @@ +using System; +using System.Runtime.InteropServices; + +namespace Raylib_cs +{ + /// + /// Pixel formats
+ /// NOTE: Support depends on OpenGL version and platform + ///
+ public enum PixelFormat + { + /// + /// 8 bit per pixel (no alpha) + /// + PIXELFORMAT_UNCOMPRESSED_GRAYSCALE = 1, + + /// + /// 8*2 bpp (2 channels) + /// + PIXELFORMAT_UNCOMPRESSED_GRAY_ALPHA, + + /// + /// 16 bpp + /// + PIXELFORMAT_UNCOMPRESSED_R5G6B5, + + /// + /// 24 bpp + /// + PIXELFORMAT_UNCOMPRESSED_R8G8B8, + + /// + /// 16 bpp (1 bit alpha) + /// + PIXELFORMAT_UNCOMPRESSED_R5G5B5A1, + + /// + /// 16 bpp (4 bit alpha) + /// + PIXELFORMAT_UNCOMPRESSED_R4G4B4A4, + + /// + /// 32 bpp + /// + PIXELFORMAT_UNCOMPRESSED_R8G8B8A8, + + /// + /// 32 bpp (1 channel - float) + /// + PIXELFORMAT_UNCOMPRESSED_R32, + + /// + /// 32*3 bpp (3 channels - float) + /// + PIXELFORMAT_UNCOMPRESSED_R32G32B32, + + /// + /// 32*4 bpp (4 channels - float) + /// + PIXELFORMAT_UNCOMPRESSED_R32G32B32A32, + + /// + /// 4 bpp (no alpha) + /// + PIXELFORMAT_COMPRESSED_DXT1_RGB, + + /// + /// 4 bpp (1 bit alpha) + /// + PIXELFORMAT_COMPRESSED_DXT1_RGBA, + + /// + /// 8 bpp + /// + PIXELFORMAT_COMPRESSED_DXT3_RGBA, + + /// + /// 8 bpp + /// + PIXELFORMAT_COMPRESSED_DXT5_RGBA, + + /// + /// 4 bpp + /// + PIXELFORMAT_COMPRESSED_ETC1_RGB, + + /// + /// 4 bpp + /// + PIXELFORMAT_COMPRESSED_ETC2_RGB, + + /// + /// 8 bpp + /// + PIXELFORMAT_COMPRESSED_ETC2_EAC_RGBA, + + /// + /// 4 bpp + /// + PIXELFORMAT_COMPRESSED_PVRT_RGB, + + /// + /// 4 bpp + /// + PIXELFORMAT_COMPRESSED_PVRT_RGBA, + + /// + /// 8 bpp + /// + PIXELFORMAT_COMPRESSED_ASTC_4x4_RGBA, + + /// + /// 2 bpp + /// + PIXELFORMAT_COMPRESSED_ASTC_8x8_RGBA + } + + /// + /// Image, pixel data stored in CPU memory (RAM) + /// + [StructLayout(LayoutKind.Sequential)] + public unsafe partial struct Image + { + /// + /// Image raw data + /// + public void* data; + + /// + /// Image base width + /// + public int width; + + /// + /// Image base height + /// + public int height; + + /// + /// Mipmap levels, 1 by default + /// + public int mipmaps; + + /// + /// Data format (PixelFormat type) + /// + public PixelFormat format; + } +} diff --git a/Raylib-cs/types/Input.cs b/Raylib-cs/types/Input.cs new file mode 100644 index 0000000..0ae0413 --- /dev/null +++ b/Raylib-cs/types/Input.cs @@ -0,0 +1,492 @@ +using System; +using System.Numerics; +using System.Runtime.InteropServices; + +namespace Raylib_cs +{ + /// + /// Keyboard keys (US keyboard layout)
+ /// NOTE: Use GetKeyPressed() to allow redefining required keys for alternative layouts + ///
+ public enum KeyboardKey + { + /// + /// NULL, used for no key pressed + /// + KEY_NULL = 0, + + // Alphanumeric keys + KEY_APOSTROPHE = 39, + KEY_COMMA = 44, + KEY_MINUS = 45, + KEY_PERIOD = 46, + KEY_SLASH = 47, + KEY_ZERO = 48, + KEY_ONE = 49, + KEY_TWO = 50, + KEY_THREE = 51, + KEY_FOUR = 52, + KEY_FIVE = 53, + KEY_SIX = 54, + KEY_SEVEN = 55, + KEY_EIGHT = 56, + KEY_NINE = 57, + KEY_SEMICOLON = 59, + KEY_EQUAL = 61, + KEY_A = 65, + KEY_B = 66, + KEY_C = 67, + KEY_D = 68, + KEY_E = 69, + KEY_F = 70, + KEY_G = 71, + KEY_H = 72, + KEY_I = 73, + KEY_J = 74, + KEY_K = 75, + KEY_L = 76, + KEY_M = 77, + KEY_N = 78, + KEY_O = 79, + KEY_P = 80, + KEY_Q = 81, + KEY_R = 82, + KEY_S = 83, + KEY_T = 84, + KEY_U = 85, + KEY_V = 86, + KEY_W = 87, + KEY_X = 88, + KEY_Y = 89, + KEY_Z = 90, + + // Function keys + KEY_SPACE = 32, + KEY_ESCAPE = 256, + KEY_ENTER = 257, + KEY_TAB = 258, + KEY_BACKSPACE = 259, + KEY_INSERT = 260, + KEY_DELETE = 261, + KEY_RIGHT = 262, + KEY_LEFT = 263, + KEY_DOWN = 264, + KEY_UP = 265, + KEY_PAGE_UP = 266, + KEY_PAGE_DOWN = 267, + KEY_HOME = 268, + KEY_END = 269, + KEY_CAPS_LOCK = 280, + KEY_SCROLL_LOCK = 281, + KEY_NUM_LOCK = 282, + KEY_PRINT_SCREEN = 283, + KEY_PAUSE = 284, + KEY_F1 = 290, + KEY_F2 = 291, + KEY_F3 = 292, + KEY_F4 = 293, + KEY_F5 = 294, + KEY_F6 = 295, + KEY_F7 = 296, + KEY_F8 = 297, + KEY_F9 = 298, + KEY_F10 = 299, + KEY_F11 = 300, + KEY_F12 = 301, + KEY_LEFT_SHIFT = 340, + KEY_LEFT_CONTROL = 341, + KEY_LEFT_ALT = 342, + KEY_LEFT_SUPER = 343, + KEY_RIGHT_SHIFT = 344, + KEY_RIGHT_CONTROL = 345, + KEY_RIGHT_ALT = 346, + KEY_RIGHT_SUPER = 347, + KEY_KB_MENU = 348, + KEY_LEFT_BRACKET = 91, + KEY_BACKSLASH = 92, + KEY_RIGHT_BRACKET = 93, + KEY_GRAVE = 96, + + // Keypad keys + KEY_KP_0 = 320, + KEY_KP_1 = 321, + KEY_KP_2 = 322, + KEY_KP_3 = 323, + KEY_KP_4 = 324, + KEY_KP_5 = 325, + KEY_KP_6 = 326, + KEY_KP_7 = 327, + KEY_KP_8 = 328, + KEY_KP_9 = 329, + KEY_KP_DECIMAL = 330, + KEY_KP_DIVIDE = 331, + KEY_KP_MULTIPLY = 332, + KEY_KP_SUBTRACT = 333, + KEY_KP_ADD = 334, + KEY_KP_ENTER = 335, + KEY_KP_EQUAL = 336, + + // Android key buttons + KEY_BACK = 4, + KEY_MENU = 82, + KEY_VOLUME_UP = 24, + KEY_VOLUME_DOWN = 25 + } + + /// + /// Mouse buttons + /// + public enum MouseButton + { + /// + /// Mouse button left + /// + MOUSE_BUTTON_LEFT = 0, + + /// + /// Mouse button right + /// + MOUSE_BUTTON_RIGHT = 1, + + /// + /// Mouse button middle (pressed wheel) + /// + MOUSE_BUTTON_MIDDLE = 2, + + /// + /// Mouse button side (advanced mouse device) + /// + MOUSE_BUTTON_SIDE = 3, + + /// + /// Mouse button extra (advanced mouse device) + /// + MOUSE_BUTTON_EXTRA = 4, + + /// + /// Mouse button forward (advanced mouse device) + /// + MOUSE_BUTTON_FORWARD = 5, + + /// + /// Mouse button back (advanced mouse device) + /// + MOUSE_BUTTON_BACK = 6, + + MOUSE_LEFT_BUTTON = MOUSE_BUTTON_LEFT, + MOUSE_RIGHT_BUTTON = MOUSE_BUTTON_RIGHT, + MOUSE_MIDDLE_BUTTON = MOUSE_BUTTON_MIDDLE, + } + + /// + /// Mouse cursor + /// + public enum MouseCursor + { + /// + /// Default pointer shape + /// + MOUSE_CURSOR_DEFAULT = 0, + + /// + /// Arrow shape + /// + MOUSE_CURSOR_ARROW = 1, + + /// + /// Text writing cursor shape + /// + MOUSE_CURSOR_IBEAM = 2, + + /// + /// Cross shape + /// + MOUSE_CURSOR_CROSSHAIR = 3, + + /// + /// Pointing hand cursor + /// + MOUSE_CURSOR_POINTING_HAND = 4, + + /// + /// Horizontal resize/move arrow shape + /// + MOUSE_CURSOR_RESIZE_EW = 5, + + /// + /// Vertical resize/move arrow shape + /// + MOUSE_CURSOR_RESIZE_NS = 6, + + /// + /// Top-left to bottom-right diagonal resize/move arrow shape + /// + MOUSE_CURSOR_RESIZE_NWSE = 7, + + /// + /// The top-right to bottom-left diagonal resize/move arrow shape + /// + MOUSE_CURSOR_RESIZE_NESW = 8, + + /// + /// The omni-directional resize/move cursor shape + /// + MOUSE_CURSOR_RESIZE_ALL = 9, + + /// + /// The operation-not-allowed shape + /// + MOUSE_CURSOR_NOT_ALLOWED = 10 + } + + /// Gamepad axis + public enum GamepadAxis + { + /// + /// Gamepad left stick X axis + /// + GAMEPAD_AXIS_LEFT_X = 0, + + /// + /// Gamepad left stick Y axis + /// + GAMEPAD_AXIS_LEFT_Y = 1, + + /// + /// Gamepad right stick X axis + /// + GAMEPAD_AXIS_RIGHT_X = 2, + + /// + /// Gamepad right stick Y axis + /// + GAMEPAD_AXIS_RIGHT_Y = 3, + + /// + /// Gamepad back trigger left, pressure level: [1..-1] + /// + GAMEPAD_AXIS_LEFT_TRIGGER = 4, + + /// + /// Gamepad back trigger right, pressure level: [1..-1] + /// + GAMEPAD_AXIS_RIGHT_TRIGGER = 5 + } + + /// + /// Gamepad buttons + /// + public enum GamepadButton + { + /// + /// This is here just for error checking + /// + GAMEPAD_BUTTON_UNKNOWN = 0, + + /// + /// Gamepad left DPAD up button + /// + GAMEPAD_BUTTON_LEFT_FACE_UP, + + /// + /// Gamepad left DPAD right button + /// + GAMEPAD_BUTTON_LEFT_FACE_RIGHT, + + /// + /// Gamepad left DPAD down button + /// + GAMEPAD_BUTTON_LEFT_FACE_DOWN, + + /// + /// Gamepad left DPAD left button + /// + GAMEPAD_BUTTON_LEFT_FACE_LEFT, + + /// + /// Gamepad right button up (i.e. PS3: Triangle, Xbox: Y) + /// + GAMEPAD_BUTTON_RIGHT_FACE_UP, + + /// + /// Gamepad right button right (i.e. PS3: Square, Xbox: X) + /// + GAMEPAD_BUTTON_RIGHT_FACE_RIGHT, + + /// + /// Gamepad right button down (i.e. PS3: Cross, Xbox: A) + /// + GAMEPAD_BUTTON_RIGHT_FACE_DOWN, + + /// + /// Gamepad right button left (i.e. PS3: Circle, Xbox: B) + /// + GAMEPAD_BUTTON_RIGHT_FACE_LEFT, + + // Triggers + GAMEPAD_BUTTON_LEFT_TRIGGER_1, + GAMEPAD_BUTTON_LEFT_TRIGGER_2, + GAMEPAD_BUTTON_RIGHT_TRIGGER_1, + GAMEPAD_BUTTON_RIGHT_TRIGGER_2, + + // These are buttons in the center of the gamepad + + /// + /// PS3 Select + /// + GAMEPAD_BUTTON_MIDDLE_LEFT, + + /// + /// PS Button/XBOX Button + /// + GAMEPAD_BUTTON_MIDDLE, + + /// + /// PS3 Start + /// + GAMEPAD_BUTTON_MIDDLE_RIGHT, + + /// + /// Left joystick press button + /// + GAMEPAD_BUTTON_LEFT_THUMB, + + /// + /// Right joystick press button + /// + GAMEPAD_BUTTON_RIGHT_THUMB + } + + /// Gesture + /// NOTE: It could be used as flags to enable only some gestures + /// + [Flags] + public enum Gesture : uint + { + GESTURE_NONE = 0, + GESTURE_TAP = 1, + GESTURE_DOUBLETAP = 2, + GESTURE_HOLD = 4, + GESTURE_DRAG = 8, + GESTURE_SWIPE_RIGHT = 16, + GESTURE_SWIPE_LEFT = 32, + GESTURE_SWIPE_UP = 64, + GESTURE_SWIPE_DOWN = 128, + GESTURE_PINCH_IN = 256, + GESTURE_PINCH_OUT = 512 + } + + /// + /// Head-Mounted-Display device parameters + /// + [StructLayout(LayoutKind.Sequential)] + public unsafe partial struct VrDeviceInfo + { + /// + /// HMD horizontal resolution in pixels + /// + public int hResolution; + + /// + /// HMD vertical resolution in pixels + /// + public int vResolution; + + /// + /// HMD horizontal size in meters + /// + public float hScreenSize; + + /// + /// HMD vertical size in meters + /// + public float vScreenSize; + + /// + /// HMD screen center in meters + /// + public float vScreenCenter; + + /// + /// HMD distance between eye and display in meters + /// + public float eyeToScreenDistance; + + /// + /// HMD lens separation distance in meters + /// + public float lensSeparationDistance; + + /// + /// HMD IPD (distance between pupils) in meters + /// + public float interpupillaryDistance; + + /// + /// HMD lens distortion constant parameters + /// + public fixed float lensDistortionValues[4]; + + /// + /// HMD chromatic aberration correction parameters + /// + public fixed float chromaAbCorrection[4]; + } + + /// + /// VR Stereo rendering configuration for simulator + /// + [StructLayout(LayoutKind.Sequential)] + public partial struct VrStereoConfig + { + /// + /// VR projection matrices (per eye) + /// + public Matrix4x4 projection1; + + /// + /// VR projection matrices (per eye) + /// + public Matrix4x4 projection2; + + /// + /// VR view offset matrices (per eye) + /// + public Matrix4x4 viewOffset1; + + /// + /// VR view offset matrices (per eye) + /// + public Matrix4x4 viewOffset2; + + /// + /// VR left lens center + /// + public Vector2 leftLensCenter; + + /// + /// VR right lens center + /// + public Vector2 rightLensCenter; + + /// + /// VR left screen center + /// + public Vector2 leftScreenCenter; + + /// + /// VR right screen center + /// + public Vector2 rightScreenCenter; + + /// + /// VR distortion scale + /// + public Vector2 scale; + + /// + /// VR distortion scale in + /// + public Vector2 scaleIn; + } +} diff --git a/Raylib-cs/types/Logging.cs b/Raylib-cs/types/Logging.cs new file mode 100644 index 0000000..db0f3fe --- /dev/null +++ b/Raylib-cs/types/Logging.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 gpOffset; + uint fpOffset; + IntPtr overflowArgArea; + IntPtr regSaveArea; + } + + /// + /// Logging workaround for formatting strings from native code + /// + public static unsafe class Logging + { + static Logging() + { + Raylib.SetTraceLogCallback(&LogConsole); + } + + [UnmanagedCallersOnly(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })] + public static unsafe void LogConsole(int msgType, sbyte* text, sbyte* args) + { + var message = GetLogMessage(new IntPtr(text), new IntPtr(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 + 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/types/Material.cs b/Raylib-cs/types/Material.cs new file mode 100644 index 0000000..fcb4f4d --- /dev/null +++ b/Raylib-cs/types/Material.cs @@ -0,0 +1,92 @@ +using System; +using System.Runtime.InteropServices; + +namespace Raylib_cs +{ + /// + /// Material map index + /// + public enum MaterialMapIndex + { + /// + /// NOTE: Same as MATERIAL_MAP_DIFFUSE + /// + MATERIAL_MAP_ALBEDO = 0, + + /// + /// NOTE: Same as MATERIAL_MAP_SPECULAR + /// + MATERIAL_MAP_METALNESS, + + MATERIAL_MAP_NORMAL, + MATERIAL_MAP_ROUGHNESS, + MATERIAL_MAP_OCCLUSION, + MATERIAL_MAP_EMISSION, + MATERIAL_MAP_HEIGHT, + + /// + /// NOTE: Uses GL_TEXTURE_CUBE_MAP + /// + MATERIAL_MAP_CUBEMAP, + + /// + /// NOTE: Uses GL_TEXTURE_CUBE_MAP + /// + MATERIAL_MAP_IRRADIANCE, + + /// + /// NOTE: Uses GL_TEXTURE_CUBE_MAP + /// + MATERIAL_MAP_PREFILTER, + + MATERIAL_MAP_BRDF, + + MATERIAL_MAP_DIFFUSE = MATERIAL_MAP_ALBEDO, + MATERIAL_MAP_SPECULAR = MATERIAL_MAP_METALNESS, + } + + /// + /// Material texture map + /// + [StructLayout(LayoutKind.Sequential)] + public partial struct MaterialMap + { + /// + /// Material map texture + /// + public Texture2D texture; + + /// + /// Material map color + /// + public Color color; + + /// + /// Material map value + /// + public float value; + } + + /// + /// Material type (generic) + /// + [StructLayout(LayoutKind.Sequential)] + public unsafe partial struct Material + { + /// + /// Material shader + /// + public Shader shader; + + //TODO: convert + /// + /// Material maps + /// + public MaterialMap* maps; + + /// + /// Material generic parameters (if required) + /// + public fixed float param[4]; + } +} diff --git a/Raylib-cs/types/Mesh.cs b/Raylib-cs/types/Mesh.cs new file mode 100644 index 0000000..1f4562d --- /dev/null +++ b/Raylib-cs/types/Mesh.cs @@ -0,0 +1,101 @@ +using System; +using System.Numerics; +using System.Runtime.InteropServices; + +namespace Raylib_cs +{ + /// + /// Vertex data definning a mesh
+ /// NOTE: Data stored in CPU memory (and GPU) + ///
+ [StructLayout(LayoutKind.Sequential)] + public unsafe partial struct Mesh + { + /// + /// Number of vertices stored in arrays + /// + public int vertexCount; + + /// + /// Number of triangles stored (indexed or not) + /// + public int triangleCount; + + #region Default vertex data + + /// + /// Vertex position (XYZ - 3 components per vertex) (shader-location = 0) + /// + public float* vertices; + + /// + /// Vertex texture coordinates (UV - 2 components per vertex) (shader-location = 1) + /// + public float* texcoords; + + /// + /// Vertex second texture coordinates (useful for lightmaps) (shader-location = 5) + /// + public float* texcoords2; + + /// + /// Vertex normals (XYZ - 3 components per vertex) (shader-location = 2) + /// + public float* normals; + + /// + /// Vertex tangents (XYZW - 4 components per vertex) (shader-location = 4) + /// + public float* tangents; + + /// + /// Vertex colors (RGBA - 4 components per vertex) (shader-location = 3) + /// + public byte* colors; + + /// + /// Vertex indices (in case vertex data comes indexed) + /// + public ushort* indices; + + #endregion + + #region Animation vertex data + + /// + /// Animated vertex positions (after bones transformations) + /// + public float* animVertices; + + /// + /// Animated normals (after bones transformations) + /// + public float* animNormals; + + /// + /// Vertex bone ids, up to 4 bones influence by vertex (skinning) + /// + public byte* boneIds; + + /// + /// Vertex bone weight, up to 4 bones influence by vertex (skinning) + /// + public float* boneWeights; + + #endregion + + #region OpenGL identifiers + + /// + /// OpenGL Vertex Array Object id + /// + public uint vaoId; + + /// + /// OpenGL Vertex Buffer Objects id (default vertex data, uint[]) + /// + public uint* vboId; + + #endregion + } +} diff --git a/Raylib-cs/types/Model.cs b/Raylib-cs/types/Model.cs new file mode 100644 index 0000000..4cd1553 --- /dev/null +++ b/Raylib-cs/types/Model.cs @@ -0,0 +1,151 @@ +using System; +using System.Numerics; +using System.Runtime.InteropServices; + +namespace Raylib_cs +{ + /// + /// Bone information + /// + [StructLayout(LayoutKind.Sequential)] + public unsafe partial struct BoneInfo + { + /// + /// Bone name (char[32]) + /// + public fixed sbyte name[32]; + + /// + /// Bone parent + /// + public int parent; + } + + /// + /// Model type + /// + [StructLayout(LayoutKind.Sequential)] + public unsafe partial struct Model + { + /// + /// Local transform matrix + /// + public Matrix4x4 transform; + + /// + /// Number of meshes + /// + public int meshCount; + + /// + /// Number of materials + /// + public int materialCount; + + /// + /// Meshes array (Mesh *) + /// + public Mesh* meshes; + + /// + /// Materials array (Material *) + /// + public Material* materials; + + /// + /// Mesh material number (int *) + /// + public int* meshMaterial; + + /// + /// Number of bones + /// + public int boneCount; + + //TODO: Span + /// + /// Bones information (skeleton, BoneInfo *) + /// + public BoneInfo* bones; + + //TODO: Span + /// + /// Bones base transformation (pose, Transform *) + /// + public Transform* bindPose; + } + + /// + /// Model animation + /// + [StructLayout(LayoutKind.Sequential)] + public readonly unsafe partial struct ModelAnimation + { + /// + /// Number of bones + /// + public readonly int boneCount; + + /// + /// Number of animation frames + /// + public readonly int frameCount; + + /// + /// Bones information (skeleton, BoneInfo *) + /// + public readonly BoneInfo* bones; + + /// + public ReadOnlySpan BoneInfo => new(bones, boneCount); + + /// + /// Poses array by frame (Transform **) + /// + public readonly Transform** framePoses; + + /// + public FramePosesCollection FramePoses => new(framePoses, frameCount, boneCount); + + public struct FramePosesCollection + { + readonly Transform** framePoses; + + readonly int frameCount; + + readonly int boneCount; + + public FramePoses this[int index] => new(framePoses[index], boneCount); + + public Transform this[int index1, int index2] => new FramePoses(framePoses[index1], boneCount)[index2]; + + internal FramePosesCollection(Transform** framePoses, int frameCount, int boneCount) + { + this.framePoses = framePoses; + this.frameCount = frameCount; + this.boneCount = boneCount; + } + } + } + + public unsafe struct FramePoses + { + readonly Transform* poses; + + readonly int count; + + public ref Transform this[int index] + { + get + { + return ref poses[index]; + } + } + + internal FramePoses(Transform* poses, int count) + { + this.poses = poses; + this.count = count; + } + } +} diff --git a/Raylib-cs/types/NPatchInfo.cs b/Raylib-cs/types/NPatchInfo.cs new file mode 100644 index 0000000..6030f35 --- /dev/null +++ b/Raylib-cs/types/NPatchInfo.cs @@ -0,0 +1,62 @@ +using System.Runtime.InteropServices; + +namespace Raylib_cs +{ + /// + /// N-patch layout + /// + public enum NPatchLayout + { + /// + /// Npatch defined by 3x3 tiles + /// + NPATCH_NINE_PATCH = 0, + + /// + /// Npatch defined by 1x3 tiles + /// + NPATCH_THREE_PATCH_VERTICAL, + + /// + /// Npatch defined by 3x1 tiles + /// + NPATCH_THREE_PATCH_HORIZONTAL + } + + /// + /// N-Patch layout info + /// + [StructLayout(LayoutKind.Sequential)] + public partial struct NPatchInfo + { + /// + /// Texture source rectangle + /// + public Rectangle source; + + /// + /// Left border offset + /// + public int left; + + /// + /// Top border offset + /// + public int top; + + /// + /// Right border offset + /// + public int right; + + /// + /// Bottom border offset + /// + public int bottom; + + /// + /// Layout of the n-patch: 3x3, 1x3 or 3x1 + /// + public NPatchLayout layout; + } +} diff --git a/Raylib-cs/types/Ray.cs b/Raylib-cs/types/Ray.cs new file mode 100644 index 0000000..93007c7 --- /dev/null +++ b/Raylib-cs/types/Ray.cs @@ -0,0 +1,55 @@ +using System.Numerics; +using System.Runtime.InteropServices; + +namespace Raylib_cs +{ + /// + /// Ray, ray for raycasting + /// + [StructLayout(LayoutKind.Sequential)] + public partial struct Ray + { + /// + /// Ray position (origin) + /// + public Vector3 position; + + /// + /// Ray direction + /// + public Vector3 direction; + + public Ray(Vector3 position, Vector3 direction) + { + this.position = position; + this.direction = direction; + } + } + + /// + /// Raycast hit information + /// + [StructLayout(LayoutKind.Sequential)] + public partial struct RayCollision + { + /// + /// Did the ray hit something? + /// + public CBool hit; + + /// + /// Distance to nearest hit + /// + public float distance; + + /// + /// Position of nearest hit + /// + public Vector3 point; + + /// + /// Surface normal of hit + /// + public Vector3 normal; + } +} diff --git a/Raylib-cs/types/Raylib.Utils.cs b/Raylib-cs/types/Raylib.Utils.cs new file mode 100644 index 0000000..2788663 --- /dev/null +++ b/Raylib-cs/types/Raylib.Utils.cs @@ -0,0 +1,929 @@ +using System; +using System.Numerics; +using System.Runtime.InteropServices; + +namespace Raylib_cs +{ + public static unsafe partial class Raylib + { + /// Initialize window and OpenGL context + public static void InitWindow(int width, int height, string title) + { + using var str1 = title.ToUTF8Buffer(); + InitWindow(width, height, str1.AsPointer()); + } + + /// Set title for window (only PLATFORM_DESKTOP) + public static void SetWindowTitle(string title) + { + using var str1 = title.ToUTF8Buffer(); + SetWindowTitle(str1.AsPointer()); + } + + /// Get the human-readable, UTF-8 encoded name of the primary monitor + public static string GetMonitorName_(int monitor) + { + return Utf8StringUtils.GetUTF8String(GetMonitorName(monitor)); + } + + /// Get clipboard text content + public static string GetClipboardText_() + { + return Utf8StringUtils.GetUTF8String(GetClipboardText()); + } + + /// Set clipboard text content + public static void SetClipboardText(string text) + { + using var str1 = text.ToUTF8Buffer(); + SetClipboardText(str1.AsPointer()); + } + + /// Load shader from files and bind default locations + public static Shader LoadShader(string vsFileName, string fsFileName) + { + using var str1 = vsFileName.ToUTF8Buffer(); + using var str2 = fsFileName.ToUTF8Buffer(); + return LoadShader(str1.AsPointer(), str2.AsPointer()); + } + + /// Load shader from code string and bind default locations + public static Shader LoadShaderFromMemory(string vsCode, string fsCode) + { + using var str1 = vsCode.ToUTF8Buffer(); + using var str2 = fsCode.ToUTF8Buffer(); + return LoadShaderFromMemory(str1.AsPointer(), str2.AsPointer()); + } + + /// Get shader uniform location + public static int GetShaderLocation(Shader shader, string uniformName) + { + using var str1 = uniformName.ToUTF8Buffer(); + return GetShaderLocation(shader, str1.AsPointer()); + } + + /// Get shader attribute location + public static int GetShaderLocationAttrib(Shader shader, string attribName) + { + using var str1 = attribName.ToUTF8Buffer(); + return GetShaderLocationAttrib(shader, str1.AsPointer()); + } + + /// Takes a screenshot of current screen (saved a .png) + public static void TakeScreenshot(string fileName) + { + using var str1 = fileName.ToUTF8Buffer(); + TakeScreenshot(str1.AsPointer()); + } + + /// Check file extension + public static CBool IsFileExtension(string fileName, string ext) + { + using var str1 = fileName.ToUTF8Buffer(); + using var str2 = ext.ToUTF8Buffer(); + return IsFileExtension(str1.AsPointer(), str2.AsPointer()); + } + + /// Get file modification time (last write time) + public static long GetFileModTime(string fileName) + { + using var str1 = fileName.ToUTF8Buffer(); + return GetFileModTime(str1.AsPointer()); + } + + /// Load image from file into CPU memory (RAM) + public static Image LoadImage(string fileName) + { + using var str1 = fileName.ToUTF8Buffer(); + return LoadImage(str1.AsPointer()); + } + + /// Load image from RAW file data + public static Image LoadImageRaw(string fileName, int width, int height, PixelFormat format, int headerSize) + { + using var str1 = fileName.ToUTF8Buffer(); + return LoadImageRaw(str1.AsPointer(), width, height, format, headerSize); + } + + /// Load image sequence from file (frames appended to image.data) + public static Image LoadImageAnim(string fileName, int[] frames) + { + using var str1 = fileName.ToUTF8Buffer(); + fixed (int* p = frames) + { + return LoadImageAnim(str1.AsPointer(), p); + } + } + + /// Export image data to file + public static void ExportImage(Image image, string fileName) + { + using var str1 = fileName.ToUTF8Buffer(); + ExportImage(image, str1.AsPointer()); + } + + /// Export image as code file defining an array of bytes + public static void ExportImageAsCode(Image image, string fileName) + { + using var str1 = fileName.ToUTF8Buffer(); + ExportImageAsCode(image, str1.AsPointer()); + } + + /// Show trace log messages (LOG_DEBUG, LOG_INFO, LOG_WARNING, LOG_ERROR) + public static void TraceLog(TraceLogLevel logLevel, string text) + { + using var str1 = text.ToUTF8Buffer(); + TraceLog(logLevel, str1.AsPointer()); + } + + /// Set shader uniform value vector + public static void SetShaderValueV(Shader shader, int uniformLoc, T[] values, ShaderUniformDataType uniformType, int count) + where T : unmanaged + { + SetShaderValueV(shader, uniformLoc, (Span)values, uniformType, count); + } + + /// Set shader uniform value vector + public static void SetShaderValueV(Shader shader, int uniformLoc, Span values, ShaderUniformDataType uniformType, int count) + where T : unmanaged + { + fixed (T* valuePtr = values) + { + SetShaderValueV(shader, uniformLoc, valuePtr, uniformType, count); + } + } + + /// Set shader uniform value + public static void SetShaderValue(Shader shader, int uniformLoc, T value, ShaderUniformDataType uniformType) + where T : unmanaged + { + SetShaderValue(shader, uniformLoc, &value, uniformType); + } + + /// Set shader uniform value + public static void SetShaderValue(Shader shader, int uniformLoc, T[] values, ShaderUniformDataType uniformType) + where T : unmanaged + { + SetShaderValue(shader, uniformLoc, (Span)values, uniformType); + } + + /// Set shader uniform value + public static void SetShaderValue(Shader shader, int uniformLoc, Span values, ShaderUniformDataType uniformType) + where T : unmanaged + { + fixed (T* valuePtr = values) + { + SetShaderValue(shader, uniformLoc, valuePtr, uniformType); + } + } + + /// Load file data as byte array (read) + public static byte* LoadFileData(string fileName, ref uint bytesRead) + { + using var str1 = fileName.ToUTF8Buffer(); + fixed (uint* p = &bytesRead) + { + return LoadFileData(str1.AsPointer(), p); + } + } + + /// Get dropped files names (memory should be freed) + public static string[] GetDroppedFiles() + { + int count; + var buffer = GetDroppedFiles(&count); + var files = new string[count]; + + for (var i = 0; i < count; i++) + { + files[i] = Marshal.PtrToStringUTF8((IntPtr)buffer[i]); + } + + return files; + } + + /// Return gamepad internal name id + public static string GetGamepadName_(int gamepad) + { + return Utf8StringUtils.GetUTF8String(GetGamepadName(gamepad)); + } + + /// Update camera position for selected mode + public static void UpdateCamera(ref Camera3D camera) + { + fixed (Camera3D* c = &camera) + { + UpdateCamera(c); + } + } + + /// Check the collision between two lines defined by two points each, returns collision point by reference + public static CBool CheckCollisionLines(Vector2 startPos1, Vector2 endPos1, Vector2 startPos2, Vector2 endPos2, ref Vector2 collisionPoint) + { + fixed (Vector2* p = &collisionPoint) + { + return CheckCollisionLines(startPos1, endPos1, startPos2, endPos2, p); + } + } + + /// Create an image from text (default font) + public static Image ImageText(string text, int fontSize, Color color) + { + using var str1 = text.ToUTF8Buffer(); + return ImageText(str1.AsPointer(), fontSize, color); + } + + /// Create an image from text (custom sprite font) + public static Image ImageTextEx(Font font, string text, float fontSize, float spacing, Color tint) + { + using var str1 = text.ToUTF8Buffer(); + return ImageTextEx(font, str1.AsPointer(), fontSize, spacing, tint); + } + + /// Convert image to POT (power-of-two) + public static void ImageToPOT(ref Image image, Color fill) + { + fixed (Image* p = &image) + { + ImageToPOT(p, fill); + } + } + + /// Convert image data to desired format + public static void ImageFormat(ref Image image, PixelFormat newFormat) + { + fixed (Image* p = &image) + { + ImageFormat(p, newFormat); + } + } + + /// Apply alpha mask to image + public static void ImageAlphaMask(ref Image image, Image alphaMask) + { + fixed (Image* p = &image) + { + ImageAlphaMask(p, alphaMask); + } + } + + /// Clear alpha channel to desired color + public static void ImageAlphaClear(ref Image image, Color color, float threshold) + { + fixed (Image* p = &image) + { + ImageAlphaClear(p, color, threshold); + } + } + + /// Crop image depending on alpha value + public static void ImageAlphaCrop(ref Image image, float threshold) + { + fixed (Image* p = &image) + { + ImageAlphaCrop(p, threshold); + } + } + + /// Premultiply alpha channel + public static void ImageAlphaPremultiply(ref Image image) + { + fixed (Image* p = &image) + { + ImageAlphaPremultiply(p); + } + } + + /// Crop an image to a defined rectangle + public static void ImageCrop(ref Image image, Rectangle crop) + { + fixed (Image* p = &image) + { + ImageCrop(p, crop); + } + } + + /// Resize image (Bicubic scaling algorithm) + public static void ImageResize(ref Image image, int newWidth, int newHeight) + { + fixed (Image* p = &image) + { + ImageResize(p, newWidth, newHeight); + } + } + + /// Resize image (Nearest-Neighbor scaling algorithm) + public static void ImageResizeNN(ref Image image, int newWidth, int newHeight) + { + fixed (Image* p = &image) + { + ImageResizeNN(p, newWidth, newHeight); + } + } + + /// Resize canvas and fill with color + public static void ImageResizeCanvas(ref Image image, int newWidth, int newHeight, int offsetX, int offsetY, Color color) + { + fixed (Image* p = &image) + { + ImageResizeCanvas(p, newWidth, newHeight, offsetX, offsetY, color); + } + } + + /// Generate all mipmap levels for a provided image + public static void ImageMipmaps(ref Image image) + { + fixed (Image* p = &image) + { + ImageMipmaps(p); + } + } + + /// Dither image data to 16bpp or lower (Floyd-Steinberg dithering) + public static void ImageDither(ref Image image, int rBpp, int gBpp, int bBpp, int aBpp) + { + fixed (Image* p = &image) + { + ImageDither(p, rBpp, gBpp, bBpp, aBpp); + } + } + + /// Flip image vertically + public static void ImageFlipVertical(ref Image image) + { + fixed (Image* p = &image) + { + ImageFlipVertical(p); + } + } + + /// Flip image horizontally + public static void ImageFlipHorizontal(ref Image image) + { + fixed (Image* p = &image) + { + ImageFlipHorizontal(p); + } + } + + /// Rotate image clockwise 90deg + public static void ImageRotateCW(ref Image image) + { + fixed (Image* p = &image) + { + ImageRotateCW(p); + } + } + + /// Rotate image counter-clockwise 90deg + public static void ImageRotateCCW(ref Image image) + { + fixed (Image* p = &image) + { + ImageRotateCCW(p); + } + } + + /// Modify image color: tint + public static void ImageColorTint(ref Image image, Color color) + { + fixed (Image* p = &image) + { + ImageColorTint(p, color); + } + } + + /// Modify image color: invert + public static void ImageColorInvert(ref Image image) + { + fixed (Image* p = &image) + { + ImageColorInvert(p); + } + } + + /// Modify image color: grayscale + public static void ImageColorGrayscale(ref Image image) + { + fixed (Image* p = &image) + { + ImageColorGrayscale(p); + } + } + + /// Modify image color: contrast (-100 to 100) + public static void ImageColorContrast(ref Image image, float contrast) + { + fixed (Image* p = &image) + { + ImageColorContrast(p, contrast); + } + } + + /// Modify image color: brightness (-255 to 255) + public static void ImageColorBrightness(ref Image image, int brightness) + { + fixed (Image* p = &image) + { + ImageColorBrightness(p, brightness); + } + } + + /// Modify image color: replace color + public static void ImageColorReplace(ref Image image, Color color, Color replace) + { + fixed (Image* p = &image) + { + ImageColorReplace(p, color, replace); + } + } + + /// Clear image background with given color + public static void ImageClearBackground(ref Image dst, Color color) + { + fixed (Image* p = &dst) + { + ImageClearBackground(p, color); + } + } + + /// Draw pixel within an image + public static void ImageDrawPixel(ref Image dst, int posX, int posY, Color color) + { + fixed (Image* p = &dst) + { + ImageDrawPixel(p, posX, posY, color); + } + } + + /// Draw pixel within an image (Vector version) + public static void ImageDrawPixelV(ref Image dst, Vector2 position, Color color) + { + fixed (Image* p = &dst) + { + ImageDrawPixelV(p, position, color); + } + } + + /// Draw line within an image + public static void ImageDrawLine(ref Image dst, int startPosX, int startPosY, int endPosX, int endPosY, Color color) + { + fixed (Image* p = &dst) + { + ImageDrawLine(p, startPosX, startPosY, endPosX, endPosY, color); + } + } + + /// Draw line within an image (Vector version) + public static void ImageDrawLineV(ref Image dst, Vector2 start, Vector2 end, Color color) + { + fixed (Image* p = &dst) + { + ImageDrawLineV(p, start, end, color); + } + } + + /// Draw circle within an image + public static void ImageDrawCircle(ref Image dst, int centerX, int centerY, int radius, Color color) + { + fixed (Image* p = &dst) + { + ImageDrawCircle(p, centerX, centerY, radius, color); + } + } + + /// Draw circle within an image (Vector version) + public static void ImageDrawCircleV(ref Image dst, Vector2 center, int radius, Color color) + { + fixed (Image* p = &dst) + { + ImageDrawCircleV(p, center, radius, color); + } + } + + /// Draw rectangle within an image + public static void ImageDrawRectangle(ref Image dst, int posX, int posY, int width, int height, Color color) + { + fixed (Image* p = &dst) + { + ImageDrawRectangle(p, posX, posY, width, height, color); + } + } + + /// Draw rectangle within an image (Vector version) + public static void ImageDrawRectangleV(ref Image dst, Vector2 position, Vector2 size, Color color) + { + fixed (Image* p = &dst) + { + ImageDrawRectangleV(p, position, size, color); + } + } + + /// Draw rectangle within an image + public static void ImageDrawRectangleRec(ref Image dst, Rectangle rec, Color color) + { + fixed (Image* p = &dst) + { + ImageDrawRectangleRec(p, rec, color); + } + } + + /// Draw rectangle lines within an image + public static void ImageDrawRectangleLines(ref Image dst, Rectangle rec, int thick, Color color) + { + fixed (Image* p = &dst) + { + ImageDrawRectangleLines(p, rec, thick, color); + } + } + + /// Draw a source image within a destination image (tint applied to source) + public static void ImageDraw(ref Image dst, Image src, Rectangle srcRec, Rectangle dstRec, Color tint) + { + fixed (Image* p = &dst) + { + ImageDraw(p, src, srcRec, dstRec, tint); + } + } + + /// Draw text (using default font) within an image (destination) + public static void ImageDrawText(ref Image dst, string text, int x, int y, int fontSize, Color color) + { + using var str1 = text.ToUTF8Buffer(); + fixed (Image* p = &dst) + { + ImageDrawText(p, str1.AsPointer(), x, y, fontSize, color); + } + } + + /// Draw text (custom sprite font) within an image (destination) + public static void ImageDrawTextEx(ref Image dst, Font font, string text, Vector2 position, int fontSize, float spacing, Color color) + { + using var str1 = text.ToUTF8Buffer(); + fixed (Image* p = &dst) + { + ImageDrawTextEx(p, font, str1.AsPointer(), position, fontSize, spacing, color); + } + } + + /// Load texture from file into GPU memory (VRAM) + public static Texture2D LoadTexture(string fileName) + { + using var str1 = fileName.ToUTF8Buffer(); + return LoadTexture(str1.AsPointer()); + } + + /// Generate GPU mipmaps for a texture + public static void GenTextureMipmaps(ref Texture2D texture) + { + fixed (Texture2D* p = &texture) + { + GenTextureMipmaps(p); + } + } + + /// Load font from file into GPU memory (VRAM) + public static Font LoadFont(string fileName) + { + using var str1 = fileName.ToUTF8Buffer(); + return LoadFont(str1.AsPointer()); + } + + /// Load font from file with extended parameters + public static Font LoadFontEx(string fileName, int fontSize, int[] fontChars, int charsCount) + { + using var str1 = fileName.ToUTF8Buffer(); + return LoadFontEx(str1.AsPointer(), fontSize, fontChars, charsCount); + } + + /// Upload vertex data into GPU and provided VAO/VBO ids + public static void UploadMesh(ref Mesh mesh, CBool dynamic) + { + fixed (Mesh* p = &mesh) + { + UploadMesh(p, dynamic); + } + } + + /// Unload mesh from memory (RAM and/or VRAM) + public static void UnloadMesh(ref Mesh mesh) + { + fixed (Mesh* p = &mesh) + { + UnloadMesh(p); + } + } + + /// Set texture for a material map type (MAP_DIFFUSE, MAP_SPECULAR...) + public static void SetMaterialTexture(ref Material material, MaterialMapIndex mapType, Texture2D texture) + { + fixed (Material* p = &material) + { + SetMaterialTexture(p, mapType, texture); + } + } + + /// Set material for a mesh + public static void SetModelMeshMaterial(ref Model model, int meshId, int materialId) + { + fixed (Model* p = &model) + { + SetModelMeshMaterial(p, meshId, materialId); + } + } + + /// Load model animations from file + public static ReadOnlySpan LoadModelAnimations(string fileName, ref uint animsCount) + { + using var str1 = fileName.ToUTF8Buffer(); + fixed (uint* p = &animsCount) + { + var model = LoadModelAnimations(str1.AsPointer(), p); + + if ((IntPtr)model == IntPtr.Zero) + { + throw new ApplicationException("Failed to load animation"); + } + + return new ReadOnlySpan(model, (int)animsCount); + } + } + + /// Compute mesh tangents + public static void GenMeshTangents(ref Mesh mesh) + { + fixed (Mesh* p = &mesh) + { + GenMeshTangents(p); + } + } + + /// Compute mesh binormals + public static void GenMeshBinormals(ref Mesh mesh) + { + fixed (Mesh* p = &mesh) + { + GenMeshBinormals(p); + } + } + + /// Convert wave data to desired format + public static void WaveFormat(ref Wave wave, int sampleRate, int sampleSize, int channels) + { + fixed (Wave* p = &wave) + { + WaveFormat(p, sampleRate, sampleSize, channels); + } + } + + /// Crop a wave to defined samples range + public static void WaveCrop(ref Wave wave, int initSample, int finalSample) + { + fixed (Wave* p = &wave) + { + WaveCrop(p, initSample, finalSample); + } + } + + /// Draw lines sequence + public static void DrawLineStrip(Vector2[] points, int numPoints, Color color) + { + fixed (Vector2* p = points) + { + DrawLineStrip(p, numPoints, color); + } + } + + /// Draw a triangle fan defined by points (first vertex is the center) + public static void DrawTriangleFan(Vector2[] points, int numPoints, Color color) + { + fixed (Vector2* p = points) + { + DrawTriangleFan(p, numPoints, color); + } + } + + /// Draw a triangle strip defined by points + public static void DrawTriangleStrip(Vector2[] points, int pointsCount, Color color) + { + fixed (Vector2* p = points) + { + DrawTriangleStrip(p, pointsCount, color); + } + } + + /// Draw a textured polygon + public static void DrawTexturePoly(Texture2D texture, Vector2 center, Vector2[] points, Vector2[] texcoords, int pointsCount, Color tint) + { + fixed (Vector2* p = points) + { + fixed (Vector2* p1 = texcoords) + { + DrawTexturePoly(texture, center, p, p1, pointsCount, tint); + } + } + } + + /// Draw text (using default font) + public static void DrawText(string text, int posX, int posY, int fontSize, Color color) + { + using var str1 = text.ToUTF8Buffer(); + DrawText(str1.AsPointer(), posX, posY, fontSize, color); + } + + /// Draw text using font and additional parameters + public static void DrawTextEx(Font font, string text, Vector2 position, float fontSize, float spacing, Color tint) + { + using var str1 = text.ToUTF8Buffer(); + DrawTextEx(font, str1.AsPointer(), position, fontSize, spacing, tint); + } + + /// Draw text using Font and pro parameters (rotation) + public static void DrawTextPro(Font font, string text, Vector2 position, Vector2 origin, float rotation, float fontSize, float spacing, Color tint) + { + using var str1 = text.ToUTF8Buffer(); + DrawTextPro(font, str1.AsPointer(), position, origin, rotation, fontSize, spacing, tint); + } + + /// Measure string width for default font + public static int MeasureText(string text, int fontSize) + { + using var str1 = text.ToUTF8Buffer(); + return MeasureText(str1.AsPointer(), fontSize); + } + + /// Measure string size for Font + public static Vector2 MeasureTextEx(Font font, string text, float fontSize, float spacing) + { + using var str1 = text.ToUTF8Buffer(); + return MeasureTextEx(font, str1.AsPointer(), fontSize, spacing); + } + + /// Append text at specific position and move cursor! + public static void TextAppend(string text, string append, int position) + { + using var str1 = text.ToUTF8Buffer(); + using var str2 = append.ToUTF8Buffer(); + TextAppend(str1.AsPointer(), str2.AsPointer(), &position); + } + + /// Get Pascal case notation version of provided string + public static string TextToPascal(string text) + { + using var str1 = text.ToUTF8Buffer(); + return Utf8StringUtils.GetUTF8String(TextToPascal(str1.AsPointer())); + } + + /// Get integer value from text (negative values not supported) + public static int TextToInteger(string text) + { + using var str1 = text.ToUTF8Buffer(); + return TextToInteger(str1.AsPointer()); + } + + /// Get all codepoints in a string, codepoints count returned by parameters + public static int[] LoadCodepoints(string text, ref int count) + { + using var str1 = text.ToUTF8Buffer(); + fixed (int* c = &count) + { + var pointsPtr = LoadCodepoints(str1.AsPointer(), c); + var codepoints = new ReadOnlySpan(pointsPtr, count).ToArray(); + UnloadCodepoints(pointsPtr); + return codepoints; + } + } + + /// Get total number of characters (codepoints) in a UTF8 encoded string + public static int GetCodepointCount(string text) + { + using var str1 = text.ToUTF8Buffer(); + return GetCodepointCount(str1.AsPointer()); + } + + /// Returns next codepoint in a UTF8 encoded string; 0x3f('?') is returned on failure + /// single codepoint / "char" + public static int GetCodepoint(string text, ref int bytesProcessed) + { + using var str1 = text.ToUTF8Buffer(); + fixed (int* p = &bytesProcessed) + { + return GetCodepoint(str1.AsPointer(), p); + } + } + + /// Encode codepoint into utf8 text (char array length returned as parameter) + public static string CodepointToUTF8(int codepoint, ref int byteSize) + { + fixed (int* l1 = &byteSize) + { + var ptr = CodepointToUTF8(codepoint, l1); + return Utf8StringUtils.GetUTF8String(ptr); + } + } + + /// Encode codepoint into utf8 text (char array length returned as parameter) + public static string TextCodepointsToUTF8(int[] codepoints, int length) + { + fixed (int* c1 = codepoints) + { + var ptr = TextCodepointsToUTF8(c1, length); + var text = Utf8StringUtils.GetUTF8String(ptr); + MemFree(ptr); + return text; + } + } + + /// Draw a model (with texture if set) + public static Model LoadModel(string fileName) + { + using var str1 = fileName.ToUTF8Buffer(); + return LoadModel(str1.AsPointer()); + } + + /// Export mesh data to file, returns true on success + public static CBool ExportMesh(Mesh mesh, string fileName) + { + using var str1 = fileName.ToUTF8Buffer(); + return ExportMesh(mesh, str1.AsPointer()); + } + + /// Draw a triangle strip defined by points + public static void DrawTriangleStrip3D(Vector3[] points, int pointsCount, Color color) + { + fixed (Vector3* p = points) + { + DrawTriangleStrip3D(p, pointsCount, color); + } + } + + /// Draw multiple mesh instances with material and different transforms + public static void DrawMeshInstanced(Mesh mesh, Material material, Matrix4x4[] transforms, int instances) + { + fixed (Matrix4x4* p = transforms) + { + DrawMeshInstanced(mesh, material, p, instances); + } + } + + /// Load wave data from file + public static Wave LoadWave(string fileName) + { + using var str1 = fileName.ToUTF8Buffer(); + return LoadWave(str1.AsPointer()); + } + + /// Load sound from file + public static Sound LoadSound(string fileName) + { + using var str1 = fileName.ToUTF8Buffer(); + return LoadSound(str1.AsPointer()); + } + + /// Export wave data to file + public static void ExportWave(Wave wave, string fileName) + { + using var str1 = fileName.ToUTF8Buffer(); + ExportWave(wave, str1.AsPointer()); + } + + /// Export wave sample data to code (.h) + public static void ExportWaveAsCode(Wave wave, string fileName) + { + using var str1 = fileName.ToUTF8Buffer(); + ExportWaveAsCode(wave, str1.AsPointer()); + } + + /// Load music stream from file + public static Music LoadMusicStream(string fileName) + { + using var str1 = fileName.ToUTF8Buffer(); + return LoadMusicStream(str1.AsPointer()); + } + + public static string SubText(this string input, int position, int length) + { + return input.Substring(position, Math.Min(length, input.Length)); + } + + public static Material GetMaterial(ref Model model, int materialIndex) + { + return model.materials[materialIndex]; + } + + public static Texture2D GetMaterialTexture(ref Model model, int materialIndex, MaterialMapIndex mapIndex) + { + return model.materials[materialIndex].maps[(int)mapIndex].texture; + } + + public static void SetMaterialTexture(ref Model model, int materialIndex, MaterialMapIndex mapIndex, ref Texture2D texture) + { + SetMaterialTexture(&model.materials[materialIndex], mapIndex, texture); + } + + public static void SetMaterialShader(ref Model model, int materialIndex, ref Shader shader) + { + model.materials[materialIndex].shader = shader; + } + } +} diff --git a/Raylib-cs/types/Rectangle.cs b/Raylib-cs/types/Rectangle.cs new file mode 100644 index 0000000..ef0de9b --- /dev/null +++ b/Raylib-cs/types/Rectangle.cs @@ -0,0 +1,29 @@ +using System.Runtime.InteropServices; + +namespace Raylib_cs +{ + /// + /// Rectangle type + /// + [StructLayout(LayoutKind.Sequential)] + public partial struct Rectangle + { + public float x; + public float y; + public float width; + public float height; + + public Rectangle(float x, float y, float width, float height) + { + this.x = x; + this.y = y; + this.width = width; + this.height = height; + } + + public override string ToString() + { + return $"{{X:{x} Y:{y} Width:{width} Height:{height}}}"; + } + } +} diff --git a/Raylib-cs/types/RenderBatch.cs b/Raylib-cs/types/RenderBatch.cs new file mode 100644 index 0000000..df86aee --- /dev/null +++ b/Raylib-cs/types/RenderBatch.cs @@ -0,0 +1,271 @@ +using System.Runtime.InteropServices; + +namespace Raylib_cs +{ + /// + /// RenderBatch type + /// + [StructLayout(LayoutKind.Sequential)] + public unsafe partial 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 + /// + VertexBuffer* vertexBuffer; + + /// + /// Draw calls array, depends on textureId + /// + DrawCall* 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 partial struct VertexBuffer + { + /// + /// Number of elements in the buffer (QUADS) + /// + public int elementCount; + + /// + /// Vertex position (XYZ - 3 components per vertex) (shader-location = 0) + /// + public float* vertices; + + /// + /// Vertex texture coordinates (UV - 2 components per vertex) (shader-location = 1) + /// + public float* texcoords; + + /// + /// Vertex colors (RGBA - 4 components per vertex) (shader-location = 3) + /// + 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 + ///
+ public void* 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 partial 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, + } + + /// + /// Matrix Modes (equivalent to OpenGL) + /// + public enum MatrixMode + { + /// + /// GL_MODELVIEW + /// + MODELVIEW = 0x1700, + + /// + /// GL_PROJECTION + /// + PROJECTION = 0x1701, + + /// + /// GL_TEXTURE + /// + TEXTURE = 0x1702 + } + + /// + /// Primitive assembly draw modes + /// + public enum DrawMode + { + /// + /// GL_LINES + /// + LINES = 0x0001, + + /// + /// GL_TRIANGLES + /// + TRIANGLES = 0x0004, + + /// + /// GL_QUADS + /// + QUADS = 0x0007 + } + + /// + /// Texture parameters (equivalent to OpenGL defines) + /// + public enum TextureFilters + { + /// + /// RL_TEXTURE_FILTER_NEAREST + ///
+ /// GL_NEAREST + ///
+ NEAREST = 0x2600, + + /// + /// RL_TEXTURE_FILTER_LINEAR + ///
+ /// GL_LINEAR + ///
+ LINEAR = 0x2601, + + /// + /// RL_TEXTURE_FILTER_MIP_NEAREST + ///
+ /// GL_NEAREST_MIPMAP_NEAREST + ///
+ MIP_NEAREST = 0x2700, + + /// + /// RL_TEXTURE_FILTER_NEAREST_MIP_LINEAR + ///
+ /// GL_NEAREST_MIPMAP_LINEAR + ///
+ NEAREST_MIP_LINEAR = 0x2702, + + /// + /// RL_TEXTURE_FILTER_LINEAR_MIP_NEAREST + ///
+ /// GL_LINEAR_MIPMAP_NEAREST + ///
+ LINEAR_MIP_NEAREST = 0x2701, + + /// + /// RL_TEXTURE_FILTER_MIP_LINEAR + ///
+ /// GL_LINEAR_MIPMAP_LINEAR + ///
+ MIP_LINEAR = 0x2703, + + /// + /// RL_TEXTURE_FILTER_ANISOTROPIC + ///
+ /// Anisotropic filter (custom identifier) + ///
+ ANISOTROPIC = 0x3000 + } + + /// + /// GL Shader type + /// + public enum ShaderType + { + /// + /// RL_FRAGMENT_SHADER + ///
+ /// GL_FRAGMENT_SHADER + ///
+ FRAGMENT = 0x8B30, + + /// + /// RL_VERTEX_SHADER + ///
+ /// GL_VERTEX_SHADER + ///
+ VERTEX = 0x8B31, + + /// + /// RL_COMPUTE_SHADER + ///
+ /// GL_COMPUTE_SHADER + ///
+ COMPUTE = 0x91b9 + } +} diff --git a/Raylib-cs/types/RenderTexture2D.cs b/Raylib-cs/types/RenderTexture2D.cs new file mode 100644 index 0000000..67a70f0 --- /dev/null +++ b/Raylib-cs/types/RenderTexture2D.cs @@ -0,0 +1,26 @@ +using System.Runtime.InteropServices; + +namespace Raylib_cs +{ + /// + /// RenderTexture2D type, for texture rendering + /// + [StructLayout(LayoutKind.Sequential)] + public partial struct RenderTexture2D + { + /// + /// OpenGL Framebuffer Object (FBO) id + /// + public uint id; + + /// + /// Color buffer attachment texture + /// + public Texture2D texture; + + /// + /// Depth buffer attachment texture + /// + public Texture2D depth; + } +} diff --git a/Raylib-cs/types/Shader.cs b/Raylib-cs/types/Shader.cs new file mode 100644 index 0000000..9592b42 --- /dev/null +++ b/Raylib-cs/types/Shader.cs @@ -0,0 +1,85 @@ +using System; +using System.Runtime.InteropServices; + +namespace Raylib_cs +{ + /// + /// Shader location index + /// + public enum ShaderLocationIndex + { + SHADER_LOC_VERTEX_POSITION = 0, + SHADER_LOC_VERTEX_TEXCOORD01, + SHADER_LOC_VERTEX_TEXCOORD02, + SHADER_LOC_VERTEX_NORMAL, + SHADER_LOC_VERTEX_TANGENT, + SHADER_LOC_VERTEX_COLOR, + SHADER_LOC_MATRIX_MVP, + SHADER_LOC_MATRIX_VIEW, + SHADER_LOC_MATRIX_PROJECTION, + SHADER_LOC_MATRIX_MODEL, + SHADER_LOC_MATRIX_NORMAL, + SHADER_LOC_VECTOR_VIEW, + SHADER_LOC_COLOR_DIFFUSE, + SHADER_LOC_COLOR_SPECULAR, + SHADER_LOC_COLOR_AMBIENT, + SHADER_LOC_MAP_ALBEDO, + SHADER_LOC_MAP_METALNESS, + SHADER_LOC_MAP_NORMAL, + SHADER_LOC_MAP_ROUGHNESS, + SHADER_LOC_MAP_OCCLUSION, + SHADER_LOC_MAP_EMISSION, + SHADER_LOC_MAP_HEIGHT, + SHADER_LOC_MAP_CUBEMAP, + SHADER_LOC_MAP_IRRADIANCE, + SHADER_LOC_MAP_PREFILTER, + SHADER_LOC_MAP_BRDF, + + SHADER_LOC_MAP_DIFFUSE = SHADER_LOC_MAP_ALBEDO, + SHADER_LOC_MAP_SPECULAR = SHADER_LOC_MAP_METALNESS, + } + + /// + /// Shader attribute data types + /// + public enum ShaderAttributeDataType + { + SHADER_ATTRIB_FLOAT = 0, + SHADER_ATTRIB_VEC2, + SHADER_ATTRIB_VEC3, + SHADER_ATTRIB_VEC4 + } + + /// + /// Shader uniform data type + /// + public enum ShaderUniformDataType + { + SHADER_UNIFORM_FLOAT = 0, + SHADER_UNIFORM_VEC2, + SHADER_UNIFORM_VEC3, + SHADER_UNIFORM_VEC4, + SHADER_UNIFORM_INT, + SHADER_UNIFORM_IVEC2, + SHADER_UNIFORM_IVEC3, + SHADER_UNIFORM_IVEC4, + SHADER_UNIFORM_SAMPLER2D + } + + /// + /// Shader type (generic) + /// + [StructLayout(LayoutKind.Sequential)] + public unsafe partial struct Shader + { + /// + /// Shader program id + /// + public uint id; + + /// + /// Shader locations array (MAX_SHADER_LOCATIONS, int *) + /// + public int* locs; + } +} diff --git a/Raylib-cs/types/Texture2D.cs b/Raylib-cs/types/Texture2D.cs new file mode 100644 index 0000000..313ea43 --- /dev/null +++ b/Raylib-cs/types/Texture2D.cs @@ -0,0 +1,137 @@ +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 + ///
+ public enum TextureFilter + { + /// + /// No filter, just pixel aproximation + /// + TEXTURE_FILTER_POINT = 0, + + /// + /// Linear filtering + /// + TEXTURE_FILTER_BILINEAR, + + /// + /// Trilinear filtering (linear with mipmaps) + /// + TEXTURE_FILTER_TRILINEAR, + + /// + /// Anisotropic filtering 4x + /// + TEXTURE_FILTER_ANISOTROPIC_4X, + + /// + /// Anisotropic filtering 8x + /// + TEXTURE_FILTER_ANISOTROPIC_8X, + + /// + /// Anisotropic filtering 16x + /// + TEXTURE_FILTER_ANISOTROPIC_16X, + } + + /// + /// Texture parameters: wrap mode + /// + public enum TextureWrap + { + /// + /// Repeats texture in tiled mode + /// + TEXTURE_WRAP_REPEAT = 0, + + /// + /// Clamps texture to edge pixel in tiled mode + /// + TEXTURE_WRAP_CLAMP, + + /// + /// Mirrors and repeats the texture in tiled mode + /// + TEXTURE_WRAP_MIRROR_REPEAT, + + /// + /// Mirrors and clamps to border the texture in tiled mode + /// + TEXTURE_WRAP_MIRROR_CLAMP + } + + /// + /// Cubemap layouts + /// + public enum CubemapLayout + { + /// + /// Automatically detect layout type + /// + CUBEMAP_LAYOUT_AUTO_DETECT = 0, + + /// + /// Layout is defined by a vertical line with faces + /// + CUBEMAP_LAYOUT_LINE_VERTICAL, + + /// + /// Layout is defined by an horizontal line with faces + /// + CUBEMAP_LAYOUT_LINE_HORIZONTAL, + + /// + /// Layout is defined by a 3x4 cross with cubemap faces + /// + CUBEMAP_LAYOUT_CROSS_THREE_BY_FOUR, + + /// + /// Layout is defined by a 4x3 cross with cubemap faces + /// + CUBEMAP_LAYOUT_CROSS_FOUR_BY_THREE, + + /// + /// Layout is defined by a panorama image (equirectangular map) + /// + CUBEMAP_LAYOUT_PANORAMA + } + + /// + /// Texture2D type
+ /// NOTE: Data stored in GPU memory + ///
+ [StructLayout(LayoutKind.Sequential)] + public partial struct Texture2D + { + /// + /// OpenGL texture id + /// + public uint id; + + /// + /// Texture base width + /// + public int width; + + /// + /// Texture base height + /// + public int height; + + /// + /// Mipmap levels, 1 by default + /// + public int mipmaps; + + /// + /// Data format (PixelFormat type) + /// + public PixelFormat format; + } +} diff --git a/Raylib-cs/types/Transform.cs b/Raylib-cs/types/Transform.cs new file mode 100644 index 0000000..7d53b09 --- /dev/null +++ b/Raylib-cs/types/Transform.cs @@ -0,0 +1,27 @@ +using System.Numerics; +using System.Runtime.InteropServices; + +namespace Raylib_cs +{ + /// + /// Transform, vectex transformation data + /// + [StructLayout(LayoutKind.Sequential)] + public partial struct Transform + { + /// + /// Translation + /// + public Vector3 translation; + + /// + /// Rotation + /// + public Vector4 rotation; + + /// + /// Scale + /// + public Vector3 scale; + } +} diff --git a/Raylib-cs/types/native/CBool.cs b/Raylib-cs/types/native/CBool.cs new file mode 100644 index 0000000..11dd92f --- /dev/null +++ b/Raylib-cs/types/native/CBool.cs @@ -0,0 +1,31 @@ +using System; +using System.Runtime.InteropServices; + +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(); + } + } +} diff --git a/Raylib-cs/types/native/UTF8Buffer.cs b/Raylib-cs/types/native/UTF8Buffer.cs new file mode 100644 index 0000000..49cf205 --- /dev/null +++ b/Raylib-cs/types/native/UTF8Buffer.cs @@ -0,0 +1,64 @@ +using System; +using System.Text; +using System.Runtime.InteropServices; + +namespace Raylib_cs +{ + /// + /// Converts text to a UTF8 buffer for passing to native code.
+ /// Uses ArrayPool to reduce memory allocation. + ///
+ public ref struct UTF8Buffer + { + private IntPtr data; + + public UTF8Buffer(string text) + { + data = Marshal.StringToCoTaskMemUTF8(text); + } + + public unsafe sbyte* AsPointer() + { + return (sbyte*)data.ToPointer(); + } + + public void Dispose() + { + Marshal.FreeCoTaskMem(data); + } + } + + public static class Utf8StringUtils + { + public static UTF8Buffer ToUTF8Buffer(this string text) + { + return new UTF8Buffer(text); + } + + public static byte[] ToUtf8String(this string text) + { + if (text == null) + { + return null; + } + + var length = Encoding.UTF8.GetByteCount(text); + + var byteArray = new byte[length + 1]; + var wrote = Encoding.UTF8.GetBytes(text, 0, text.Length, byteArray, 0); + byteArray[wrote] = 0; + + return byteArray; + } + + public static unsafe string GetUTF8String(sbyte* bytes) + { + return Marshal.PtrToStringUTF8((IntPtr)bytes); + } + + public static byte[] GetUTF8Bytes(this string text) + { + return Encoding.UTF8.GetBytes(text); + } + } +} diff --git a/app.config b/app.config deleted file mode 100755 index af44a75..0000000 --- a/app.config +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file