From e3f29a5bbca30d42056df41e1449b2ae2ffe36e9 Mon Sep 17 00:00:00 2001 From: Braedon Lewis Date: Sun, 19 Nov 2023 22:18:54 -0500 Subject: [PATCH] Update raylib-api --- generator/Program.cs | 9 +- raylib-api | 2 +- raylib-beef/example/src/Program.bf | 2 +- raylib-beef/src/Raymath.bf | 456 +++++++++++++++++++++++++++++ raylib-beef/src/Rlgl.bf | 91 ------ raylib-beef/src/rlVertexBuffer.bf | 18 +- 6 files changed, 466 insertions(+), 112 deletions(-) diff --git a/generator/Program.cs b/generator/Program.cs index 15753de..ad87045 100644 --- a/generator/Program.cs +++ b/generator/Program.cs @@ -13,7 +13,8 @@ namespace RaylibBeefGenerator // Current Output Beef Code private static StringBuilder OutputString = new StringBuilder(); - private static string OutputDir = @"C:\Dev\raylib-beef\raylib-beef\src\"; + private static string ExecutingPath = Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)!, "../../../../"); + private static string OutputDir = Path.Combine(ExecutingPath, "raylib-beef/src/"); private static Dictionary jsonFiles = new() { @@ -45,7 +46,7 @@ namespace RaylibBeefGenerator for (var i = 0; i < jsonFiles.Count; i++) { - ConvertFile(jsonFiles.ElementAt(i).Value, @$"C:\Dev\raylib-beef\raylib-api\{jsonFiles.ElementAt(i).Key}"); + ConvertFile(jsonFiles.ElementAt(i).Value, Path.Combine(ExecutingPath, $"raylib-api/{jsonFiles.ElementAt(i).Key}")); } Console.WriteLine("Successfully Generated Bindings!"); @@ -54,7 +55,7 @@ namespace RaylibBeefGenerator public static void ConvertFile(FileDefinition def, string location) { - var api = JsonConvert.DeserializeObject(File.ReadAllText(location)); + var api = JsonConvert.DeserializeObject(File.ReadAllText(location))!; OutputString.Clear(); OutputString = new(); @@ -72,7 +73,7 @@ namespace RaylibBeefGenerator if (!string.IsNullOrEmpty(define.Description)) AppendLine($"/// {define.Description}"); var defineType = define.Type.ConvertTypes(); - AppendLine($"public const {defineType} {define.Name.ConvertName()} = {define.Value.ToString().ParseValue(defineType)};"); + AppendLine($"public const {defineType} {define.Name.ConvertName()} = {define.Value.ToString()!.ParseValue(defineType)};"); AppendLine(""); } diff --git a/raylib-api b/raylib-api index 75b79a9..5e9f155 160000 --- a/raylib-api +++ b/raylib-api @@ -1 +1 @@ -Subproject commit 75b79a9bb1368c483aa575205435dc49f16c58fc +Subproject commit 5e9f1551c3a394c63a7080c093e51c621cac4159 diff --git a/raylib-beef/example/src/Program.bf b/raylib-beef/example/src/Program.bf index 7a1a77a..55d4daf 100644 --- a/raylib-beef/example/src/Program.bf +++ b/raylib-beef/example/src/Program.bf @@ -8,7 +8,7 @@ class Program { public static int Main(String[] args) { - InitWindow(800, 600, "Raylib Beef 4.5"); + InitWindow(800, 600, scope $"Raylib Beef {RAYLIB_VERSION_MAJOR}.{RAYLIB_VERSION_MINOR}.{RAYLIB_VERSION_PATCH}"); InitAudioDevice(); var beefMain = Color(165, 47, 78, 255); diff --git a/raylib-beef/src/Raymath.bf b/raylib-beef/src/Raymath.bf index ed1f6ad..9db84e6 100644 --- a/raylib-beef/src/Raymath.bf +++ b/raylib-beef/src/Raymath.bf @@ -13,5 +13,461 @@ public static class Raymath public const float RAD2DEG = (180.0f/PI); + /// + [CLink] + public static extern float Clamp(float value, float min, float max); + + /// + [CLink] + public static extern float Lerp(float start, float end, float amount); + + /// + [CLink] + public static extern float Normalize(float value, float start, float end); + + /// + [CLink] + public static extern float Remap(float value, float inputStart, float inputEnd, float outputStart, float outputEnd); + + /// + [CLink] + public static extern float Wrap(float value, float min, float max); + + /// + [CLink] + public static extern int32 FloatEquals(float x, float y); + + /// + [CLink] + public static extern Vector2 Vector2Zero(); + + /// + [CLink] + public static extern Vector2 Vector2One(); + + /// + [CLink] + public static extern Vector2 Vector2Add(Vector2 v1, Vector2 v2); + + /// + [CLink] + public static extern Vector2 Vector2AddValue(Vector2 v, float add); + + /// + [CLink] + public static extern Vector2 Vector2Subtract(Vector2 v1, Vector2 v2); + + /// + [CLink] + public static extern Vector2 Vector2SubtractValue(Vector2 v, float sub); + + /// + [CLink] + public static extern float Vector2Length(Vector2 v); + + /// + [CLink] + public static extern float Vector2LengthSqr(Vector2 v); + + /// + [CLink] + public static extern float Vector2DotProduct(Vector2 v1, Vector2 v2); + + /// + [CLink] + public static extern float Vector2Distance(Vector2 v1, Vector2 v2); + + /// + [CLink] + public static extern float Vector2DistanceSqr(Vector2 v1, Vector2 v2); + + /// + [CLink] + public static extern float Vector2Angle(Vector2 v1, Vector2 v2); + + /// + [CLink] + public static extern float Vector2LineAngle(Vector2 start, Vector2 end); + + /// + [CLink] + public static extern Vector2 Vector2Scale(Vector2 v, float scale); + + /// + [CLink] + public static extern Vector2 Vector2Multiply(Vector2 v1, Vector2 v2); + + /// + [CLink] + public static extern Vector2 Vector2Negate(Vector2 v); + + /// + [CLink] + public static extern Vector2 Vector2Divide(Vector2 v1, Vector2 v2); + + /// + [CLink] + public static extern Vector2 Vector2Normalize(Vector2 v); + + /// + [CLink] + public static extern Vector2 Vector2Transform(Vector2 v, Matrix mat); + + /// + [CLink] + public static extern Vector2 Vector2Lerp(Vector2 v1, Vector2 v2, float amount); + + /// + [CLink] + public static extern Vector2 Vector2Reflect(Vector2 v, Vector2 normal); + + /// + [CLink] + public static extern Vector2 Vector2Rotate(Vector2 v, float angle); + + /// + [CLink] + public static extern Vector2 Vector2MoveTowards(Vector2 v, Vector2 target, float maxDistance); + + /// + [CLink] + public static extern Vector2 Vector2Invert(Vector2 v); + + /// + [CLink] + public static extern Vector2 Vector2Clamp(Vector2 v, Vector2 min, Vector2 max); + + /// + [CLink] + public static extern Vector2 Vector2ClampValue(Vector2 v, float min, float max); + + /// + [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); + + /// + [CLink] + public static extern Vector3 Vector3AddValue(Vector3 v, float add); + + /// + [CLink] + public static extern Vector3 Vector3Subtract(Vector3 v1, Vector3 v2); + + /// + [CLink] + public static extern Vector3 Vector3SubtractValue(Vector3 v, float sub); + + /// + [CLink] + public static extern Vector3 Vector3Scale(Vector3 v, float scalar); + + /// + [CLink] + public static extern Vector3 Vector3Multiply(Vector3 v1, Vector3 v2); + + /// + [CLink] + public static extern Vector3 Vector3CrossProduct(Vector3 v1, Vector3 v2); + + /// + [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); + + /// + [CLink] + public static extern float Vector3Distance(Vector3 v1, Vector3 v2); + + /// + [CLink] + public static extern float Vector3DistanceSqr(Vector3 v1, Vector3 v2); + + /// + [CLink] + public static extern float Vector3Angle(Vector3 v1, Vector3 v2); + + /// + [CLink] + public static extern Vector3 Vector3Negate(Vector3 v); + + /// + [CLink] + public static extern Vector3 Vector3Divide(Vector3 v1, Vector3 v2); + + /// + [CLink] + public static extern Vector3 Vector3Normalize(Vector3 v); + + /// + [CLink] + public static extern Vector3 Vector3Project(Vector3 v1, Vector3 v2); + + /// + [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); + + /// + [CLink] + public static extern Vector3 Vector3RotateByQuaternion(Vector3 v, Quaternion q); + + /// + [CLink] + public static extern Vector3 Vector3RotateByAxisAngle(Vector3 v, Vector3 axis, float angle); + + /// + [CLink] + public static extern Vector3 Vector3Lerp(Vector3 v1, Vector3 v2, float amount); + + /// + [CLink] + public static extern Vector3 Vector3Reflect(Vector3 v, Vector3 normal); + + /// + [CLink] + public static extern Vector3 Vector3Min(Vector3 v1, Vector3 v2); + + /// + [CLink] + public static extern Vector3 Vector3Max(Vector3 v1, Vector3 v2); + + /// + [CLink] + public static extern Vector3 Vector3Barycenter(Vector3 p, Vector3 a, Vector3 b, Vector3 c); + + /// + [CLink] + public static extern Vector3 Vector3Unproject(Vector3 source, Matrix projection, Matrix view); + + /// + [CLink] + public static extern float3 Vector3ToFloatV(Vector3 v); + + /// + [CLink] + public static extern Vector3 Vector3Invert(Vector3 v); + + /// + [CLink] + public static extern Vector3 Vector3Clamp(Vector3 v, Vector3 min, Vector3 max); + + /// + [CLink] + public static extern Vector3 Vector3ClampValue(Vector3 v, float min, float max); + + /// + [CLink] + public static extern int32 Vector3Equals(Vector3 p, Vector3 q); + + /// + [CLink] + public static extern Vector3 Vector3Refract(Vector3 v, Vector3 n, float r); + + /// + [CLink] + public static extern float MatrixDeterminant(Matrix mat); + + /// + [CLink] + public static extern float MatrixTrace(Matrix mat); + + /// + [CLink] + public static extern Matrix MatrixTranspose(Matrix mat); + + /// + [CLink] + public static extern Matrix MatrixInvert(Matrix mat); + + /// + [CLink] + public static extern Matrix MatrixIdentity(); + + /// + [CLink] + public static extern Matrix MatrixAdd(Matrix left, Matrix right); + + /// + [CLink] + public static extern Matrix MatrixSubtract(Matrix left, Matrix right); + + /// + [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); + + /// + [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); + + /// + [CLink] + public static extern float16 MatrixToFloatV(Matrix mat); + + /// + [CLink] + public static extern Quaternion QuaternionAdd(Quaternion q1, Quaternion q2); + + /// + [CLink] + public static extern Quaternion QuaternionAddValue(Quaternion q, float add); + + /// + [CLink] + public static extern Quaternion QuaternionSubtract(Quaternion q1, Quaternion q2); + + /// + [CLink] + public static extern Quaternion QuaternionSubtractValue(Quaternion q, float sub); + + /// + [CLink] + public static extern Quaternion QuaternionIdentity(); + + /// + [CLink] + public static extern float QuaternionLength(Quaternion q); + + /// + [CLink] + public static extern Quaternion QuaternionNormalize(Quaternion q); + + /// + [CLink] + public static extern Quaternion QuaternionInvert(Quaternion q); + + /// + [CLink] + public static extern Quaternion QuaternionMultiply(Quaternion q1, Quaternion q2); + + /// + [CLink] + public static extern Quaternion QuaternionScale(Quaternion q, float mul); + + /// + [CLink] + public static extern Quaternion QuaternionDivide(Quaternion q1, Quaternion q2); + + /// + [CLink] + public static extern Quaternion QuaternionLerp(Quaternion q1, Quaternion q2, float amount); + + /// + [CLink] + public static extern Quaternion QuaternionNlerp(Quaternion q1, Quaternion q2, float amount); + + /// + [CLink] + public static extern Quaternion QuaternionSlerp(Quaternion q1, Quaternion q2, float amount); + + /// + [CLink] + public static extern Quaternion QuaternionFromVector3ToVector3(Vector3 from, Vector3 to); + + /// + [CLink] + public static extern Quaternion QuaternionFromMatrix(Matrix mat); + + /// + [CLink] + public static extern Matrix QuaternionToMatrix(Quaternion q); + + /// + [CLink] + public static extern Quaternion QuaternionFromAxisAngle(Vector3 axis, float angle); + + /// + [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); + + /// + [CLink] + public static extern Quaternion QuaternionTransform(Quaternion q, Matrix mat); + + /// + [CLink] + public static extern int32 QuaternionEquals(Quaternion p, Quaternion q); + } diff --git a/raylib-beef/src/Rlgl.bf b/raylib-beef/src/Rlgl.bf index e57e3ab..d58eb87 100644 --- a/raylib-beef/src/Rlgl.bf +++ b/raylib-beef/src/Rlgl.bf @@ -222,95 +222,6 @@ public static class Rlgl /// GL_BLEND_COLOR public const int32 RL_BLEND_COLOR = 32773; - public const float PI = 3.141592653589793f; - - public const float DEG2RAD = (PI/180.0f); - - public const float RAD2DEG = (180.0f/PI); - - public const int32 GL_SHADING_LANGUAGE_VERSION = 35724; - - public const int32 GL_COMPRESSED_RGB_S3TC_DXT1_EXT = 33776; - - public const int32 GL_COMPRESSED_RGBA_S3TC_DXT1_EXT = 33777; - - public const int32 GL_COMPRESSED_RGBA_S3TC_DXT3_EXT = 33778; - - public const int32 GL_COMPRESSED_RGBA_S3TC_DXT5_EXT = 33779; - - public const int32 GL_ETC1_RGB8_OES = 36196; - - public const int32 GL_COMPRESSED_RGB8_ETC2 = 37492; - - public const int32 GL_COMPRESSED_RGBA8_ETC2_EAC = 37496; - - public const int32 GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG = 35840; - - public const int32 GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG = 35842; - - public const int32 GL_COMPRESSED_RGBA_ASTC_4x4_KHR = 37808; - - public const int32 GL_COMPRESSED_RGBA_ASTC_8x8_KHR = 37815; - - public const int32 GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT = 34047; - - public const int32 GL_TEXTURE_MAX_ANISOTROPY_EXT = 34046; - - public const int32 GL_UNSIGNED_SHORT_5_6_5 = 33635; - - public const int32 GL_UNSIGNED_SHORT_5_5_5_1 = 32820; - - public const int32 GL_UNSIGNED_SHORT_4_4_4_4 = 32819; - - public const int32 GL_LUMINANCE = 6409; - - public const int32 GL_LUMINANCE_ALPHA = 6410; - - /// Bound by default to shader location: 0 - public const char8* RL_DEFAULT_SHADER_ATTRIB_NAME_POSITION = "vertexPosition"; - - /// Bound by default to shader location: 1 - public const char8* RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD = "vertexTexCoord"; - - /// Bound by default to shader location: 2 - public const char8* RL_DEFAULT_SHADER_ATTRIB_NAME_NORMAL = "vertexNormal"; - - /// Bound by default to shader location: 3 - public const char8* RL_DEFAULT_SHADER_ATTRIB_NAME_COLOR = "vertexColor"; - - /// Bound by default to shader location: 4 - public const char8* RL_DEFAULT_SHADER_ATTRIB_NAME_TANGENT = "vertexTangent"; - - /// Bound by default to shader location: 5 - public const char8* RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD2 = "vertexTexCoord2"; - - /// model-view-projection matrix - public const char8* RL_DEFAULT_SHADER_UNIFORM_NAME_MVP = "mvp"; - - /// view matrix - public const char8* RL_DEFAULT_SHADER_UNIFORM_NAME_VIEW = "matView"; - - /// projection matrix - public const char8* RL_DEFAULT_SHADER_UNIFORM_NAME_PROJECTION = "matProjection"; - - /// model matrix - public const char8* RL_DEFAULT_SHADER_UNIFORM_NAME_MODEL = "matModel"; - - /// normal matrix (transpose(inverse(matModelView)) - public const char8* RL_DEFAULT_SHADER_UNIFORM_NAME_NORMAL = "matNormal"; - - /// color diffuse (base tint color, multiplied by texture color) - public const char8* RL_DEFAULT_SHADER_UNIFORM_NAME_COLOR = "colDiffuse"; - - /// texture0 (texture slot active 0) - public const char8* RL_DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE0 = "texture0"; - - /// texture1 (texture slot active 1) - public const char8* RL_DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE1 = "texture1"; - - /// texture2 (texture slot active 2) - public const char8* RL_DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE2 = "texture2"; - /// Choose the current matrix to be transformed [CLink] public static extern void rlMatrixMode(int32 mode); @@ -907,7 +818,5 @@ public static class Rlgl [CLink] public static extern void rlLoadDrawQuad(); - /// OpenGL extension functions loader signature (same as GLADloadproc) - public function void * rlglLoadProc(char8 * name); } diff --git a/raylib-beef/src/rlVertexBuffer.bf b/raylib-beef/src/rlVertexBuffer.bf index 5249108..4da91f9 100644 --- a/raylib-beef/src/rlVertexBuffer.bf +++ b/raylib-beef/src/rlVertexBuffer.bf @@ -18,34 +18,22 @@ public struct rlVertexBuffer /// Vertex colors (RGBA - 4 components per vertex) (shader-location = 3) public char8 * colors; - /// - public void* rlRenderBatch; - /// Vertex indices (in case vertex data comes indexed) (6 indices per quad) - public int32 * indices; - - /// Number of vertex required for index alignment (LINES, TRIANGLES) - public void* vertexAlignment; - - /// Shader id to be used on the draw -> Using RLGL.currentShaderId - public void* shaderId; + public void* indices; /// OpenGL Vertex Array Object id - public int32 vaoId; + public void* vaoId; /// 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* rlRenderBatch, int32 * indices, void* vertexAlignment, void* shaderId, int32 vaoId, int32[4] vboId) + public this(int32 elementCount, float * vertices, float * texcoords, char8 * colors, void* indices, void* vaoId, int32[4] vboId) { this.elementCount = elementCount; this.vertices = vertices; this.texcoords = texcoords; this.colors = colors; - this.rlRenderBatch = rlRenderBatch; this.indices = indices; - this.vertexAlignment = vertexAlignment; - this.shaderId = shaderId; this.vaoId = vaoId; this.vboId = vboId; }