aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2024-05-18 11:27:25 +0200
committerlonkaars <loek@pipeframe.xyz>2024-05-18 11:27:25 +0200
commit08529a4a8e685637c1e733a6fff528a813d9a95c (patch)
tree2ef35b36297eeea92e155fcb9a5bbfbe43bc4e24
parent1b1314ed856f8380726fd07cde5dd73125101ef2 (diff)
ensure same source
-rw-r--r--.gitignore4
-rw-r--r--main.c34
-rw-r--r--makefile14
-rw-r--r--shader.frag (renamed from spirv.frag)0
-rw-r--r--shader.vert (renamed from spirv.vert)0
5 files changed, 21 insertions, 31 deletions
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 <GL/glew.h>
#include <GLFW/glfw3.h>
-// 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/spirv.frag b/shader.frag
index f417dc1..f417dc1 100644
--- a/spirv.frag
+++ b/shader.frag
diff --git a/spirv.vert b/shader.vert
index f9cf360..f9cf360 100644
--- a/spirv.vert
+++ b/shader.vert