src/shader.c

changeset 92
78ce93fb46e5
parent 88
6234b7ea48f3
equal deleted inserted replaced
91:8433c87c0f51 92:78ce93fb46e5
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
61 return id; 61 return id;
62 } else { 62 } else {
63 char *log = malloc(1024); 63 char *log = malloc(1024);
64 glGetShaderInfoLog(id, 1024, NULL, log); 64 glGetShaderInfoLog(id, 1024, NULL, log);
65 glDeleteShader(id); 65 glDeleteShader(id);
66 asc_error(log); 66 asc_error("Shader %u compilation failed.\n%s", id, log);
67 free(log); 67 free(log);
68 return 0; 68 return 0;
69 } 69 }
70 } 70 }
71 71
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

mercurial