Commit: d933b1810886de1500e47111a7083ff5c3aa9959
Parent: 5a3fdd7fcfeb641f1976e86823e1b62494e56388
Author: Randy Palamar
Date: Sat, 28 Mar 2026 07:13:26 -0600
build: remove objcopy shader embedding
this is not really portable. instead, its trivial to just embed
the shader as a byte array which is obviously supported
everywhere.
Diffstat:
4 files changed, 36 insertions(+), 26 deletions(-)
diff --git a/build.sh b/build.sh
@@ -4,9 +4,7 @@ version=1.0
cflags=${CFLAGS:-"-march=native -O3"}
cflags="${cflags} -std=c11 "
-ldflags=${LDFLAGS}
-# TODO(rnp): embed shader without lto stripping it */
-ldflags="${ldflags} -fno-lto -lm"
+ldflags="${LDFLAGS} -flto -lm"
output="colourpicker"
@@ -18,7 +16,7 @@ for arg; do
esac
done
-machine=$(uname -m)
+mkdir -p out
case $(uname -s) in
MINGW64*)
@@ -26,16 +24,6 @@ MINGW64*)
output="Colour Picker"
windres assets/colourpicker.rc out/colourpicker.rc.o
ldflags="out/colourpicker.rc.o ${ldflags} -mwindows -lgdi32 -lwinmm"
- case ${machine} in
- x86_64) binary_format="pe-x86-64" ;;
- *) binary_format="pe-${machine}" ;;
- esac
- ;;
-*)
- case ${machine} in
- aarch64) binary_format="elf64-littleaarch64" ;;
- x86_64) binary_format="elf64-x86-64" ;;
- esac
;;
esac
@@ -77,7 +65,6 @@ fi
[ ! -s "config.h" ] && cp config.def.h config.h
-mkdir -p out
raylib=out/libraylib.a
[ ${debug} ] && raylib="libraylib.so"
[ "./build.sh" -nt ${raylib} ] || [ ! -f ${raylib} ] && build_raylib
@@ -95,10 +82,7 @@ if [ "$debug" ]; then
${cc} ${cflags} -fPIC -shared colourpicker.c -o colourpicker.so
ldflags="${ldflags} -Wl,-rpath,. ${raylib}"
else
- if [ ! -s "out/slider_lerp.o" ] || [ "slider_lerp.glsl" -nt "out/slider_lerp.o" ]; then
- objcopy --input-target=binary slider_lerp.glsl --output-target=${binary_format} out/slider_lerp.o
- fi
- ldflags="${raylib} out/slider_lerp.o ${ldflags}"
+ ldflags="${raylib} ${ldflags}"
fi
${cc} ${cflags} -DVERSION="\"${version}\"" main.c -o "${output}" ${ldflags}
diff --git a/colourpicker.c b/colourpicker.c
@@ -1167,7 +1167,7 @@ colour_picker_init(ColourPickerCtx *ctx)
#ifdef _DEBUG
ctx->picker_shader = LoadShader(0, HSV_LERP_SHADER_NAME);
#else
- ctx->picker_shader = LoadShaderFromMemory(0, _binary_slider_lerp_glsl_start);
+ ctx->picker_shader = LoadShaderFromMemory(0, (char *)slider_lerp_bytes);
#endif
ctx->mode_id = GetShaderLocation(ctx->picker_shader, "u_mode");
ctx->colour_mode_id = GetShaderLocation(ctx->picker_shader, "u_colour_mode");
diff --git a/gen_incs.c b/gen_incs.c
@@ -13,7 +13,6 @@
#include <stdlib.h>
#include <string.h>
-
#define ISSPACE(a) ((a) == ' ' || (a) == '\t')
function str8
@@ -129,6 +128,35 @@ export_font_as_code(char *font_path, char *output_name, int font_size, str8 mem)
fclose(fp);
}
+function void
+generate_shader_include(str8 memory)
+{
+ str8 raw = read_whole_file(HSV_LERP_SHADER_NAME, &memory);
+ // NOTE(rnp): raylib is dumb and wants this to be 0 terminated
+ raw.data[raw.length++] = 0;
+
+ char *output_name = "out/shader_inc.h";
+ FILE *fp = fopen(output_name, "w");
+ if (fp == NULL) {
+ printf("Failed to open output font file: %s\n", output_name);
+ exit(1);
+ }
+
+ fprintf(fp, "/* See LICENSE for copyright details */\n\n");
+ fprintf(fp, "// GENERATED CODE\n\n");
+ fprintf(fp, "read_only global u8 slider_lerp_bytes[] = {\n");
+ for (s64 i = 0; i < raw.length; i++) {
+ b32 end_line = (i != 0) && (i % 16) == 0;
+ if (i != 0) fprintf(fp, end_line ? "," : ", ");
+ if (end_line) fprintf(fp, "\n");
+ if ((i % 16) == 0) fprintf(fp, "\t");
+ fprintf(fp, "0x%02X", raw.data[i]);
+ }
+ fprintf(fp, ", 0x00\n");
+ fprintf(fp, "\n};\n");
+ fclose(fp);
+}
+
extern s32
main(void)
{
@@ -146,5 +174,7 @@ main(void)
export_font_as_code("assets/Lora-SemiBold.ttf", (char *)tmem.data, font_sizes[i], rmem);
}
+ generate_shader_include(smem);
+
return 0;
}
diff --git a/util.c b/util.c
@@ -9,13 +9,9 @@
#include "lora_sb_0_inc.h"
#include "lora_sb_1_inc.h"
+#include "shader_inc.h"
#include "config.h"
-/* NOTE(rnp): symbols in release builds shaders are embedded in the binary */
-#ifndef _DEBUG
-extern char _binary_slider_lerp_glsl_start[];
-#endif
-
#define fmod_f32(a, b) __builtin_fmodf((a), (b))
#if ARCH_ARM64