diff --git a/README.md b/README.md index 7a3799c..affdd50 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Manually tweaked, auto-generated [raylib](https://github.com/raysan5/raylib) bindings for zig. -Bindings tested on raylib version 5.6-dev and Zig 0.15.1 +Bindings tested on raylib version 6.0 and Zig 0.16.0 Thanks to all the [contributors](https://github.com/raylib-zig/raylib-zig/graphs/contributors) for their help with this binding. diff --git a/build.zig b/build.zig index 85aaf35..460ddf7 100644 --- a/build.zig +++ b/build.zig @@ -16,38 +16,6 @@ const Program = struct { desc: []const u8, }; -fn getRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode, options: Options) *std.Build.Step.Compile { - const raylib_dep = b.dependency("raylib", .{ - .target = target, - .optimize = optimize, - .raudio = options.raudio, - .rmodels = options.rmodels, - .rshapes = options.rshapes, - .rtext = options.rtext, - .rtextures = options.rtextures, - .platform = options.platform, - .linkage = options.linkage, - .linux_display_backend = options.linux_display_backend, - .opengl_version = options.opengl_version, - .android_api_version = options.android_api_version, - .android_ndk = options.android_ndk, - .config = options.config, - }); - - const raylib = raylib_dep.artifact("raylib"); - - const raygui_dep = b.dependency("raygui", .{ - .target = target, - .optimize = optimize, - .link_libc = true, - }); - - rl.addRaygui(b, raylib, raygui_dep, options); - - b.installArtifact(raylib); - return raylib; -} - fn getModule(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode) *std.Build.Module { if (b.modules.contains("raylib")) { return b.modules.get("raylib").?; @@ -77,7 +45,29 @@ pub fn build(b: *std.Build) !void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); - const raylib_artifact = this.getRaylib(b, target, optimize, Options.getOptions(b)); + const options = Options.getOptions(b); + const raylib_dep = b.dependency("raylib", .{ + .target = target, + .optimize = optimize, + .raudio = options.raudio, + .rmodels = options.rmodels, + .rshapes = options.rshapes, + .rtext = options.rtext, + .rtextures = options.rtextures, + .platform = options.platform, + .linkage = options.linkage, + .linux_display_backend = options.linux_display_backend, + .opengl_version = options.opengl_version, + .android_api_version = options.android_api_version, + .android_ndk = options.android_ndk, + .config = options.config, + .raygui = true, + }); + + const raylib_artifact = raylib_dep.artifact("raylib"); + + b.installArtifact(raylib_artifact); + const raylib = this.getModule(b, target, optimize); const raygui = this.gui.getModule(b, target, optimize); @@ -456,7 +446,7 @@ pub fn build(b: *std.Build) !void { .optimize = optimize, .flags = emcc_flags, .settings = emcc_settings, - .shell_file_path = emsdk.shell(b), + .shell_file_path = emsdk.shell(raylib_dep), .install_dir = install_dir, .embed_paths = &.{.{ .src_path = "resources/" }}, }); diff --git a/build.zig.zon b/build.zig.zon index 93eacf1..9183505 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -1,11 +1,11 @@ .{ .name = .raylib_zig, - .version = "5.6.0-dev", + .version = "6.0.0", .fingerprint = 0xc4cfa8c610114f28, .dependencies = .{ .raylib = .{ - .url = "git+https://github.com/raysan5/raylib#f36533cbd8feead845a2e0b4568ec0484a15cd10", - .hash = "raylib-5.6.0-dev-whq8uGJqKQUEDd38DCov-XG29PYzw3kM_LNbPUkcDGyM", + .url = "git+https://github.com/raysan5/raylib#6.0", + .hash = "raylib-6.0.0-whq8uCSwLgWWeF3ec3dbG6Rr36SLFL-s2WJ1Q_2E22Bb", }, .raygui = .{ .url = "git+https://github.com/raysan5/raygui#3b2855842ab578a034f827c38cf8f62c042fc983", @@ -16,11 +16,11 @@ .hash = "N-V-__8AAJl1DwBezhYo_VE6f53mPVm00R-Fk28NPW7P14EQ", }, .zemscripten = .{ - .url = "git+https://github.com/zig-gamedev/zemscripten?ref=main#00da03b188220374a57cb34cda6230b8d53737ea", - .hash = "zemscripten-0.2.0-dev-sRlDqFJSAAB8hgnRt5DDMKP3zLlDtMnUDwYRJVCa5lGY", + .url = "git+https://github.com/zig-gamedev/zemscripten#70bdafc473be2131445bb6fd977fe7cb92fd0f5f", + .hash = "zemscripten-0.2.0-dev-sRlDqEtQAAB_1tPdqJsxQIqXxvvklcFu6VN5p6ANy8hw", }, }, - .minimum_zig_version = "0.16.0-dev.3070+b22eb176b", + .minimum_zig_version = "0.16.0", .paths = .{ "build.zig", "build.zig.zon", diff --git a/examples/shapes/basic_shapes.zig b/examples/shapes/basic_shapes.zig index 2686ebb..083aa52 100644 --- a/examples/shapes/basic_shapes.zig +++ b/examples/shapes/basic_shapes.zig @@ -32,7 +32,7 @@ pub fn main() anyerror!void { // Circle shapes and lines rl.drawCircle(screenWidth / 5, 120, 35, .dark_blue); - rl.drawCircleGradient(screenWidth / 5, 220, 60, .green, .sky_blue); + rl.drawCircleGradient(rl.Vector2.init(screenWidth / 5, 220), 60, .green, .sky_blue); rl.drawCircleLines(screenWidth / 5, 340, 80, .dark_blue); // Rectangle shapes and lines diff --git a/examples/shapes/top_down_lights.zig b/examples/shapes/top_down_lights.zig index 2990309..e804984 100644 --- a/examples/shapes/top_down_lights.zig +++ b/examples/shapes/top_down_lights.zig @@ -87,7 +87,7 @@ fn drawLightMask(slot: usize) void { defer rl.gl.rlSetBlendMode(@intFromEnum(rl.gl.rlBlendMode.rl_blend_alpha)); // If we are valid, then draw the light radius to the alpha mask - if (lights[slot].valid) rl.drawCircleGradient(@intFromFloat(lights[slot].position.x), @intFromFloat(lights[slot].position.y), lights[slot].outerRadius, rl.colorAlpha(.white, 0), .white); + if (lights[slot].valid) rl.drawCircleGradient(lights[slot].position, lights[slot].outerRadius, rl.colorAlpha(.white, 0), .white); rl.gl.rlDrawRenderBatchActive(); diff --git a/lib/raylib-ext.zig b/lib/raylib-ext.zig index 39acb82..7f212b6 100644 --- a/lib/raylib-ext.zig +++ b/lib/raylib-ext.zig @@ -231,10 +231,10 @@ pub extern "c" fn DrawLineStrip(points: [*c]const rl.Vector2, pointCount: c_int, pub extern "c" fn DrawLineBezier(startPos: rl.Vector2, endPos: rl.Vector2, thick: f32, color: rl.Color) void; pub extern "c" fn DrawLineDashed(startPos: rl.Vector2, endPos: rl.Vector2, dashSize: c_int, spaceSize: c_int, color: rl.Color) void; pub extern "c" fn DrawCircle(centerX: c_int, centerY: c_int, radius: f32, color: rl.Color) void; +pub extern "c" fn DrawCircleV(center: rl.Vector2, radius: f32, color: rl.Color) void; +pub extern "c" fn DrawCircleGradient(center: rl.Vector2, radius: f32, inner: rl.Color, outer: rl.Color) void; pub extern "c" fn DrawCircleSector(center: rl.Vector2, radius: f32, startAngle: f32, endAngle: f32, segments: c_int, color: rl.Color) void; pub extern "c" fn DrawCircleSectorLines(center: rl.Vector2, radius: f32, startAngle: f32, endAngle: f32, segments: c_int, color: rl.Color) void; -pub extern "c" fn DrawCircleGradient(centerX: c_int, centerY: c_int, radius: f32, inner: rl.Color, outer: rl.Color) void; -pub extern "c" fn DrawCircleV(center: rl.Vector2, radius: f32, color: rl.Color) void; pub extern "c" fn DrawCircleLines(centerX: c_int, centerY: c_int, radius: f32, color: rl.Color) void; pub extern "c" fn DrawCircleLinesV(center: rl.Vector2, radius: f32, color: rl.Color) void; pub extern "c" fn DrawEllipse(centerX: c_int, centerY: c_int, radiusH: f32, radiusV: f32, color: rl.Color) void; diff --git a/lib/raylib.h b/lib/raylib.h index c6aad86..bdca643 100644 --- a/lib/raylib.h +++ b/lib/raylib.h @@ -10,7 +10,7 @@ * - Software renderer optional, for systems with no GPU: [rlsw] * - Custom OpenGL abstraction layer (usable as standalone module): [rlgl] * - Multiple Fonts formats supported (TTF, OTF, FNT, BDF, Sprite fonts) -* - Many texture formats supportted, including compressed formats (DXT, ETC, ASTC) +* - Many texture formats supported, including compressed formats (DXT, ETC, ASTC) * - Full 3d support for 3d Shapes, Models, Billboards, Heightmaps and more! * - Flexible Materials system, supporting classic maps and PBR maps * - Animated 3D models supported (skeletal bones animation) (IQM, M3D, GLTF) @@ -35,14 +35,14 @@ * [rcore] sinfl (Micha Mettke) for DEFLATE decompression algorithm * [rcore] sdefl (Micha Mettke) for DEFLATE compression algorithm * [rcore] rprand (Ramon Santamaria) for pseudo-random numbers generation -* [rtextures] qoi (Dominic Szablewski - https://phoboslab.org) for QOI image manage -* [rtextures] stb_image (Sean Barret) for images loading (BMP, TGA, PNG, JPEG, HDR...) -* [rtextures] stb_image_write (Sean Barret) for image writing (BMP, TGA, PNG, JPG) -* [rtextures] stb_image_resize2 (Sean Barret) for image resizing algorithms -* [rtextures] stb_perlin (Sean Barret) for Perlin Noise image generation +* [rtextures] qoi (Dominic Szablewski - https://phoboslab.org) for QOI image management +* [rtextures] stb_image (Sean Barrett) for images loading (BMP, TGA, PNG, JPEG, HDR...) +* [rtextures] stb_image_write (Sean Barrett) for image writing (BMP, TGA, PNG, JPG) +* [rtextures] stb_image_resize2 (Sean Barrett) for image resizing algorithms +* [rtextures] stb_perlin (Sean Barrett) for Perlin Noise image generation * [rtextures] rltexgpu (Ramon Santamaria) for GPU-compressed texture formats -* [rtext] stb_truetype (Sean Barret) for ttf fonts loading -* [rtext] stb_rect_pack (Sean Barret) for rectangles packing +* [rtext] stb_truetype (Sean Barrett) for ttf fonts loading +* [rtext] stb_rect_pack (Sean Barrett) for rectangles packing * [rmodels] par_shapes (Philip Rideout) for parametric 3d shapes generation * [rmodels] tinyobj_loader_c (Syoyo Fujita) for models loading (OBJ, MTL) * [rmodels] cgltf (Johannes Kuhlmann) for models loading (glTF) @@ -51,10 +51,10 @@ * [raudio] dr_wav (David Reid) for WAV audio file loading * [raudio] dr_flac (David Reid) for FLAC audio file loading * [raudio] dr_mp3 (David Reid) for MP3 audio file loading -* [raudio] stb_vorbis (Sean Barret) for OGG audio loading +* [raudio] stb_vorbis (Sean Barrett) for OGG audio loading * [raudio] jar_xm (Joshua Reisenauer) for XM audio module loading * [raudio] jar_mod (Joshua Reisenauer) for MOD audio module loading -* [raudio] qoa (Dominic Szablewski - https://phoboslab.org) for QOA audio manage +* [raudio] qoa (Dominic Szablewski - https://phoboslab.org) for QOA audio management * * * LICENSE: zlib/libpng @@ -1071,9 +1071,9 @@ RLAPI Shader LoadShaderFromMemory(const char *vsCode, const char *fsCode); // Lo RLAPI bool IsShaderValid(Shader shader); // Check if a shader is valid (loaded on GPU) RLAPI int GetShaderLocation(Shader shader, const char *uniformName); // Get shader uniform location RLAPI int GetShaderLocationAttrib(Shader shader, const char *attribName); // Get shader attribute location -RLAPI void SetShaderValue(Shader shader, int locIndex, const void *value, int uniformType); // Set shader uniform value -RLAPI void SetShaderValueV(Shader shader, int locIndex, const void *value, int uniformType, int count); // Set shader uniform value vector -RLAPI void SetShaderValueMatrix(Shader shader, int locIndex, Matrix mat); // Set shader uniform value (matrix 4x4) +RLAPI void SetShaderValue(Shader shader, int locIndex, const void *value, int uniformType); // Set shader uniform value +RLAPI void SetShaderValueV(Shader shader, int locIndex, const void *value, int uniformType, int count); // Set shader uniform value vector +RLAPI void SetShaderValueMatrix(Shader shader, int locIndex, Matrix mat); // Set shader uniform value (matrix 4x4) RLAPI void SetShaderValueTexture(Shader shader, int locIndex, Texture2D texture); // Set shader uniform value and bind the texture (sampler2d) RLAPI void UnloadShader(Shader shader); // Unload shader from GPU memory (VRAM) @@ -1175,10 +1175,10 @@ RLAPI unsigned char *CompressData(const unsigned char *data, int dataSize, int * RLAPI unsigned char *DecompressData(const unsigned char *compData, int compDataSize, int *dataSize); // Decompress data (DEFLATE algorithm), memory must be MemFree() RLAPI char *EncodeDataBase64(const unsigned char *data, int dataSize, int *outputSize); // Encode data to Base64 string (includes NULL terminator), memory must be MemFree() RLAPI unsigned char *DecodeDataBase64(const char *text, int *outputSize); // Decode Base64 string (expected NULL terminated), memory must be MemFree() -RLAPI unsigned int ComputeCRC32(unsigned char *data, int dataSize); // Compute CRC32 hash code -RLAPI unsigned int *ComputeMD5(unsigned char *data, int dataSize); // Compute MD5 hash code, returns static int[4] (16 bytes) -RLAPI unsigned int *ComputeSHA1(unsigned char *data, int dataSize); // Compute SHA1 hash code, returns static int[5] (20 bytes) -RLAPI unsigned int *ComputeSHA256(unsigned char *data, int dataSize); // Compute SHA256 hash code, returns static int[8] (32 bytes) +RLAPI unsigned int ComputeCRC32(unsigned char *data, int dataSize); // Compute CRC32 hash code +RLAPI unsigned int *ComputeMD5(unsigned char *data, int dataSize); // Compute MD5 hash code, returns static int[4] (16 bytes) +RLAPI unsigned int *ComputeSHA1(unsigned char *data, int dataSize); // Compute SHA1 hash code, returns static int[5] (20 bytes) +RLAPI unsigned int *ComputeSHA256(unsigned char *data, int dataSize); // Compute SHA256 hash code, returns static int[8] (32 bytes) // Automation events functionality RLAPI AutomationEventList LoadAutomationEventList(const char *fileName); // Load automation events list from file, NULL for empty list, capacity = MAX_AUTOMATION_EVENTS @@ -1279,10 +1279,10 @@ RLAPI void DrawLineStrip(const Vector2 *points, int pointCount, Color color); RLAPI void DrawLineBezier(Vector2 startPos, Vector2 endPos, float thick, Color color); // Draw line segment cubic-bezier in-out interpolation RLAPI void DrawLineDashed(Vector2 startPos, Vector2 endPos, int dashSize, int spaceSize, Color color); // Draw a dashed line RLAPI void DrawCircle(int centerX, int centerY, float radius, Color color); // Draw a color-filled circle -RLAPI void DrawCircleSector(Vector2 center, float radius, float startAngle, float endAngle, int segments, Color color); // Draw a piece of a circle -RLAPI void DrawCircleSectorLines(Vector2 center, float radius, float startAngle, float endAngle, int segments, Color color); // Draw circle sector outline -RLAPI void DrawCircleGradient(int centerX, int centerY, float radius, Color inner, Color outer); // Draw a gradient-filled circle RLAPI void DrawCircleV(Vector2 center, float radius, Color color); // Draw a color-filled circle (Vector version) +RLAPI void DrawCircleGradient(Vector2 center, float radius, Color inner, Color outer); // Draw a gradient-filled circle +RLAPI void DrawCircleSector(Vector2 center, float radius, float startAngle, float endAngle, int segments, Color color); // Draw a piece of a circle +RLAPI void DrawCircleSectorLines(Vector2 center, float radius, float startAngle, float endAngle, int segments, Color color); // Draw circle sector outline RLAPI void DrawCircleLines(int centerX, int centerY, float radius, Color color); // Draw circle outline RLAPI void DrawCircleLinesV(Vector2 center, float radius, Color color); // Draw circle outline (Vector version) RLAPI void DrawEllipse(int centerX, int centerY, float radiusH, float radiusV, Color color); // Draw ellipse @@ -1290,7 +1290,7 @@ RLAPI void DrawEllipseV(Vector2 center, float radiusH, float radiusV, Color colo RLAPI void DrawEllipseLines(int centerX, int centerY, float radiusH, float radiusV, Color color); // Draw ellipse outline RLAPI void DrawEllipseLinesV(Vector2 center, float radiusH, float radiusV, Color color); // Draw ellipse outline (Vector version) RLAPI void DrawRing(Vector2 center, float innerRadius, float outerRadius, float startAngle, float endAngle, int segments, Color color); // Draw ring -RLAPI void DrawRingLines(Vector2 center, float innerRadius, float outerRadius, float startAngle, float endAngle, int segments, Color color); // Draw ring outline +RLAPI void DrawRingLines(Vector2 center, float innerRadius, float outerRadius, float startAngle, float endAngle, int segments, Color color); // Draw ring outline RLAPI void DrawRectangle(int posX, int posY, int width, int height, Color color); // Draw a color-filled rectangle RLAPI void DrawRectangleV(Vector2 position, Vector2 size, Color color); // Draw a color-filled rectangle (Vector version) RLAPI void DrawRectangleRec(Rectangle rec, Color color); // Draw a color-filled rectangle @@ -1539,11 +1539,11 @@ RLAPI const char *TextSubtext(const char *text, int position, int length); RLAPI const char *TextRemoveSpaces(const char *text); // Remove text spaces, concat words RLAPI char *GetTextBetween(const char *text, const char *begin, const char *end); // Get text between two strings RLAPI char *TextReplace(const char *text, const char *search, const char *replacement); // Replace text string with new string -RLAPI char *TextReplaceAlloc(const char *text, const char *search, const char *replacement); // Replace text string with new string, memory must be MemFree() +RLAPI char *TextReplaceAlloc(const char *text, const char *search, const char *replacement); // Replace text string with new string, memory must be MemFree() RLAPI char *TextReplaceBetween(const char *text, const char *begin, const char *end, const char *replacement); // Replace text between two specific strings RLAPI char *TextReplaceBetweenAlloc(const char *text, const char *begin, const char *end, const char *replacement); // Replace text between two specific strings, memory must be MemFree() RLAPI char *TextInsert(const char *text, const char *insert, int position); // Insert text in a defined byte position -RLAPI char *TextInsertAlloc(const char *text, const char *insert, int position); // Insert text in a defined byte position, memory must be MemFree() +RLAPI char *TextInsertAlloc(const char *text, const char *insert, int position); // Insert text in a defined byte position, memory must be MemFree() RLAPI char *TextJoin(char **textList, int count, const char *delimiter); // Join text strings with delimiter RLAPI char **TextSplit(const char *text, char delimiter, int *count); // Split text into multiple strings, using MAX_TEXTSPLIT_COUNT static strings RLAPI void TextAppend(char *text, const char *append, int *position); // Append text at specific position and move cursor @@ -1600,7 +1600,7 @@ RLAPI void DrawModelEx(Model model, Vector3 position, Vector3 rotationAxis, floa RLAPI void DrawModelWires(Model model, Vector3 position, float scale, Color tint); // Draw a model wires (with texture if set) RLAPI void DrawModelWiresEx(Model model, Vector3 position, Vector3 rotationAxis, float rotationAngle, Vector3 scale, Color tint); // Draw a model wires (with texture if set) with extended parameters RLAPI void DrawBoundingBox(BoundingBox box, Color color); // Draw bounding box (wires) -RLAPI void DrawBillboard(Camera camera, Texture2D texture, Vector3 position, float scale, Color tint); // Draw a billboard texture +RLAPI void DrawBillboard(Camera camera, Texture2D texture, Vector3 position, float scale, Color tint); // Draw a billboard texture RLAPI void DrawBillboardRec(Camera camera, Texture2D texture, Rectangle source, Vector3 position, Vector2 size, Color tint); // Draw a billboard texture defined by source RLAPI void DrawBillboardPro(Camera camera, Texture2D texture, Rectangle source, Vector3 position, Vector3 up, Vector2 size, Vector2 origin, float rotation, Color tint); // Draw a billboard texture defined by source and rotation diff --git a/lib/raylib.zig b/lib/raylib.zig index 8ddb53b..8ca1f6f 100644 --- a/lib/raylib.zig +++ b/lib/raylib.zig @@ -3801,6 +3801,16 @@ pub fn drawCircle(centerX: i32, centerY: i32, radius: f32, color: Color) void { cdef.DrawCircle(@as(c_int, centerX), @as(c_int, centerY), radius, color); } +/// Draw a color-filled circle (Vector version) +pub fn drawCircleV(center: Vector2, radius: f32, color: Color) void { + cdef.DrawCircleV(center, radius, color); +} + +/// Draw a gradient-filled circle +pub fn drawCircleGradient(center: Vector2, radius: f32, inner: Color, outer: Color) void { + cdef.DrawCircleGradient(center, radius, inner, outer); +} + /// Draw a piece of a circle pub fn drawCircleSector(center: Vector2, radius: f32, startAngle: f32, endAngle: f32, segments: i32, color: Color) void { cdef.DrawCircleSector(center, radius, startAngle, endAngle, @as(c_int, segments), color); @@ -3811,16 +3821,6 @@ pub fn drawCircleSectorLines(center: Vector2, radius: f32, startAngle: f32, endA cdef.DrawCircleSectorLines(center, radius, startAngle, endAngle, @as(c_int, segments), color); } -/// Draw a gradient-filled circle -pub fn drawCircleGradient(centerX: i32, centerY: i32, radius: f32, inner: Color, outer: Color) void { - cdef.DrawCircleGradient(@as(c_int, centerX), @as(c_int, centerY), radius, inner, outer); -} - -/// Draw a color-filled circle (Vector version) -pub fn drawCircleV(center: Vector2, radius: f32, color: Color) void { - cdef.DrawCircleV(center, radius, color); -} - /// Draw circle outline pub fn drawCircleLines(centerX: i32, centerY: i32, radius: f32, color: Color) void { cdef.DrawCircleLines(@as(c_int, centerX), @as(c_int, centerY), radius, color); diff --git a/lib/raymath.h b/lib/raymath.h index 8a0cce1..9398258 100644 --- a/lib/raymath.h +++ b/lib/raymath.h @@ -15,7 +15,7 @@ * - Functions use always a "result" variable for return (except C++ operators) * - Functions are always defined inline * - Angles are always in radians (DEG2RAD/RAD2DEG macros provided for convenience) -* - No compound literals used to make sure libray is compatible with C++ +* - No compound literals used to make sure the library is compatible with C++ * * CONFIGURATION: * #define RAYMATH_IMPLEMENTATION @@ -183,7 +183,7 @@ typedef struct float16 { #if RAYMATH_USE_SIMD_INTRINSICS // SIMD is used on the most costly raymath function MatrixMultiply() // NOTE: Only SSE intrinsics support implemented - // TODO: Consider support for other SIMD instrinsics: + // TODO: Consider support for other SIMD intrinsics: // - SSEx, AVX, AVX2, FMA, NEON, RVV /* #if defined(__SSE4_2__) @@ -1151,7 +1151,7 @@ RMAPI Vector3 Vector3Unproject(Vector3 source, Matrix projection, Matrix view) // Create quaternion from source point Quaternion quat = { source.x, source.y, source.z, 1.0f }; - // Multiply quat point by unprojecte matrix + // Multiply quat point by unprojected matrix Quaternion qtransformed = { // QuaternionTransform(quat, matViewProjInv) matViewProjInv.m0*quat.x + matViewProjInv.m4*quat.y + matViewProjInv.m8*quat.z + matViewProjInv.m12*quat.w, matViewProjInv.m1*quat.x + matViewProjInv.m5*quat.y + matViewProjInv.m9*quat.z + matViewProjInv.m13*quat.w, @@ -1264,19 +1264,21 @@ RMAPI Vector3 Vector3Refract(Vector3 v, Vector3 n, float r) //---------------------------------------------------------------------------------- // Module Functions Definition - Vector4 math //---------------------------------------------------------------------------------- - +// Get vector zero RMAPI Vector4 Vector4Zero(void) { Vector4 result = { 0.0f, 0.0f, 0.0f, 0.0f }; return result; } +// Get vector one RMAPI Vector4 Vector4One(void) { Vector4 result = { 1.0f, 1.0f, 1.0f, 1.0f }; return result; } +// Add two vectors RMAPI Vector4 Vector4Add(Vector4 v1, Vector4 v2) { Vector4 result = { @@ -1288,6 +1290,7 @@ RMAPI Vector4 Vector4Add(Vector4 v1, Vector4 v2) return result; } +// Add value to vector components RMAPI Vector4 Vector4AddValue(Vector4 v, float add) { Vector4 result = { @@ -1299,6 +1302,7 @@ RMAPI Vector4 Vector4AddValue(Vector4 v, float add) return result; } +// Substract vectors RMAPI Vector4 Vector4Subtract(Vector4 v1, Vector4 v2) { Vector4 result = { @@ -1310,6 +1314,7 @@ RMAPI Vector4 Vector4Subtract(Vector4 v1, Vector4 v2) return result; } +// Substract value from vector components RMAPI Vector4 Vector4SubtractValue(Vector4 v, float add) { Vector4 result = { @@ -1321,18 +1326,21 @@ RMAPI Vector4 Vector4SubtractValue(Vector4 v, float add) return result; } +// Vector length RMAPI float Vector4Length(Vector4 v) { float result = sqrtf((v.x*v.x) + (v.y*v.y) + (v.z*v.z) + (v.w*v.w)); return result; } +// Vector square length RMAPI float Vector4LengthSqr(Vector4 v) { float result = (v.x*v.x) + (v.y*v.y) + (v.z*v.z) + (v.w*v.w); return result; } +// Vectors dot product RMAPI float Vector4DotProduct(Vector4 v1, Vector4 v2) { float result = (v1.x*v2.x + v1.y*v2.y + v1.z*v2.z + v1.w*v2.w); @@ -1358,6 +1366,7 @@ RMAPI float Vector4DistanceSqr(Vector4 v1, Vector4 v2) return result; } +// Scale vector components by value (multiply) RMAPI Vector4 Vector4Scale(Vector4 v, float scale) { Vector4 result = { v.x*scale, v.y*scale, v.z*scale, v.w*scale }; @@ -1753,13 +1762,14 @@ RMAPI Matrix MatrixMultiply(Matrix left, Matrix right) return result; } +// Multiply matrix components by value RMAPI Matrix MatrixMultiplyValue(Matrix left, float value) { Matrix result = { - left.m0 * value, left.m4 * value, left.m8 * value, left.m12 * value, - left.m1 * value, left.m5 * value, left.m9 * value, left.m13 * value, - left.m2 * value, left.m6 * value, left.m10 * value, left.m14 * value, - left.m3 * value, left.m7 * value, left.m11 * value, left.m15 * value + left.m0*value, left.m4*value, left.m8*value, left.m12*value, + left.m1*value, left.m5*value, left.m9*value, left.m13*value, + left.m2*value, left.m6*value, left.m10*value, left.m14*value, + left.m3*value, left.m7*value, left.m11*value, left.m15*value }; return result; @@ -2495,19 +2505,14 @@ RMAPI Quaternion QuaternionFromAxisAngle(Vector3 axis, float angle) { Quaternion result = { 0.0f, 0.0f, 0.0f, 1.0f }; - float axisLength = sqrtf(axis.x*axis.x + axis.y*axis.y + axis.z*axis.z); + float length = sqrtf(axis.x*axis.x + axis.y*axis.y + axis.z*axis.z); - if (axisLength != 0.0f) + if (length != 0.0f) { angle *= 0.5f; - float length = 0.0f; - float ilength = 0.0f; - // Vector3Normalize(axis) - length = axisLength; - if (length == 0.0f) length = 1.0f; - ilength = 1.0f/length; + float ilength = 1.0f/length; axis.x *= ilength; axis.y *= ilength; axis.z *= ilength; diff --git a/lib/rlgl.h b/lib/rlgl.h index e97bad3..5c6e95a 100644 --- a/lib/rlgl.h +++ b/lib/rlgl.h @@ -7,10 +7,10 @@ * that provides a pseudo-OpenGL 1.1 immediate-mode style API (rlVertex, rlTranslate, rlRotate...) * * ADDITIONAL NOTES: -* When choosing an OpenGL backend different than OpenGL 1.1, some internal buffer are +* When choosing an OpenGL backend different than OpenGL 1.1, some internal buffers are * initialized on rlglInit() to accumulate vertex data * -* When an internal state change is required all the stored vertex data is rendered in batch, +* When an internal state change is required all the stored vertex data is rendered in a batch, * additionally, rlDrawRenderBatchActive() could be called to force flushing of the batch * * Some resources are also loaded for convenience, here the complete list: @@ -29,7 +29,7 @@ * #define GRAPHICS_API_OPENGL_ES2 * #define GRAPHICS_API_OPENGL_ES3 * Use selected OpenGL graphics backend, should be supported by platform -* Those preprocessor defines are only used on rlgl module, if OpenGL version is +* Those preprocessor defines are only used on the rlgl module, if OpenGL version is * required by any other module, use rlGetVersion() to check it * * #define RLGL_IMPLEMENTATION @@ -49,7 +49,7 @@ * #define RL_DEFAULT_BATCH_BUFFER_ELEMENTS 8192 // Default internal render batch elements limits * #define RL_DEFAULT_BATCH_BUFFERS 1 // Default number of batch buffers (multi-buffering) * #define RL_DEFAULT_BATCH_DRAWCALLS 256 // Default number of batch draw calls (by state changes: mode, texture) -* #define RL_DEFAULT_BATCH_MAX_TEXTURE_UNITS 4 // Maximum number of textures units that can be activated on batch drawing (SetShaderValueTexture()) +* #define RL_DEFAULT_BATCH_MAX_TEXTURE_UNITS 4 // Maximum number of texture units that can be activated on batch drawing (SetShaderValueTexture()) * * #define RL_MAX_MATRIX_STACK_SIZE 32 // Maximum size of internal Matrix stack * #define RL_MAX_SHADER_LOCATIONS 32 // Maximum number of shader locations supported @@ -1015,9 +1015,7 @@ RLAPI void rlLoadDrawQuad(void); // Load and draw a quad #ifndef RL_DEFAULT_SHADER_ATTRIB_NAME_BONEWEIGHTS #define RL_DEFAULT_SHADER_ATTRIB_NAME_BONEWEIGHTS "vertexBoneWeights" // Bound by default to shader location: RL_DEFAULT_SHADER_ATTRIB_LOCATION_BONEWEIGHTS #endif -#ifndef RL_DEFAULT_SHADER_UNIFORM_NAME_BONEMATRICES - #define RL_DEFAULT_SHADER_UNIFORM_NAME_BONEMATRICES "boneMatrices" // Bound by default to shader location: RL_DEFAULT_SHADER_ATTRIB_LOCATION_BONEMATRICES -#endif + #ifndef RL_DEFAULT_SHADER_ATTRIB_NAME_INSTANCETRANSFORM #define RL_DEFAULT_SHADER_ATTRIB_NAME_INSTANCETRANSFORM "instanceTransform" // Bound by default to shader location: RL_DEFAULT_SHADER_ATTRIB_LOCATION_INSTANCETRANSFORM #endif @@ -1141,21 +1139,23 @@ typedef struct rlglData { //---------------------------------------------------------------------------------- // Global Variables Definition //---------------------------------------------------------------------------------- +static bool isGpuReady = false; static double rlCullDistanceNear = RL_CULL_DISTANCE_NEAR; static double rlCullDistanceFar = RL_CULL_DISTANCE_FAR; #if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2) static rlglData RLGL = { 0 }; -#endif // GRAPHICS_API_OPENGL_33 || GRAPHICS_API_OPENGL_ES2 -static bool isGpuReady = false; +#endif #if defined(GRAPHICS_API_OPENGL_ES2) && !defined(GRAPHICS_API_OPENGL_ES3) +// VAO functions entry points // NOTE: VAO functionality is exposed through extensions (OES) static PFNGLGENVERTEXARRAYSOESPROC glGenVertexArrays = NULL; static PFNGLBINDVERTEXARRAYOESPROC glBindVertexArray = NULL; static PFNGLDELETEVERTEXARRAYSOESPROC glDeleteVertexArrays = NULL; -// NOTE: Instancing functionality could also be available through extension +// Instancing functionality entry points +// NOTE: Instancing functionality could be available through extensions static PFNGLDRAWARRAYSINSTANCEDEXTPROC glDrawArraysInstanced = NULL; static PFNGLDRAWELEMENTSINSTANCEDEXTPROC glDrawElementsInstanced = NULL; static PFNGLVERTEXATTRIBDIVISOREXTPROC glVertexAttribDivisor = NULL; @@ -3687,6 +3687,8 @@ void rlUnloadTexture(unsigned int id) // NOTE: Only supports GPU mipmap generation void rlGenTextureMipmaps(unsigned int id, int width, int height, int format, int *mipmaps) { + if (!isGpuReady) { TRACELOG(RL_LOG_WARNING, "GL: GPU is not ready to load data, trying to load before InitWindow()?"); return; } + #if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2) glBindTexture(GL_TEXTURE_2D, id);