diff options
-rw-r--r-- | .gitignore | 4 | ||||
-rw-r--r-- | main.c | 34 | ||||
-rw-r--r-- | makefile | 14 | ||||
-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
@@ -1,5 +1,3 @@ *.o +*.h main -*_frag.* -*_vert.* -*.spv @@ -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 @@ -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 < $< > $@ |