aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomasz Kramkowski <tk@the-tk.com>2018-03-28 00:17:30 +0100
committerTomasz Kramkowski <tk@the-tk.com>2018-03-28 00:18:53 +0100
commit768feb8bf10807142ff1f21d29f7492509362a18 (patch)
tree5adad2a4791c5c100c934e01d70c089d0b6002ed
parentf68b69f5d2e99143d371c6e50ca28f0d5ff739c5 (diff)
downloadfaqe-768feb8bf10807142ff1f21d29f7492509362a18.tar.gz
faqe-768feb8bf10807142ff1f21d29f7492509362a18.tar.xz
faqe-768feb8bf10807142ff1f21d29f7492509362a18.zip
Move to using bie for assets
Shaders are now stored in a bie flat archive and indexed via assets.c and assets.h.
-rw-r--r--.gitignore2
-rw-r--r--Makefile17
-rw-r--r--assets.c6
-rw-r--r--assets.h15
-rw-r--r--assets.mk9
-rw-r--r--gltest.c6
-rw-r--r--shaders.h20
7 files changed, 44 insertions, 31 deletions
diff --git a/.gitignore b/.gitignore
index 8fd08ee..8365d9f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -12,5 +12,7 @@ eprintf.h
eprintf.c
loadgl.h
loadgl.c
+assets.bie
+assets.idx
config.mk
diff --git a/Makefile b/Makefile
index 1f026a1..737ef79 100644
--- a/Makefile
+++ b/Makefile
@@ -14,25 +14,26 @@ CFLAGS += $(shell $(PKG_CONFIG) --cflags $(LIBS)) -std=c11 -MMD -MP
LDFLAGS += -Wl,--as-needed
LDLIBS += $(shell $(PKG_CONFIG) --libs $(LIBS)) -lm
-OBJ := gltest.o loadgl.o eprintf.o vert.o frag.o glprog.o
-DEP := $(OBJ:.o=.d)
-
-%.o: %.glsl
- $(LD) -r -b binary $(OUTPUT_OPTION) $<
+OBJ := gltest.o loadgl.o eprintf.o glprog.o assets.o assets_data.o
all: $(PROG)
$(PROG): $(OBJ)
-clean:
- $(RM) $(OBJ) $(DEP) $(PROG) $(CLEAN)
-
+gltest.o: assets.h
loadgl.o gltest.o glprog.o: loadgl.h
loadgl.c loadgl.h: loadgl.%: loadgl.m4 loadgl.%.in
m4 $^ >$@
CLEAN += loadgl.c loadgl.h
+include assets.mk
+
include $(EPRINTF_PATH)/module.mk
deplinks: $(EPRINTF_FILES)
+DEP := $(OBJ:.o=.d)
+
+clean:
+ $(RM) $(OBJ) $(DEP) $(PROG) $(CLEAN)
+
-include $(DEP)
.PHONY: all clean
diff --git a/assets.c b/assets.c
new file mode 100644
index 0000000..ed90df9
--- /dev/null
+++ b/assets.c
@@ -0,0 +1,6 @@
+#include "assets.h"
+
+extern char _binary_assets_bie_start[];
+
+#define BIE_ENTRY(name, pos, size) struct asset name = { &_binary_assets_bie_start[pos], size };
+#include "assets.idx"
diff --git a/assets.h b/assets.h
new file mode 100644
index 0000000..4fe44c9
--- /dev/null
+++ b/assets.h
@@ -0,0 +1,15 @@
+#ifndef ASSETS_H
+#define ASSETS_H
+
+#include <stddef.h>
+
+struct asset {
+ void *data;
+ size_t size;
+};
+
+#define BIE_ENTRY(name, pos, size) extern struct asset name;
+#include "assets.idx"
+#undef BIE_ENTRY
+
+#endif // ASSETS_H
diff --git a/assets.mk b/assets.mk
new file mode 100644
index 0000000..27c502f
--- /dev/null
+++ b/assets.mk
@@ -0,0 +1,9 @@
+ASSETS := vert.glsl frag.glsl
+
+assets.o: assets.h
+assets.h assets.c: assets.idx
+assets.bie assets.idx: $(ASSETS)
+ bie assets.bie assets.idx $^
+assets_data.o: assets.bie
+ $(LD) -r -b binary $(OUTPUT_OPTION) $<
+CLEAN += assets.bie assets.idx
diff --git a/gltest.c b/gltest.c
index 5b1d4fc..335b4af 100644
--- a/gltest.c
+++ b/gltest.c
@@ -5,12 +5,12 @@
#include <GLFW/glfw3.h>
#include <stdbool.h>
+#include "assets.h"
#include "eprintf.h"
#include "gldefs.h"
#include "glprog.h"
#include "linmath.h"
#include "loadgl.h"
-#include "shaders.h"
#include "nelem.h"
enum {
@@ -90,8 +90,8 @@ int main(int argc, char **argv)
gl_va_enable(2);
prog = glprog_load(2, (struct shdrdat []){
- { GL_VERTEX_SHADER, shader_vert_data, shader_vert_size },
- { GL_FRAGMENT_SHADER, shader_frag_data, shader_frag_size },
+ { GL_VERTEX_SHADER, vert_glsl.data, vert_glsl.size },
+ { GL_FRAGMENT_SHADER, frag_glsl.data, frag_glsl.size },
},
1, &(struct unidat){ "ucolor", &ucolor });
diff --git a/shaders.h b/shaders.h
deleted file mode 100644
index 4a388e5..0000000
--- a/shaders.h
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- * Copyright (C) 2018 Tomasz Kramkowski <tk@the-tk.com>
- * SPDX-License-Identifier: MIT
- */
-#ifndef SHADERS_H
-#define SHADERS_H
-
-#include <stddef.h>
-
-extern char _binary_vert_glsl_start[];
-extern char _binary_vert_glsl_end[];
-#define shader_vert_data _binary_vert_glsl_start
-#define shader_vert_size (_binary_vert_glsl_end - _binary_vert_glsl_start)
-
-extern char _binary_frag_glsl_start[];
-extern char _binary_frag_glsl_end[];
-#define shader_frag_data _binary_frag_glsl_start
-#define shader_frag_size (_binary_frag_glsl_end - _binary_frag_glsl_start)
-
-#endif // SHADERS_H