make resource embedding more cross platform

This commit is contained in:
sam 2024-09-02 17:18:27 +12:00
parent 8720b2db3b
commit 1bcf149b8e
5 changed files with 13831 additions and 7 deletions

BIN
.DS_Store vendored Normal file

Binary file not shown.

View file

@ -6,16 +6,17 @@ CFLAGS=-I. -Iinclude -Wall -Wextra -Werror -Wno-header-guard -Wno-comment -g
LDFLAGS=-g
SHADER_FLAGS=--slang glsl430:hlsl5:metal_macos
C_FILES=$(shell find -L * -type f -name '*.c')
C_FILES=$(shell find -L src -type f -name '*.c')
C_OBJ=$(C_FILES:.c=.o)
SHADER_FILES=$(shell find -L * -type f -name '*.glsl')
SHADER_OBJ=$(SHADER_FILES:.glsl=.glsl.h)
RESOURCES_DIR=res
RESOURCES_C=$(RESOURCES_DIR)/res.c
RESOURCES_OBJ=$(RESOURCES_DIR)/res.o
RESOURCES_H=include/gear/resources.h
RESOURCE_FILES=$(shell find -L $(RESOURCES_DIR) -type f -not -wholename $(RESOURCES_OBJ))
RESOURCE_FILES=$(shell find -L res -type f -not -name '*.o' -not -name '*.c')
ifeq ($(CC), gcc)
CFLAGS += -Wno-use-after-free
@ -41,17 +42,21 @@ endif
.PHONY: shaders resources
$(BINARY): shaders resources $(RESOURCES_OBJ) $(C_OBJ) $(OBJC_OBJ)
$(BINARY): shaders resources $(C_OBJ) $(OBJC_OBJ)
$(CC) $(C_OBJ) $(OBJC_OBJ) $(RESOURCES_OBJ) $(LDFLAGS) -o $(BINARY)
shaders: $(SHADER_OBJ)
@echo Shaders compiled
resources:
$(LD) -r -b binary -o $(RESOURCES_OBJ) $(RESOURCE_FILES)
@echo "// Generated resource file" > res/res.c
$(foreach res, $(RESOURCE_FILES), xxd -i $(res) >> $(RESOURCES_C);)
$(CC) -o $(RESOURCES_OBJ) -c $(RESOURCES_C)
@echo "#ifndef __G_RESOURCES_H__" > $(RESOURCES_H)
@echo "#define __G_RESOURCES_H__" >> $(RESOURCES_H)
@nm -j $(RESOURCES_OBJ) | awk '{ print "extern char " $$0 "[];" }' >> $(RESOURCES_H)
@nm -g -j $(RESOURCES_OBJ) | \
awk '{ if($$0 ~ /len$$/) { print "extern int " substr($$0, 2) ";" } else { print "extern char " substr($$0, 2) "[];" } }' >> $(RESOURCES_H)
@echo "#endif" >> $(RESOURCES_H)
@echo Resources compiled

13818
res/res.c Normal file

File diff suppressed because it is too large Load diff

View file

@ -2,6 +2,7 @@
#include "gear/base.h"
#include "gear/graphics/pipeline.h"
#include "gear/images.h"
#define SL_IMPLEMENTATION
#include "slibs/slibs.h"
#include <gear/graphics/renderer.h>
#include <gear/camera.h>

View file

@ -37,8 +37,8 @@ g_gui* g_gui_create() {
config.pixel_snap = true;
g_gui_font = nk_font_atlas_add_from_memory(atlas,
_binary_res_OpenSans_Regular_ttf_start,
_binary_res_OpenSans_Regular_ttf_end - _binary_res_OpenSans_Regular_ttf_start,
res_OpenSans_Regular_ttf,
res_OpenSans_Regular_ttf_len,
font_size, &config);
i32 atlas_width, atlas_height;