wasm support

This commit is contained in:
Braedon Lewis 2023-12-13 10:28:46 -05:00
parent 618975a00b
commit fe7f9d32e3
51 changed files with 2323 additions and 697 deletions

View file

@ -4,7 +4,7 @@
BeefLang bindings for **Raylib 5.0**.
> **Note**: OS is limited to Windows right now, I see no reason why this wouldn't work on other platforms, though. I guess only one way to find out.
> **Note**: OS is limited to Windows & WebAssembly right now, I see no reason why this wouldn't work on other platforms, though. I guess only one way to find out.
## Example
```cs
@ -21,8 +21,8 @@ class Program
InitWindow(800, 600, scope $"Raylib Beef {RAYLIB_VERSION_MAJOR}.{RAYLIB_VERSION_MINOR}.{RAYLIB_VERSION_PATCH}");
InitAudioDevice();
var beefMain = Color(165, 47, 78, 255);
var beefOutline = Color(243, 157, 157, 255);
let beefMain = Color(165, 47, 78, 255);
let beefOutline = Color(243, 157, 157, 255);
while (!WindowShouldClose())
{

View file

@ -1,5 +1,6 @@
using Newtonsoft.Json;
using System;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
@ -77,39 +78,61 @@ namespace RaylibBeefGenerator
AppendLine("");
}
for (var i = 0; i < api.Functions.Count; i++)
{
var func = api.Functions[i];
var functionsWStructs = new List<Function>();
var functionsWOStructs = new List<Function>();
foreach (var func in api.Functions)
{
var addWO = true;
foreach (var param in func.Params)
{
if (api.Structs.Find(c => c.Name == param.Type) != null || api.Aliases.Find(c => c.Name == param.Type) != null)
{
addWO = false;
break;
}
}
if (addWO)
functionsWOStructs.Add(func);
else
functionsWStructs.Add(func);
}
// Platform agnostic methods (kinda)
foreach (var func in functionsWOStructs)
{
AppendLine($"/// {func.Description}");
// AppendLine($"[Import(Raylib.RaylibBin), CallingConvention(.Cdecl), LinkName(\"{func.Name}\")]");
AppendLine("[CLink]");
AppendLine($"public static extern {func.ReturnType.ConvertTypes()} {func.Name.ConvertName()}({Parameters2String(func.Params)});");
AppendLine($"public static extern {func.ReturnType.ConvertTypes()} {func.Name.ConvertName()}({Parameters2String(func.Params, api)});");
AppendLine("");
}
AppendLine($"#if !BF_PLATFORM_WASM", true);
AppendLine("");
/*
var char8Params = new List<Param>();
var funcHasChar8 = false;
for (var p = 0; p < func.Params.Count; p++)
{
var param = func.Params[p];
if (param.Type.ConvertTypes() == "char8 *")
{
param.Type = "String";
funcHasChar8 = true;
}
char8Params.Add(param);
}
if (funcHasChar8)
foreach (var func in functionsWStructs)
{
AppendLine($"/// {func.Description}");
AppendLine($"[Import(\"{ImportLib}\"), CallingConvention(.Cdecl), LinkName(\"{func.Name}\")]");
AppendLine($"public static extern void {func.Name.ConvertName()}({Parameters2String(char8Params)});");
// AppendLine($"[Import(Raylib.RaylibBin), CallingConvention(.Cdecl), LinkName(\"{func.Name}\")]");
AppendLine("[CLink]");
AppendLine($"public static extern {func.ReturnType.ConvertTypes()} {func.Name.ConvertName()}({Parameters2String(func.Params, api)});");
AppendLine("");
}
*/
AppendLine($"#else", true);
AppendLine("");
// Emscripten
foreach (var func in functionsWStructs)
{
AppendLine($"/// {func.Description}");
// AppendLine($"[Import(Raylib.RaylibBin), CallingConvention(.Cdecl), LinkName(\"{func.Name}\")]");
AppendLine("[CLink]");
AppendLine($"public static extern {func.ReturnType.ConvertTypes()} {func.Name.ConvertName()}({Parameters2String(func.Params, api, true)});");
AppendLine("");
}
AppendLine($"#endif", true);
AppendLine("");
@ -118,7 +141,7 @@ namespace RaylibBeefGenerator
var callback = api.Callbacks[i];
if (!string.IsNullOrEmpty(callback.Description)) AppendLine($"/// {callback.Description}");
AppendLine($"public function {callback.ReturnType.ConvertTypes()} {callback.Name.ConvertName()}({callback.Params.Parameters2String()});");
AppendLine($"public function {callback.ReturnType.ConvertTypes()} {callback.Name.ConvertName()}({ callback.Params.Parameters2String(api)});");
AppendLine("");
}
@ -144,6 +167,7 @@ namespace RaylibBeefGenerator
UniversalHeader();
AppendLine($"[AllowDuplicates]");
AppendLine($"/// {@enum.Description}");
AppendLine($"public enum {@enum.Name} : c_int");
AppendLine("{");
@ -191,8 +215,13 @@ namespace RaylibBeefGenerator
{
var field = structu.Fields[i];
// This is like the only thing that is hardcoded, and that saddens me.
if (field.Type == "rAudioProcessor *" || field.Type == "rAudioBuffer *" || field.Type.StartsWith("#if") || field.Type == "#endif")
// field.Type == "rAudioProcessor *" || field.Type == "rAudioBuffer *"
if (field.Type[^1] == '*') // Is Pointer
{
if (api.Structs.Find(c => c.Name == field.Type.Remove(field.Type.Length - 2, 2)) == null)
field.Type = "void*";
}
else if (field.Type.StartsWith("#if") || field.Type == "#endif")
{
field.Type = "void*";
}
@ -233,7 +262,7 @@ namespace RaylibBeefGenerator
WriteToFile($"{structu.Name}");
}
public static string Parameters2String(this List<Param> @params)
public static string Parameters2String(this List<Param> @params, RaylibBeefGenerator.Root api, bool emscripten = false)
{
var paramStr = string.Empty;
@ -243,6 +272,13 @@ namespace RaylibBeefGenerator
var t = ConvertTypes(param.Type);
if (t == "...") { paramStr = paramStr[..^2]; continue; }; // Dunno what this is about, or how to convert it.
if (emscripten)
{
// Emscripten REALLY likes passing structs by reference
if (api.Structs.Find(c => c.Name == param.Type) != null || api.Aliases.Find(c => c.Name == param.Type) != null)
paramStr += "in ";
}
paramStr += $"{t} {param.Name.ConvertName()}";
if (p < @params.Count - 1)
paramStr += ", ";
@ -339,13 +375,16 @@ namespace RaylibBeefGenerator
return Regex.Replace(original, pattern, replacement);
}
public static void AppendLine(string content)
public static void AppendLine(string content, bool ignoreTabs = false)
{
var output = string.Empty;
if (!ignoreTabs)
{
for (int i = 0; i < TabIndex; i++)
{
output += "\t";
}
}
output += content;
OutputString.AppendLine(output);
}

View file

@ -12,11 +12,19 @@ CLibType = "DynamicDebug"
LibPaths = ["$(ProjectDir)\\libs\\libs_x64\\raylibdll.lib"]
PostBuildCmds = ["CopyToDependents(\"$(ProjectDir)/libs/libs_x64/*.dll\")"]
[Configs.Debug.wasm32]
OtherLinkFlags = "$(LinkFlags) -s USE_GLFW=3"
LibPaths = ["$(ProjectDir)\\libs\\wasm\\libraylib.a"]
[Configs.Release.Win64]
CLibType = "Dynamic"
LibPaths = ["$(ProjectDir)\\libs\\libs_x64\\raylibdll.lib"]
PostBuildCmds = ["CopyToDependents(\"$(ProjectDir)/libs/libs_x64/*.dll\")"]
[Configs.Release.wasm32]
OtherLinkFlags = "$(LinkFlags) -s USE_GLFW=3"
LibPaths = ["$(ProjectDir)\\libs\\wasm\\libraylib.a"]
[Configs.Paranoid.Win64]
PostBuildCmds = ["CopyToDependents(\"$(ProjectDir)/libs/libs_x64/*.dll\")"]

View file

@ -3,3 +3,8 @@ Projects = {raylib-beef = {Path = "."}, example = {Path = "example"}}
[Workspace]
StartupProject = "example"
[Configs.Debug.wasm32]
AllocType = "CRT"
EnableObjectDebugFlags = false
EmitObjectAccessCheck = false

View file

@ -0,0 +1,2 @@
cd ../build/Debug_wasm32/example
python -m http.server

View file

@ -6,37 +6,74 @@ namespace example;
class Program
{
public static int Main(String[] args)
private const let ColBeefMain = Color(165, 47, 78, 255);
private const let ColBeefOutline = Color(243, 157, 157, 255);
#if BF_PLATFORM_WASM
private function void em_callback_func();
[CLink, CallingConvention(.Stdcall)]
private static extern void emscripten_set_main_loop(em_callback_func func, int32 fps, int32 simulateInfinteLoop);
[CLink, CallingConvention(.Stdcall)]
private static extern int32 emscripten_set_main_loop_timing(int32 mode, int32 value);
[CLink, CallingConvention(.Stdcall)]
private static extern double emscripten_get_now();
private static void EmscriptenMainLoop()
{
InitWindow(800, 600, scope $"Raylib Beef {RAYLIB_VERSION_MAJOR}.{RAYLIB_VERSION_MINOR}.{RAYLIB_VERSION_PATCH}");
InitAudioDevice();
Update();
}
#endif
var beefMain = Color(165, 47, 78, 255);
var beefOutline = Color(243, 157, 157, 255);
while (!WindowShouldClose())
private static void Update()
{
BeginDrawing();
ClearBackground(RAYWHITE);
DrawRectangle(GetScreenWidth() / 2 - 128, GetScreenHeight() / 2 - 128, 256, 256, beefOutline);
DrawRectangle(GetScreenWidth() / 2 - 112, GetScreenHeight() / 2 - 112, 224, 224, beefMain);
void DrawPlatform(char8* text)
=> DrawText(text, GetScreenWidth() / 2 - (MeasureText(text, 50) / 2), 40, 50, ColBeefOutline);
DrawText("raylib", GetScreenWidth() / 2 - 44, GetScreenHeight() / 2, 50, beefOutline);
DrawText("beef", GetScreenWidth() / 2 - 62, GetScreenHeight() / 2 + 46, 50, beefOutline);
#if BF_PLATFORM_WASM
DrawPlatform("webassembly");
#else
DrawPlatform("windows");
#endif
DrawRectangle(GetScreenWidth() / 2 + 54, GetScreenHeight() / 2 + 54, 42, 42, beefOutline);
DrawRectangle(GetScreenWidth() / 2 - 128, GetScreenHeight() / 2 - 128, 256, 256, ColBeefOutline);
DrawRectangle(GetScreenWidth() / 2 - 112, GetScreenHeight() / 2 - 112, 224, 224, ColBeefMain);
DrawText("raylib", GetScreenWidth() / 2 - 44, GetScreenHeight() / 2, 50, ColBeefOutline);
DrawText("beef", GetScreenWidth() / 2 - 62, GetScreenHeight() / 2 + 46, 50, ColBeefOutline);
DrawRectangle(GetScreenWidth() / 2 + 54, GetScreenHeight() / 2 + 54, 42, 42, ColBeefOutline);
DrawRectangle(GetScreenWidth() / 2 + 62, GetScreenHeight() / 2 + 62, 26, 26, RAYWHITE);
DrawCircle(GetMouseX(), GetMouseY(), 20, beefOutline);
DrawCircle(GetMouseX(), GetMouseY(), 8, beefMain);
DrawCircle(GetMouseX(), GetMouseY(), 20, ColBeefOutline);
DrawCircle(GetMouseX(), GetMouseY(), 8, ColBeefMain);
DrawFPS(20, 20);
EndDrawing();
}
public static int Main(String[] args)
{
InitWindow(800, 600, scope $"Raylib Beef {RAYLIB_VERSION_MAJOR}.{RAYLIB_VERSION_MINOR}.{RAYLIB_VERSION_PATCH}");
InitAudioDevice();
#if BF_PLATFORM_WASM
emscripten_set_main_loop(=> EmscriptenMainLoop, 0, 1);
#else
while (!WindowShouldClose())
{
Update();
}
#endif
CloseAudioDevice();
CloseWindow();

Binary file not shown.

View file

@ -3,6 +3,7 @@ using System.Interop;
namespace RaylibBeef;
[AllowDuplicates]
/// Color blending modes (pre-defined)
public enum BlendMode : c_int
{

View file

@ -3,6 +3,7 @@ using System.Interop;
namespace RaylibBeef;
[AllowDuplicates]
/// Camera system modes
public enum CameraMode : c_int
{

View file

@ -3,6 +3,7 @@ using System.Interop;
namespace RaylibBeef;
[AllowDuplicates]
/// Camera projection
public enum CameraProjection : c_int
{

View file

@ -3,6 +3,7 @@ using System.Interop;
namespace RaylibBeef;
[AllowDuplicates]
/// System/Window config flags
public enum ConfigFlags : c_int
{

View file

@ -3,6 +3,7 @@ using System.Interop;
namespace RaylibBeef;
[AllowDuplicates]
/// Cubemap layouts
public enum CubemapLayout : c_int
{

View file

@ -13,9 +13,9 @@ public struct FilePathList
public int32 count;
/// Filepaths entries
public char8 ** paths;
public void* paths;
public this(int32 capacity, int32 count, char8 ** paths)
public this(int32 capacity, int32 count, void* paths)
{
this.capacity = capacity;
this.count = count;

View file

@ -3,6 +3,7 @@ using System.Interop;
namespace RaylibBeef;
[AllowDuplicates]
/// Font type, defines generation method
public enum FontType : c_int
{

View file

@ -3,6 +3,7 @@ using System.Interop;
namespace RaylibBeef;
[AllowDuplicates]
/// Gamepad axis
public enum GamepadAxis : c_int
{

View file

@ -3,6 +3,7 @@ using System.Interop;
namespace RaylibBeef;
[AllowDuplicates]
/// Gamepad buttons
public enum GamepadButton : c_int
{

View file

@ -3,6 +3,7 @@ using System.Interop;
namespace RaylibBeef;
[AllowDuplicates]
/// Gesture
public enum Gesture : c_int
{

View file

@ -7,7 +7,7 @@ namespace RaylibBeef;
public struct Image
{
/// Image raw data
public void * data;
public void* data;
/// Image base width
public int32 width;
@ -21,7 +21,7 @@ public struct Image
/// Data format (PixelFormat type)
public int32 format;
public this(void * data, int32 width, int32 height, int32 mipmaps, int32 format)
public this(void* data, int32 width, int32 height, int32 mipmaps, int32 format)
{
this.data = data;
this.width = width;

View file

@ -3,6 +3,7 @@ using System.Interop;
namespace RaylibBeef;
[AllowDuplicates]
/// Keyboard keys (US keyboard layout)
public enum KeyboardKey : c_int
{

View file

@ -3,6 +3,7 @@ using System.Interop;
namespace RaylibBeef;
[AllowDuplicates]
/// Material map index
public enum MaterialMapIndex : c_int
{

View file

@ -13,45 +13,45 @@ public struct Mesh
public int32 triangleCount;
/// Vertex position (XYZ - 3 components per vertex) (shader-location = 0)
public float * vertices;
public void* vertices;
/// Vertex texture coordinates (UV - 2 components per vertex) (shader-location = 1)
public float * texcoords;
public void* texcoords;
/// Vertex texture second coordinates (UV - 2 components per vertex) (shader-location = 5)
public float * texcoords2;
public void* texcoords2;
/// Vertex normals (XYZ - 3 components per vertex) (shader-location = 2)
public float * normals;
public void* normals;
/// Vertex tangents (XYZW - 4 components per vertex) (shader-location = 4)
public float * tangents;
public void* tangents;
/// Vertex colors (RGBA - 4 components per vertex) (shader-location = 3)
public char8 * colors;
public void* colors;
/// Vertex indices (in case vertex data comes indexed)
public uint16 * indices;
public void* indices;
/// Animated vertex positions (after bones transformations)
public float * animVertices;
public void* animVertices;
/// Animated normals (after bones transformations)
public float * animNormals;
public void* animNormals;
/// Vertex bone ids, max 255 bone ids, up to 4 bones influence by vertex (skinning)
public char8 * boneIds;
public void* boneIds;
/// Vertex bone weight, up to 4 bones influence by vertex (skinning)
public float * boneWeights;
public void* boneWeights;
/// OpenGL Vertex Array Object id
public int32 vaoId;
/// OpenGL Vertex Buffer Objects id (default vertex data)
public int32 * vboId;
public void* vboId;
public this(int32 vertexCount, int32 triangleCount, float * vertices, float * texcoords, float * texcoords2, float * normals, float * tangents, char8 * colors, uint16 * indices, float * animVertices, float * animNormals, char8 * boneIds, float * boneWeights, int32 vaoId, int32 * vboId)
public this(int32 vertexCount, int32 triangleCount, void* vertices, void* texcoords, void* texcoords2, void* normals, void* tangents, void* colors, void* indices, void* animVertices, void* animNormals, void* boneIds, void* boneWeights, int32 vaoId, void* vboId)
{
this.vertexCount = vertexCount;
this.triangleCount = triangleCount;

View file

@ -22,7 +22,7 @@ public struct Model
public Material * materials;
/// Mesh material number
public int32 * meshMaterial;
public void* meshMaterial;
/// Number of bones
public int32 boneCount;
@ -33,7 +33,7 @@ public struct Model
/// Bones base transformation (pose)
public Transform * bindPose;
public this(Matrix transform, int32 meshCount, int32 materialCount, Mesh * meshes, Material * materials, int32 * meshMaterial, int32 boneCount, BoneInfo * bones, Transform * bindPose)
public this(Matrix transform, int32 meshCount, int32 materialCount, Mesh * meshes, Material * materials, void* meshMaterial, int32 boneCount, BoneInfo * bones, Transform * bindPose)
{
this.transform = transform;
this.meshCount = meshCount;

View file

@ -16,12 +16,12 @@ public struct ModelAnimation
public BoneInfo * bones;
/// Poses array by frame
public Transform ** framePoses;
public void* framePoses;
/// Animation name
public char8[32] name;
public this(int32 boneCount, int32 frameCount, BoneInfo * bones, Transform ** framePoses, char8[32] name)
public this(int32 boneCount, int32 frameCount, BoneInfo * bones, void* framePoses, char8[32] name)
{
this.boneCount = boneCount;
this.frameCount = frameCount;

View file

@ -3,6 +3,7 @@ using System.Interop;
namespace RaylibBeef;
[AllowDuplicates]
/// Mouse buttons
public enum MouseButton : c_int
{

View file

@ -3,6 +3,7 @@ using System.Interop;
namespace RaylibBeef;
[AllowDuplicates]
/// Mouse cursor
public enum MouseCursor : c_int
{

View file

@ -19,9 +19,9 @@ public struct Music
public int32 ctxType;
/// Audio context data, depends on type
public void * ctxData;
public void* ctxData;
public this(AudioStream stream, int32 frameCount, bool looping, int32 ctxType, void * ctxData)
public this(AudioStream stream, int32 frameCount, bool looping, int32 ctxType, void* ctxData)
{
this.stream = stream;
this.frameCount = frameCount;

View file

@ -3,6 +3,7 @@ using System.Interop;
namespace RaylibBeef;
[AllowDuplicates]
/// N-patch layout
public enum NPatchLayout : c_int
{

View file

@ -3,6 +3,7 @@ using System.Interop;
namespace RaylibBeef;
[AllowDuplicates]
/// Pixel formats
public enum PixelFormat : c_int
{

File diff suppressed because it is too large Load diff

View file

@ -45,6 +45,72 @@ public static class Raymath
[CLink]
public static extern Vector2 Vector2One();
///
[CLink]
public static extern Vector3 Vector3Zero();
///
[CLink]
public static extern Vector3 Vector3One();
///
[CLink]
public static extern float Vector3Length(Vector3 v);
///
[CLink]
public static extern float Vector3LengthSqr(Vector3 v);
///
[CLink]
public static extern void Vector3OrthoNormalize(Vector3 * v1, Vector3 * v2);
///
[CLink]
public static extern Matrix MatrixIdentity();
///
[CLink]
public static extern Matrix MatrixTranslate(float x, float y, float z);
///
[CLink]
public static extern Matrix MatrixRotateX(float angle);
///
[CLink]
public static extern Matrix MatrixRotateY(float angle);
///
[CLink]
public static extern Matrix MatrixRotateZ(float angle);
///
[CLink]
public static extern Matrix MatrixScale(float x, float y, float z);
///
[CLink]
public static extern Matrix MatrixFrustum(double left, double right, double bottom, double top, double near, double far);
///
[CLink]
public static extern Matrix MatrixPerspective(double fovY, double aspect, double nearPlane, double farPlane);
///
[CLink]
public static extern Matrix MatrixOrtho(double left, double right, double bottom, double top, double nearPlane, double farPlane);
///
[CLink]
public static extern Quaternion QuaternionIdentity();
///
[CLink]
public static extern Quaternion QuaternionFromEuler(float pitch, float yaw, float roll);
#if !BF_PLATFORM_WASM
///
[CLink]
public static extern Vector2 Vector2Add(Vector2 v1, Vector2 v2);
@ -145,14 +211,6 @@ public static class Raymath
[CLink]
public static extern int32 Vector2Equals(Vector2 p, Vector2 q);
///
[CLink]
public static extern Vector3 Vector3Zero();
///
[CLink]
public static extern Vector3 Vector3One();
///
[CLink]
public static extern Vector3 Vector3Add(Vector3 v1, Vector3 v2);
@ -185,14 +243,6 @@ public static class Raymath
[CLink]
public static extern Vector3 Vector3Perpendicular(Vector3 v);
///
[CLink]
public static extern float Vector3Length(Vector3 v);
///
[CLink]
public static extern float Vector3LengthSqr(Vector3 v);
///
[CLink]
public static extern float Vector3DotProduct(Vector3 v1, Vector3 v2);
@ -229,10 +279,6 @@ public static class Raymath
[CLink]
public static extern Vector3 Vector3Reject(Vector3 v1, Vector3 v2);
///
[CLink]
public static extern void Vector3OrthoNormalize(Vector3 * v1, Vector3 * v2);
///
[CLink]
public static extern Vector3 Vector3Transform(Vector3 v, Matrix mat);
@ -309,10 +355,6 @@ public static class Raymath
[CLink]
public static extern Matrix MatrixInvert(Matrix mat);
///
[CLink]
public static extern Matrix MatrixIdentity();
///
[CLink]
public static extern Matrix MatrixAdd(Matrix left, Matrix right);
@ -325,26 +367,10 @@ public static class Raymath
[CLink]
public static extern Matrix MatrixMultiply(Matrix left, Matrix right);
///
[CLink]
public static extern Matrix MatrixTranslate(float x, float y, float z);
///
[CLink]
public static extern Matrix MatrixRotate(Vector3 axis, float angle);
///
[CLink]
public static extern Matrix MatrixRotateX(float angle);
///
[CLink]
public static extern Matrix MatrixRotateY(float angle);
///
[CLink]
public static extern Matrix MatrixRotateZ(float angle);
///
[CLink]
public static extern Matrix MatrixRotateXYZ(Vector3 angle);
@ -353,22 +379,6 @@ public static class Raymath
[CLink]
public static extern Matrix MatrixRotateZYX(Vector3 angle);
///
[CLink]
public static extern Matrix MatrixScale(float x, float y, float z);
///
[CLink]
public static extern Matrix MatrixFrustum(double left, double right, double bottom, double top, double near, double far);
///
[CLink]
public static extern Matrix MatrixPerspective(double fovY, double aspect, double nearPlane, double farPlane);
///
[CLink]
public static extern Matrix MatrixOrtho(double left, double right, double bottom, double top, double nearPlane, double farPlane);
///
[CLink]
public static extern Matrix MatrixLookAt(Vector3 eye, Vector3 target, Vector3 up);
@ -393,10 +403,6 @@ public static class Raymath
[CLink]
public static extern Quaternion QuaternionSubtractValue(Quaternion q, float sub);
///
[CLink]
public static extern Quaternion QuaternionIdentity();
///
[CLink]
public static extern float QuaternionLength(Quaternion q);
@ -453,10 +459,6 @@ public static class Raymath
[CLink]
public static extern void QuaternionToAxisAngle(Quaternion q, Vector3 * outAxis, float * outAngle);
///
[CLink]
public static extern Quaternion QuaternionFromEuler(float pitch, float yaw, float roll);
///
[CLink]
public static extern Vector3 QuaternionToEuler(Quaternion q);
@ -469,5 +471,368 @@ public static class Raymath
[CLink]
public static extern int32 QuaternionEquals(Quaternion p, Quaternion q);
#else
///
[CLink]
public static extern Vector2 Vector2Add(in Vector2 v1, in Vector2 v2);
///
[CLink]
public static extern Vector2 Vector2AddValue(in Vector2 v, float add);
///
[CLink]
public static extern Vector2 Vector2Subtract(in Vector2 v1, in Vector2 v2);
///
[CLink]
public static extern Vector2 Vector2SubtractValue(in Vector2 v, float sub);
///
[CLink]
public static extern float Vector2Length(in Vector2 v);
///
[CLink]
public static extern float Vector2LengthSqr(in Vector2 v);
///
[CLink]
public static extern float Vector2DotProduct(in Vector2 v1, in Vector2 v2);
///
[CLink]
public static extern float Vector2Distance(in Vector2 v1, in Vector2 v2);
///
[CLink]
public static extern float Vector2DistanceSqr(in Vector2 v1, in Vector2 v2);
///
[CLink]
public static extern float Vector2Angle(in Vector2 v1, in Vector2 v2);
///
[CLink]
public static extern float Vector2LineAngle(in Vector2 start, in Vector2 end);
///
[CLink]
public static extern Vector2 Vector2Scale(in Vector2 v, float scale);
///
[CLink]
public static extern Vector2 Vector2Multiply(in Vector2 v1, in Vector2 v2);
///
[CLink]
public static extern Vector2 Vector2Negate(in Vector2 v);
///
[CLink]
public static extern Vector2 Vector2Divide(in Vector2 v1, in Vector2 v2);
///
[CLink]
public static extern Vector2 Vector2Normalize(in Vector2 v);
///
[CLink]
public static extern Vector2 Vector2Transform(in Vector2 v, in Matrix mat);
///
[CLink]
public static extern Vector2 Vector2Lerp(in Vector2 v1, in Vector2 v2, float amount);
///
[CLink]
public static extern Vector2 Vector2Reflect(in Vector2 v, in Vector2 normal);
///
[CLink]
public static extern Vector2 Vector2Rotate(in Vector2 v, float angle);
///
[CLink]
public static extern Vector2 Vector2MoveTowards(in Vector2 v, in Vector2 target, float maxDistance);
///
[CLink]
public static extern Vector2 Vector2Invert(in Vector2 v);
///
[CLink]
public static extern Vector2 Vector2Clamp(in Vector2 v, in Vector2 min, in Vector2 max);
///
[CLink]
public static extern Vector2 Vector2ClampValue(in Vector2 v, float min, float max);
///
[CLink]
public static extern int32 Vector2Equals(in Vector2 p, in Vector2 q);
///
[CLink]
public static extern Vector3 Vector3Add(in Vector3 v1, in Vector3 v2);
///
[CLink]
public static extern Vector3 Vector3AddValue(in Vector3 v, float add);
///
[CLink]
public static extern Vector3 Vector3Subtract(in Vector3 v1, in Vector3 v2);
///
[CLink]
public static extern Vector3 Vector3SubtractValue(in Vector3 v, float sub);
///
[CLink]
public static extern Vector3 Vector3Scale(in Vector3 v, float scalar);
///
[CLink]
public static extern Vector3 Vector3Multiply(in Vector3 v1, in Vector3 v2);
///
[CLink]
public static extern Vector3 Vector3CrossProduct(in Vector3 v1, in Vector3 v2);
///
[CLink]
public static extern Vector3 Vector3Perpendicular(in Vector3 v);
///
[CLink]
public static extern float Vector3DotProduct(in Vector3 v1, in Vector3 v2);
///
[CLink]
public static extern float Vector3Distance(in Vector3 v1, in Vector3 v2);
///
[CLink]
public static extern float Vector3DistanceSqr(in Vector3 v1, in Vector3 v2);
///
[CLink]
public static extern float Vector3Angle(in Vector3 v1, in Vector3 v2);
///
[CLink]
public static extern Vector3 Vector3Negate(in Vector3 v);
///
[CLink]
public static extern Vector3 Vector3Divide(in Vector3 v1, in Vector3 v2);
///
[CLink]
public static extern Vector3 Vector3Normalize(in Vector3 v);
///
[CLink]
public static extern Vector3 Vector3Project(in Vector3 v1, in Vector3 v2);
///
[CLink]
public static extern Vector3 Vector3Reject(in Vector3 v1, in Vector3 v2);
///
[CLink]
public static extern Vector3 Vector3Transform(in Vector3 v, in Matrix mat);
///
[CLink]
public static extern Vector3 Vector3RotateByQuaternion(in Vector3 v, in Quaternion q);
///
[CLink]
public static extern Vector3 Vector3RotateByAxisAngle(in Vector3 v, in Vector3 axis, float angle);
///
[CLink]
public static extern Vector3 Vector3Lerp(in Vector3 v1, in Vector3 v2, float amount);
///
[CLink]
public static extern Vector3 Vector3Reflect(in Vector3 v, in Vector3 normal);
///
[CLink]
public static extern Vector3 Vector3Min(in Vector3 v1, in Vector3 v2);
///
[CLink]
public static extern Vector3 Vector3Max(in Vector3 v1, in Vector3 v2);
///
[CLink]
public static extern Vector3 Vector3Barycenter(in Vector3 p, in Vector3 a, in Vector3 b, in Vector3 c);
///
[CLink]
public static extern Vector3 Vector3Unproject(in Vector3 source, in Matrix projection, in Matrix view);
///
[CLink]
public static extern float3 Vector3ToFloatV(in Vector3 v);
///
[CLink]
public static extern Vector3 Vector3Invert(in Vector3 v);
///
[CLink]
public static extern Vector3 Vector3Clamp(in Vector3 v, in Vector3 min, in Vector3 max);
///
[CLink]
public static extern Vector3 Vector3ClampValue(in Vector3 v, float min, float max);
///
[CLink]
public static extern int32 Vector3Equals(in Vector3 p, in Vector3 q);
///
[CLink]
public static extern Vector3 Vector3Refract(in Vector3 v, in Vector3 n, float r);
///
[CLink]
public static extern float MatrixDeterminant(in Matrix mat);
///
[CLink]
public static extern float MatrixTrace(in Matrix mat);
///
[CLink]
public static extern Matrix MatrixTranspose(in Matrix mat);
///
[CLink]
public static extern Matrix MatrixInvert(in Matrix mat);
///
[CLink]
public static extern Matrix MatrixAdd(in Matrix left, in Matrix right);
///
[CLink]
public static extern Matrix MatrixSubtract(in Matrix left, in Matrix right);
///
[CLink]
public static extern Matrix MatrixMultiply(in Matrix left, in Matrix right);
///
[CLink]
public static extern Matrix MatrixRotate(in Vector3 axis, float angle);
///
[CLink]
public static extern Matrix MatrixRotateXYZ(in Vector3 angle);
///
[CLink]
public static extern Matrix MatrixRotateZYX(in Vector3 angle);
///
[CLink]
public static extern Matrix MatrixLookAt(in Vector3 eye, in Vector3 target, in Vector3 up);
///
[CLink]
public static extern float16 MatrixToFloatV(in Matrix mat);
///
[CLink]
public static extern Quaternion QuaternionAdd(in Quaternion q1, in Quaternion q2);
///
[CLink]
public static extern Quaternion QuaternionAddValue(in Quaternion q, float add);
///
[CLink]
public static extern Quaternion QuaternionSubtract(in Quaternion q1, in Quaternion q2);
///
[CLink]
public static extern Quaternion QuaternionSubtractValue(in Quaternion q, float sub);
///
[CLink]
public static extern float QuaternionLength(in Quaternion q);
///
[CLink]
public static extern Quaternion QuaternionNormalize(in Quaternion q);
///
[CLink]
public static extern Quaternion QuaternionInvert(in Quaternion q);
///
[CLink]
public static extern Quaternion QuaternionMultiply(in Quaternion q1, in Quaternion q2);
///
[CLink]
public static extern Quaternion QuaternionScale(in Quaternion q, float mul);
///
[CLink]
public static extern Quaternion QuaternionDivide(in Quaternion q1, in Quaternion q2);
///
[CLink]
public static extern Quaternion QuaternionLerp(in Quaternion q1, in Quaternion q2, float amount);
///
[CLink]
public static extern Quaternion QuaternionNlerp(in Quaternion q1, in Quaternion q2, float amount);
///
[CLink]
public static extern Quaternion QuaternionSlerp(in Quaternion q1, in Quaternion q2, float amount);
///
[CLink]
public static extern Quaternion QuaternionFromVector3ToVector3(in Vector3 from, in Vector3 to);
///
[CLink]
public static extern Quaternion QuaternionFromMatrix(in Matrix mat);
///
[CLink]
public static extern Matrix QuaternionToMatrix(in Quaternion q);
///
[CLink]
public static extern Quaternion QuaternionFromAxisAngle(in Vector3 axis, float angle);
///
[CLink]
public static extern void QuaternionToAxisAngle(in Quaternion q, Vector3 * outAxis, float * outAngle);
///
[CLink]
public static extern Vector3 QuaternionToEuler(in Quaternion q);
///
[CLink]
public static extern Quaternion QuaternionTransform(in Quaternion q, in Matrix mat);
///
[CLink]
public static extern int32 QuaternionEquals(in Quaternion p, in Quaternion q);
#endif
}

View file

@ -558,10 +558,6 @@ public static class Rlgl
[CLink]
public static extern rlRenderBatch rlLoadRenderBatch(int32 numBuffers, int32 bufferElements);
/// Unload render batch system
[CLink]
public static extern void rlUnloadRenderBatch(rlRenderBatch batch);
/// Draw render batch data (Update->Draw->Reset)
[CLink]
public static extern void rlDrawRenderBatch(rlRenderBatch * batch);
@ -722,10 +718,6 @@ public static class Rlgl
[CLink]
public static extern void rlSetUniform(int32 locIndex, void * value, int32 uniformType, int32 count);
/// Set shader value matrix
[CLink]
public static extern void rlSetUniformMatrix(int32 locIndex, Matrix mat);
/// Set shader value sampler
[CLink]
public static extern void rlSetUniformSampler(int32 locIndex, int32 textureId);
@ -794,6 +786,24 @@ public static class Rlgl
[CLink]
public static extern Matrix rlGetMatrixViewOffsetStereo(int32 eye);
/// Load and draw a cube
[CLink]
public static extern void rlLoadDrawCube();
/// Load and draw a quad
[CLink]
public static extern void rlLoadDrawQuad();
#if !BF_PLATFORM_WASM
/// Unload render batch system
[CLink]
public static extern void rlUnloadRenderBatch(rlRenderBatch batch);
/// Set shader value matrix
[CLink]
public static extern void rlSetUniformMatrix(int32 locIndex, Matrix mat);
/// Set a custom projection matrix (replaces internal projection matrix)
[CLink]
public static extern void rlSetMatrixProjection(Matrix proj);
@ -810,13 +820,32 @@ public static class Rlgl
[CLink]
public static extern void rlSetMatrixViewOffsetStereo(Matrix right, Matrix left);
/// Load and draw a cube
[CLink]
public static extern void rlLoadDrawCube();
#else
/// Load and draw a quad
/// Unload render batch system
[CLink]
public static extern void rlLoadDrawQuad();
public static extern void rlUnloadRenderBatch(in rlRenderBatch batch);
/// Set shader value matrix
[CLink]
public static extern void rlSetUniformMatrix(int32 locIndex, in Matrix mat);
/// Set a custom projection matrix (replaces internal projection matrix)
[CLink]
public static extern void rlSetMatrixProjection(in Matrix proj);
/// Set a custom modelview matrix (replaces internal modelview matrix)
[CLink]
public static extern void rlSetMatrixModelview(in Matrix view);
/// Set eyes projection matrices for stereo rendering
[CLink]
public static extern void rlSetMatrixProjectionStereo(in Matrix right, in Matrix left);
/// Set eyes view offsets matrices for stereo rendering
[CLink]
public static extern void rlSetMatrixViewOffsetStereo(in Matrix right, in Matrix left);
#endif
}

View file

@ -10,9 +10,9 @@ public struct Shader
public int32 id;
/// Shader locations array (RL_MAX_SHADER_LOCATIONS)
public int32 * locs;
public void* locs;
public this(int32 id, int32 * locs)
public this(int32 id, void* locs)
{
this.id = id;
this.locs = locs;

View file

@ -3,6 +3,7 @@ using System.Interop;
namespace RaylibBeef;
[AllowDuplicates]
/// Shader attribute data types
public enum ShaderAttributeDataType : c_int
{

View file

@ -3,6 +3,7 @@ using System.Interop;
namespace RaylibBeef;
[AllowDuplicates]
/// Shader location index
public enum ShaderLocationIndex : c_int
{

View file

@ -3,6 +3,7 @@ using System.Interop;
namespace RaylibBeef;
[AllowDuplicates]
/// Shader uniform data type
public enum ShaderUniformDataType : c_int
{

View file

@ -3,6 +3,7 @@ using System.Interop;
namespace RaylibBeef;
[AllowDuplicates]
/// Texture parameters: filter mode
public enum TextureFilter : c_int
{

View file

@ -3,6 +3,7 @@ using System.Interop;
namespace RaylibBeef;
[AllowDuplicates]
/// Texture parameters: wrap mode
public enum TextureWrap : c_int
{

View file

@ -3,6 +3,7 @@ using System.Interop;
namespace RaylibBeef;
[AllowDuplicates]
/// Trace log level
public enum TraceLogLevel : c_int
{

View file

@ -19,9 +19,9 @@ public struct Wave
public int32 channels;
/// Buffer data pointer
public void * data;
public void* data;
public this(int32 frameCount, int32 sampleRate, int32 sampleSize, int32 channels, void * data)
public this(int32 frameCount, int32 sampleRate, int32 sampleSize, int32 channels, void* data)
{
this.frameCount = frameCount;
this.sampleRate = sampleRate;

View file

@ -3,6 +3,7 @@ using System.Interop;
namespace RaylibBeef;
[AllowDuplicates]
/// Color blending modes (pre-defined)
public enum rlBlendMode : c_int
{

View file

@ -3,6 +3,7 @@ using System.Interop;
namespace RaylibBeef;
[AllowDuplicates]
/// Face culling mode
public enum rlCullMode : c_int
{

View file

@ -3,6 +3,7 @@ using System.Interop;
namespace RaylibBeef;
[AllowDuplicates]
/// Framebuffer texture attachment type
public enum rlFramebufferAttachTextureType : c_int
{

View file

@ -3,6 +3,7 @@ using System.Interop;
namespace RaylibBeef;
[AllowDuplicates]
/// Framebuffer attachment type
public enum rlFramebufferAttachType : c_int
{

View file

@ -3,6 +3,7 @@ using System.Interop;
namespace RaylibBeef;
[AllowDuplicates]
/// OpenGL version
public enum rlGlVersion : c_int
{

View file

@ -3,6 +3,7 @@ using System.Interop;
namespace RaylibBeef;
[AllowDuplicates]
/// Texture pixel formats
public enum rlPixelFormat : c_int
{

View file

@ -3,6 +3,7 @@ using System.Interop;
namespace RaylibBeef;
[AllowDuplicates]
/// Shader attribute data types
public enum rlShaderAttributeDataType : c_int
{

View file

@ -3,6 +3,7 @@ using System.Interop;
namespace RaylibBeef;
[AllowDuplicates]
/// Shader location point type
public enum rlShaderLocationIndex : c_int
{

View file

@ -3,6 +3,7 @@ using System.Interop;
namespace RaylibBeef;
[AllowDuplicates]
/// Shader uniform data type
public enum rlShaderUniformDataType : c_int
{

View file

@ -3,6 +3,7 @@ using System.Interop;
namespace RaylibBeef;
[AllowDuplicates]
/// Texture parameters: filter mode
public enum rlTextureFilter : c_int
{

View file

@ -3,6 +3,7 @@ using System.Interop;
namespace RaylibBeef;
[AllowDuplicates]
/// Trace log level
public enum rlTraceLogLevel : c_int
{

View file

@ -10,13 +10,13 @@ public struct rlVertexBuffer
public int32 elementCount;
/// Vertex position (XYZ - 3 components per vertex) (shader-location = 0)
public float * vertices;
public void* vertices;
/// Vertex texture coordinates (UV - 2 components per vertex) (shader-location = 1)
public float * texcoords;
public void* texcoords;
/// Vertex colors (RGBA - 4 components per vertex) (shader-location = 3)
public char8 * colors;
public void* colors;
/// Vertex indices (in case vertex data comes indexed) (6 indices per quad)
public void* indices;
@ -27,7 +27,7 @@ public struct rlVertexBuffer
/// OpenGL Vertex Buffer Objects id (4 types of vertex data)
public int32[4] vboId;
public this(int32 elementCount, float * vertices, float * texcoords, char8 * colors, void* indices, void* vaoId, int32[4] vboId)
public this(int32 elementCount, void* vertices, void* texcoords, void* colors, void* indices, void* vaoId, int32[4] vboId)
{
this.elementCount = elementCount;
this.vertices = vertices;