diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rwxr-xr-x | blob | 25 | ||||
-rwxr-xr-x | blobheader | 15 | ||||
-rw-r--r-- | makefile | 14 | ||||
-rw-r--r-- | shader.c | 8 |
5 files changed, 38 insertions, 25 deletions
@@ -2,3 +2,4 @@ main *_frag.* *_vert.* +*.spv @@ -0,0 +1,25 @@ +#!/bin/sh +input="$1" +base="$2" +symbol_base="$(echo "$base" | tr '[:punct:]' '_')" + +# assembly (used to compile data with custom symbol name) +cat << EOF > "$base.s" +.section .rodata +.global ${symbol_base}_head +${symbol_base}_head: +.incbin "$input" +EOF + +# C header +cat << EOF > "$base.h" +#pragma once +// NOTE: THIS FILE IS GENERATED, DO NOT EDIT +#include <stddef.h> + +extern const char ${symbol_base}_head; +const char* ${symbol_base} = &${symbol_base}_head; +const size_t ${symbol_base}_size = $(wc -c < "$input"); + +EOF + diff --git a/blobheader b/blobheader deleted file mode 100755 index c188205..0000000 --- a/blobheader +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/sh -source="$1" -symbol_base="$(echo "$source" | tr '[:punct:]' '_')" -cat << EOF -#pragma once -// NOTE: THIS FILE IS GENERATED, DO NOT EDIT -#include <stddef.h> - -extern char _binary_${symbol_base}_start; -extern char _binary_${symbol_base}_end; - -#define ${symbol_base} ((const char* const)(&_binary_${symbol_base}_start)) -#define ${symbol_base}_size ((size_t)(&_binary_${symbol_base}_end - &_binary_${symbol_base}_start)) - -EOF @@ -5,6 +5,7 @@ LDFLAGS += -lGLEW CFLAGS += -g .PHONY: FORCE +.SECONDARY: # do not remove intermediate files all: main FORCE @@ -18,12 +19,13 @@ main: hello_vert.o main.o: hello_vert.h main.o: hello_frag.h -%_frag.o %_frag.h &: %.frag - ld -r -b binary -o $*_frag.o $< - ./blobheader $< > $*_frag.h -%_vert.o %_vert.h &: %.vert - ld -r -b binary -o $*_vert.o $< - ./blobheader $< > $*_vert.h +%.s %.h &: %.spv + ./blob $< $* + +%_frag.spv: %.frag + glslc -o $@ $< +%_vert.spv: %.vert + glslc -o $@ $< clean: FORCE git clean -fxdi @@ -8,7 +8,7 @@ void check_shader(GLuint shader) { glGetShaderiv(shader, GL_COMPILE_STATUS, &success); if (success) return; glGetShaderInfoLog(shader, LOG_MAX, NULL, debug); - die("error: shader compilation failed:\n%s\n", debug); + die("error: shader compilation failed!\n%s", debug); } void check_program(GLuint program) { @@ -17,13 +17,13 @@ void check_program(GLuint program) { glGetProgramiv(program, GL_LINK_STATUS, &success); if (success) return; glGetProgramInfoLog(program, LOG_MAX, NULL, debug); - die("error: shader linking failed:\n%s\n", debug); + die("error: shader linking failed!\n%s", debug); } GLuint load_shader(GLenum type, const char* const src, size_t src_size) { GLuint shader = glCreateShader(type); - glShaderSource(shader, 1, &src, (const int*) &src_size); - glCompileShader(shader); + glShaderBinary(1, &shader, GL_SHADER_BINARY_FORMAT_SPIR_V_ARB, src, src_size); + glSpecializeShaderARB(shader, "main", 0, 0, 0); check_shader(shader); return shader; } |