diff options
Diffstat (limited to 'shader.c')
-rw-r--r-- | shader.c | 52 |
1 files changed, 0 insertions, 52 deletions
diff --git a/shader.c b/shader.c deleted file mode 100644 index 6831b28..0000000 --- a/shader.c +++ /dev/null @@ -1,52 +0,0 @@ -#include "shader.h" - -#include "die.h" - -void check_shader(GLuint shader) { - int success; - char debug[LOG_MAX]; - glGetShaderiv(shader, GL_COMPILE_STATUS, &success); - if (success) return; - glGetShaderInfoLog(shader, LOG_MAX, NULL, debug); - die("error: shader compilation failed!\n%s", debug); -} - -void check_program(GLuint program) { - int success; - char debug[LOG_MAX]; - glGetProgramiv(program, GL_LINK_STATUS, &success); - if (success) return; - glGetProgramInfoLog(program, LOG_MAX, NULL, 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); - glShaderBinary(1, &shader, GL_SHADER_BINARY_FORMAT_SPIR_V_ARB, src, src_size); - glSpecializeShaderARB(shader, "main", 0, 0, 0); - check_shader(shader); - return shader; -} - -GLuint frag_shader(const char* const src, size_t src_size) { - return load_shader(GL_FRAGMENT_SHADER, src, src_size); -} -GLuint vert_shader(const char* const src, size_t src_size) { - return load_shader(GL_VERTEX_SHADER, src, src_size); -} - -GLuint link_shaders(GLuint vert, GLuint frag) { - GLuint shader = glCreateProgram(); - glAttachShader(shader, vert); - glAttachShader(shader, frag); - glLinkProgram(shader); - - check_program(shader); - - glUseProgram(shader); - - glDeleteShader(vert); - glDeleteShader(frag); - return shader; -} - |