From 3c81f15df48f89eef5cae5cc1e71441b6de50870 Mon Sep 17 00:00:00 2001 From: msmshazan Date: Mon, 15 Oct 2018 16:24:58 +0530 Subject: [PATCH 1/3] Fix for Pinvoking structs --- Bindings/Bindings.csproj | 2 +- Bindings/Raylib.cs | 76 ++++++++++++++++++++++++++++++++-------- 2 files changed, 62 insertions(+), 16 deletions(-) diff --git a/Bindings/Bindings.csproj b/Bindings/Bindings.csproj index 7127df4..b073098 100644 --- a/Bindings/Bindings.csproj +++ b/Bindings/Bindings.csproj @@ -5,7 +5,7 @@ Debug AnyCPU {A2B3BBC8-3D48-46DD-B3CF-263F554E4474} - Library + Exe Raylib Bindings v4.6.1 diff --git a/Bindings/Raylib.cs b/Bindings/Raylib.cs index 5479185..47d1fe3 100644 --- a/Bindings/Raylib.cs +++ b/Bindings/Raylib.cs @@ -506,24 +506,44 @@ namespace Raylib // Vertex data definning a mesh // NOTE: Data stored in CPU memory (and GPU) - [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] - public struct Mesh + [StructLayout(LayoutKind.Explicit, CharSet = CharSet.Ansi,Size = 128)] + public unsafe struct Mesh { + [FieldOffset(0)] public int vertexCount; + [FieldOffset(4)] public int triangleCount; - public float[] vertices; - public float[] texcoords; - public float[] texcoords2; - public float[] normals; - public float[] tangents; - public byte[] colors; - public ushort[] indices; + [FieldOffset(8)] + public IntPtr vertices; + [FieldOffset(16)] + public IntPtr texcoords; + [FieldOffset(24)] + public IntPtr texcoords2; + [FieldOffset(32)] + public IntPtr normals; + [FieldOffset(40)] + public IntPtr tangents; + [FieldOffset(48)] + public IntPtr colors; + [FieldOffset(56)] + public IntPtr indices; + [FieldOffset(64)] + public IntPtr baseVertices; + [FieldOffset(72)] + public IntPtr baseNormals; + [FieldOffset(80)] + public IntPtr weightBias; + [FieldOffset(88)] + public IntPtr weightId; + + + [FieldOffset(96)] public uint vaoId; - [MarshalAs(UnmanagedType.ByValArray, SizeConst = 7)] // Raylib.PHYSAC_MAX_VERTICES)] - public uint[] vboId; + [FieldOffset(100)] + public fixed uint vboId[7]; } // Shader type (generic) @@ -548,17 +568,43 @@ namespace Raylib public Color color; public float value; } + public unsafe struct FixedMaterials + { + public MaterialMap maps0; + public MaterialMap maps1; + public MaterialMap maps2; + public MaterialMap maps3; + public MaterialMap maps4; + public MaterialMap maps5; + public MaterialMap maps6; + public MaterialMap maps7; + public MaterialMap maps8; + public MaterialMap maps9; + public MaterialMap maps10; + public MaterialMap maps11; + + public ref MaterialMap this[int index] + { + get + { + fixed (MaterialMap* e = &maps0) + return ref e[index]; + } + } + } // Material type (generic) - [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi,Size = 480)] public struct Material { + + + public Shader shader; - [MarshalAs(UnmanagedType.ByValArray, SizeConst = Raylib.MAX_MATERIAL_MAPS)] - public MaterialMap[] maps; + public FixedMaterials maps; - public float[] param; + public IntPtr param; } // Model type From 4267707d51910278a9ce9206ad78581928a3898c Mon Sep 17 00:00:00 2001 From: msmshazan Date: Mon, 15 Oct 2018 16:32:15 +0530 Subject: [PATCH 2/3] small change --- Bindings/Raylib.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Bindings/Raylib.cs b/Bindings/Raylib.cs index 47d1fe3..46e9cf1 100644 --- a/Bindings/Raylib.cs +++ b/Bindings/Raylib.cs @@ -568,7 +568,7 @@ namespace Raylib public Color color; public float value; } - public unsafe struct FixedMaterials + public unsafe struct _MaterialMap_e_FixedBuffer { public MaterialMap maps0; @@ -602,7 +602,7 @@ namespace Raylib public Shader shader; - public FixedMaterials maps; + public _MaterialMap_e_FixedBuffer maps; public IntPtr param; } From f9b3233c69398abaa37bd55819c37b64b12a1a28 Mon Sep 17 00:00:00 2001 From: msmshazan Date: Mon, 15 Oct 2018 16:50:44 +0530 Subject: [PATCH 3/3] Some fixes --- Bindings/Raylib.cs | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/Bindings/Raylib.cs b/Bindings/Raylib.cs index 46e9cf1..e0683cf 100644 --- a/Bindings/Raylib.cs +++ b/Bindings/Raylib.cs @@ -506,43 +506,28 @@ namespace Raylib // Vertex data definning a mesh // NOTE: Data stored in CPU memory (and GPU) - [StructLayout(LayoutKind.Explicit, CharSet = CharSet.Ansi,Size = 128)] + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] public unsafe struct Mesh { - [FieldOffset(0)] public int vertexCount; - [FieldOffset(4)] public int triangleCount; - [FieldOffset(8)] public IntPtr vertices; - [FieldOffset(16)] public IntPtr texcoords; - [FieldOffset(24)] public IntPtr texcoords2; - [FieldOffset(32)] public IntPtr normals; - [FieldOffset(40)] public IntPtr tangents; - [FieldOffset(48)] public IntPtr colors; - [FieldOffset(56)] public IntPtr indices; - [FieldOffset(64)] public IntPtr baseVertices; - [FieldOffset(72)] public IntPtr baseNormals; - [FieldOffset(80)] public IntPtr weightBias; - [FieldOffset(88)] public IntPtr weightId; - [FieldOffset(96)] public uint vaoId; - [FieldOffset(100)] public fixed uint vboId[7]; } @@ -594,7 +579,7 @@ namespace Raylib } } // Material type (generic) - [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi,Size = 480)] + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] public struct Material {