-
Notifications
You must be signed in to change notification settings - Fork 0
/
program.c
62 lines (44 loc) · 1.27 KB
/
program.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <stdlib.h>
#include <glisy/program.h>
GLboolean
glisy_program_init(glisy_program *program) {
if (!program) return GL_FALSE;
program->id = glCreateProgram();
if (program->id == 0) return GL_FALSE;
return GL_TRUE;
}
GLboolean
glisy_program_attach_shader(const glisy_program *program, const glisy_shader *shader) {
if (!program) return GL_FALSE;
if (!shader) return GL_FALSE;
// @TODO(jwerle): error handling
glAttachShader(program->id, shader->id);
return GL_TRUE;
}
GLboolean
glisy_program_link(glisy_program *program) {
GLint isLinked = 0;
if (!program) return GL_FALSE;
glLinkProgram(program->id);
glGetProgramiv(program->id, GL_LINK_STATUS, &isLinked);
if (!isLinked) {
GLint infoLen = 0;
glGetProgramiv(program->id, GL_INFO_LOG_LENGTH, &infoLen);
if (infoLen > 1) {
char *infoLog = malloc(sizeof (char) * infoLen);
glGetProgramInfoLog (program->id, infoLen, NULL, infoLog);
printf("Error linking program:\n%s\n", infoLog);
free(infoLog);
}
glisy_program_delete(program);
return GL_FALSE;
}
return GL_TRUE;
}
GLboolean
glisy_program_delete(glisy_program *program) {
if (!program) return GL_FALSE;
if (program->id == 0) return GL_FALSE;
glDeleteProgram(program->id);
return GL_TRUE;
}