From 08529a4a8e685637c1e733a6fff528a813d9a95c Mon Sep 17 00:00:00 2001 From: lonkaars Date: Sat, 18 May 2024 11:27:25 +0200 Subject: ensure same source --- .gitignore | 4 +--- main.c | 34 ++++++++++------------------------ makefile | 14 ++++++++++---- shader.frag | 8 ++++++++ shader.vert | 7 +++++++ spirv.frag | 8 -------- spirv.vert | 7 ------- 7 files changed, 36 insertions(+), 46 deletions(-) create mode 100644 shader.frag create mode 100644 shader.vert delete mode 100644 spirv.frag delete mode 100644 spirv.vert diff --git a/.gitignore b/.gitignore index 91e6b1a..b57f542 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,3 @@ *.o +*.h main -*_frag.* -*_vert.* -*.spv diff --git a/main.c b/main.c index 72c84ce..408a243 100644 --- a/main.c +++ b/main.c @@ -3,36 +3,22 @@ #include #include -// spir-v shaders: const uint32_t vert_spirv[] = -#include "spirv_vert.h" +#include "vert_spirv.h" ; const uint32_t frag_spirv[] = -#include "spirv_frag.h" +#include "frag_spirv.h" ; - -// glsl source: -const char* vert_src = "\ -#version 330 core \n\ -layout (location = 0) in vec3 vert; \n\ - \n\ -void main() { \n\ - gl_Position = vec4(vert.xyz, 0.001); \n\ -} \n\ -\0"; -const char* frag_src = "\ -#version 330 core \n\ -uniform float test; \n\ - \n\ -void main() { \n\ - vec2 uv = gl_FragCoord.xy / ivec2(800, 600); \n\ - gl_FragColor = vec4(uv.xy, test, 1.0); \n\ -} \n\ -\0"; +const char vert_src[] = { +#include "vert_src.h" +, 0x00 }; +const char frag_src[] = { +#include "frag_src.h" +, 0x00 }; GLuint load_shader_src(GLenum type, const char* src) { GLuint shader = glCreateShader(type); - glShaderSource(shader, 1, &frag_src, NULL); + glShaderSource(shader, 1, &src, NULL); glCompileShader(shader); return shader; } @@ -65,7 +51,7 @@ void test(const char* label, GLuint shader) { GLchar name[80]; GLsizei length; glGetActiveUniformName(shader, i, 80, &length, name); - printf("\t[%u] = \"%.*s\"\n", i, length, name); + printf("\t(location = %u) = \"%.*s\"\n", i, length, name); } // directly get uniform location diff --git a/makefile b/makefile index 1ffe4ef..840c908 100644 --- a/makefile +++ b/makefile @@ -7,11 +7,17 @@ GLFLAGS += -fauto-map-locations main: main.c -main.c: spirv_vert.h -main.c: spirv_frag.h +main.c: vert_spirv.h +main.c: frag_spirv.h +main.c: vert_src.h +main.c: frag_src.h -%_frag.h: %.frag +frag_spirv.h: shader.frag glslc $(GLFLAGS) -mfmt=c -o $@ $< -%_vert.h: %.vert +vert_spirv.h: shader.vert glslc $(GLFLAGS) -mfmt=c -o $@ $< +frag_src.h: shader.frag + xxd -i < $< > $@ +vert_src.h: shader.vert + xxd -i < $< > $@ diff --git a/shader.frag b/shader.frag new file mode 100644 index 0000000..f417dc1 --- /dev/null +++ b/shader.frag @@ -0,0 +1,8 @@ +#version 330 core +uniform float test; + +void main() { + vec2 uv = gl_FragCoord.xy / ivec2(800, 600); + gl_FragColor = vec4(uv.xy, test, 1.0); +} + diff --git a/shader.vert b/shader.vert new file mode 100644 index 0000000..f9cf360 --- /dev/null +++ b/shader.vert @@ -0,0 +1,7 @@ +#version 330 core +layout (location = 0) in vec3 vert; + +void main() { + gl_Position = vec4(vert.xyz, 0.001); +} + diff --git a/spirv.frag b/spirv.frag deleted file mode 100644 index f417dc1..0000000 --- a/spirv.frag +++ /dev/null @@ -1,8 +0,0 @@ -#version 330 core -uniform float test; - -void main() { - vec2 uv = gl_FragCoord.xy / ivec2(800, 600); - gl_FragColor = vec4(uv.xy, test, 1.0); -} - diff --git a/spirv.vert b/spirv.vert deleted file mode 100644 index f9cf360..0000000 --- a/spirv.vert +++ /dev/null @@ -1,7 +0,0 @@ -#version 330 core -layout (location = 0) in vec3 vert; - -void main() { - gl_Position = vec4(vert.xyz, 0.001); -} - -- cgit v1.2.3