diff --git a/src/build.zig b/src/build.zig index 8485322d5..64480a4f1 100644 --- a/src/build.zig +++ b/src/build.zig @@ -16,7 +16,10 @@ pub fn addRaylib(b: *std.Build, target: std.zig.CrossTarget, optimize: std.built }); raylib.linkLibC(); - raylib.addIncludePath(srcdir ++ "/external/glfw/include"); + // No GLFW required on PLATFORM_DRM + if (!options.platform_drm) { + raylib.addIncludePath(srcdir ++ "/external/glfw/include"); + } raylib.addCSourceFiles(&.{ srcdir ++ "/raudio.c", @@ -49,15 +52,32 @@ pub fn addRaylib(b: *std.Build, target: std.zig.CrossTarget, optimize: std.built raylib.defineCMacro("PLATFORM_DESKTOP", null); }, .linux => { - raylib.addCSourceFiles(&.{srcdir ++ "/rglfw.c"}, raylib_flags); - raylib.linkSystemLibrary("GL"); - raylib.linkSystemLibrary("rt"); - raylib.linkSystemLibrary("dl"); - raylib.linkSystemLibrary("m"); - raylib.linkSystemLibrary("X11"); - raylib.addIncludePath("/usr/include"); + if (!options.platform_drm) { + raylib.addCSourceFiles(&.{srcdir ++ "/rglfw.c"}, raylib_flags); + raylib.linkSystemLibrary("GL"); + raylib.linkSystemLibrary("rt"); + raylib.linkSystemLibrary("dl"); + raylib.linkSystemLibrary("m"); + raylib.linkSystemLibrary("X11"); + raylib.addIncludePath("/usr/include"); - raylib.defineCMacro("PLATFORM_DESKTOP", null); + raylib.defineCMacro("PLATFORM_DESKTOP", null); + } else { + raylib.linkSystemLibrary("GLESv2"); + raylib.linkSystemLibrary("EGL"); + raylib.linkSystemLibrary("drm"); + raylib.linkSystemLibrary("gbm"); + raylib.linkSystemLibrary("pthread"); + raylib.linkSystemLibrary("rt"); + raylib.linkSystemLibrary("m"); + raylib.linkSystemLibrary("dl"); + raylib.addIncludePath("/usr/include/libdrm"); + + raylib.defineCMacro("PLATFORM_DRM", null); + raylib.defineCMacro("GRAPHICS_API_OPENGL_ES2", null); + raylib.defineCMacro("EGL_NO_X11", null); + raylib.defineCMacro("DEFAULT_BATCH_BUFFER_ELEMENT", "2048"); + } }, .freebsd, .openbsd, .netbsd, .dragonfly => { raylib.addCSourceFiles(&.{srcdir ++ "/rglfw.c"}, raylib_flags); @@ -115,8 +135,9 @@ pub fn addRaylib(b: *std.Build, target: std.zig.CrossTarget, optimize: std.built return raylib; } -const Options = struct { +pub const Options = struct { raygui: bool = false, + platform_drm: bool = false, }; pub fn build(b: *std.Build) void { @@ -131,9 +152,11 @@ pub fn build(b: *std.Build) void { const optimize = b.standardOptimizeOption(.{}); const raygui = b.option(bool, "raygui", "Compile with raygui support"); + const platform_drm = b.option(bool, "platform_drm", "Compile raylib in native mode (no X11)"); const lib = addRaylib(b, target, optimize, .{ .raygui = raygui orelse false, + .platform_drm = platform_drm orelse false, }); lib.installHeader("src/raylib.h", "raylib.h"); diff --git a/src/raylib.h b/src/raylib.h index c20a69d2b..108ab0245 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -974,7 +974,7 @@ RLAPI int GetMonitorPhysicalHeight(int monitor); // Get specifi RLAPI int GetMonitorRefreshRate(int monitor); // Get specified monitor refresh rate RLAPI Vector2 GetWindowPosition(void); // Get window position XY on monitor RLAPI Vector2 GetWindowScaleDPI(void); // Get window scale DPI factor -RLAPI const char *GetMonitorName(int monitor); // Get the human-readable, UTF-8 encoded name of the primary monitor +RLAPI const char *GetMonitorName(int monitor); // Get the human-readable, UTF-8 encoded name of the specified monitor RLAPI void SetClipboardText(const char *text); // Set clipboard text content RLAPI const char *GetClipboardText(void); // Get clipboard text content RLAPI void EnableEventWaiting(void); // Enable waiting for events on EndDrawing(), no automatic event polling @@ -1588,7 +1588,7 @@ RLAPI void SetAudioStreamPan(AudioStream stream, float pan); // Set pan RLAPI void SetAudioStreamBufferSizeDefault(int size); // Default size for new audio streams RLAPI void SetAudioStreamCallback(AudioStream stream, AudioCallback callback); // Audio thread callback to request new data -RLAPI void AttachAudioStreamProcessor(AudioStream stream, AudioCallback processor); // Attach audio stream processor to stream +RLAPI void AttachAudioStreamProcessor(AudioStream stream, AudioCallback processor); // Attach audio stream processor to stream, receives the samples as s RLAPI void DetachAudioStreamProcessor(AudioStream stream, AudioCallback processor); // Detach audio stream processor from stream RLAPI void AttachAudioMixedProcessor(AudioCallback processor); // Attach audio stream processor to the entire audio pipeline, receives the samples as s diff --git a/src/rtextures.c b/src/rtextures.c index bc53e1cec..ca341bc81 100644 --- a/src/rtextures.c +++ b/src/rtextures.c @@ -3135,26 +3135,28 @@ void ImageDrawRectangleRec(Image *dst, Rectangle rec, Color color) if (rec.height < 0) rec.height = 0; int sy = (int)rec.y; - int ey = sy + (int)rec.height; - int sx = (int)rec.x; int bytesPerPixel = GetPixelDataSize(1, 1, dst->format); - for (int y = sy; y < ey; y++) + // Fill in the first pixel of the first row based on image format + ImageDrawPixel(dst, sx, sy, color); + + int bytesOffset = ((sy*dst->width) + sx)*bytesPerPixel; + unsigned char *pSrcPixel = (unsigned char *)dst->data + bytesOffset; + + // Repeat the first pixel data throughout the row + for (int x = 1; x < (int)rec.width; x++) { - // Fill in the first pixel of the row based on image format - ImageDrawPixel(dst, sx, y, color); - - int bytesOffset = ((y*dst->width) + sx)*bytesPerPixel; - unsigned char *pSrcPixel = (unsigned char *)dst->data + bytesOffset; - - // Repeat the first pixel data throughout the row - for (int x = 1; x < (int)rec.width; x++) - { - memcpy(pSrcPixel + x*bytesPerPixel, pSrcPixel, bytesPerPixel); - } + memcpy(pSrcPixel + x*bytesPerPixel, pSrcPixel, bytesPerPixel); } + + // Repeat the first row data for all other rows + int bytesPerRow = bytesPerPixel * (int)rec.width; + for (int y = 1; y < (int)rec.height; y++) + { + memcpy(pSrcPixel + (y*dst->width)*bytesPerPixel, pSrcPixel, bytesPerRow); + } } // Draw rectangle lines within an image