45 * @return the compiled shader |
45 * @return the compiled shader |
46 */ |
46 */ |
47 static unsigned asc_shader_compile(unsigned int type, char const *code) { |
47 static unsigned asc_shader_compile(unsigned int type, char const *code) { |
48 GLuint id = glCreateShader(type); |
48 GLuint id = glCreateShader(type); |
49 if (id == 0) { |
49 if (id == 0) { |
50 asc_error("glCreateShader failed"); |
50 asc_error("glCreateShader failed: %s", glGetError()); |
51 return 0; |
51 return 0; |
52 } |
52 } |
53 |
53 |
54 GLint success; |
54 GLint success; |
55 int length = (int) strlen(code); // must be int because of OpenGL API |
55 int length = (int) strlen(code); // must be int because of OpenGL API |
80 */ |
80 */ |
81 static AscShaderProgram asc_shader_link(unsigned shader[], unsigned n) { |
81 static AscShaderProgram asc_shader_link(unsigned shader[], unsigned n) { |
82 GLint success; |
82 GLint success; |
83 GLint id = glCreateProgram(); |
83 GLint id = glCreateProgram(); |
84 if (id <= 0) { |
84 if (id <= 0) { |
85 asc_error("glCreateProgram failed"); |
85 asc_error("glCreateProgram failed: %s", glGetError()); |
86 return (AscShaderProgram) {0}; |
86 return (AscShaderProgram) {0}; |
87 } |
87 } |
88 for (unsigned i = 0; i < n; i++) { |
88 for (unsigned i = 0; i < n; i++) { |
89 glAttachShader(id, shader[i]); |
89 glAttachShader(id, shader[i]); |
90 } |
90 } |
104 return prog; |
104 return prog; |
105 } else { |
105 } else { |
106 char *log = malloc(1024); |
106 char *log = malloc(1024); |
107 glGetProgramInfoLog(id, 1024, NULL, log); |
107 glGetProgramInfoLog(id, 1024, NULL, log); |
108 glDeleteProgram(id); |
108 glDeleteProgram(id); |
109 asc_error(log); |
109 asc_error("Linking shader program %u failed.\n%s", id, log); |
110 free(log); |
110 free(log); |
111 return (AscShaderProgram) {0}; |
111 return (AscShaderProgram) {0}; |
112 } |
112 } |
113 } |
113 } |
114 |
114 |