From 0fb57c082c1362196e2abd09e9c37fdc818edd7c Mon Sep 17 00:00:00 2001 From: Freya Murphy Date: Mon, 10 Nov 2025 23:27:40 -0500 Subject: graphics: add feature to include assets statically in the binary --- graphics/Cargo.toml | 5 +++-- graphics/src/render.rs | 29 +++++++++++++++++++++++++---- 2 files changed, 28 insertions(+), 6 deletions(-) (limited to 'graphics') diff --git a/graphics/Cargo.toml b/graphics/Cargo.toml index e898b04..0fe31d0 100644 --- a/graphics/Cargo.toml +++ b/graphics/Cargo.toml @@ -16,8 +16,9 @@ workspace = true [features] default = [] -wayland = ["raylib/GLFW_BUILD_WAYLAND", "raylib/wayland"] -sdl = ["raylib/sdl"] +wayland = ["raylib/wayland", "raylib/GLFW_BUILD_WAYLAND"] +sdl = ["raylib/sdl", "raylib/SUPPORT_MODULE_RTEXT"] +static = [] # Individual features seem to currently be # broken on windows diff --git a/graphics/src/render.rs b/graphics/src/render.rs index 945528b..bbfa2b9 100644 --- a/graphics/src/render.rs +++ b/graphics/src/render.rs @@ -46,6 +46,27 @@ macro_rules! draw_text { }}; } +#[cfg(not(feature = "static"))] +macro_rules! load_texture { + ($handle:expr, $thread:expr, $filepath:expr) => ( + $handle.load_texture($thread, $filepath)? + ) +} + +#[cfg(feature = "static")] +macro_rules! load_texture { + ($handle:expr, $thread:expr, $filepath:expr) => ( + { + let bytes = include_bytes!(concat!("../../", $filepath)); + let len = $filepath.len(); + let ext = &$filepath[len-4..]; + let image = ::raylib::texture::Image::load_image_from_mem(ext, bytes)?; + $handle.load_texture_from_image($thread, &image)? + } + + ) +} + /// The baseline size of all ingame sprites and tile textures const TEXTURE_SIZE: u16 = 16; @@ -121,10 +142,10 @@ struct Textures { } impl Textures { fn new(handle: &mut RaylibHandle, thread: &RaylibThread) -> crate::Result { - let atlas = handle.load_texture(thread, "assets/atlas.bmp")?; - let player = handle.load_texture(thread, "assets/player.bmp")?; - let error = handle.load_texture(thread, "assets/error.bmp")?; - let font = handle.load_texture(thread, "assets/font.bmp")?; + let atlas = load_texture!(handle, thread, "assets/atlas.bmp"); + let player = load_texture!(handle, thread, "assets/player.bmp"); + let error = load_texture!(handle, thread, "assets/error.bmp"); + let font = load_texture!(handle, thread, "assets/font.bmp"); Ok(Self { atlas, -- cgit v1.2.3-freya