-
Notifications
You must be signed in to change notification settings - Fork 0
/
program.c
73 lines (53 loc) · 1.47 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
63
64
65
66
67
68
69
70
71
72
73
#include <stdlib.h>
#include <glisy/program.h>
GLboolean
glisyProgramInit(GlisyProgram *program) {
if (!program) return GL_FALSE;
program->id = glCreateProgram();
if (program->id == 0) return GL_FALSE;
return GL_TRUE;
}
GLboolean
glisyProgramAttachShader(const GlisyProgram *program, const GlisyShader *shader) {
if (!program) return GL_FALSE;
if (!shader) return GL_FALSE;
// @TODO(jwerle): error handling
glAttachShader(program->id, shader->id);
return GL_TRUE;
}
GLboolean
glisyProgramLink(GlisyProgram *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);
}
glisyProgramDelete(program);
return GL_FALSE;
}
return GL_TRUE;
}
GLboolean
glisyProgramBind(GlisyProgram *program) {
if (!program) return GL_FALSE;
if (!program->id) {
if (!glisyProgramLink(program)) return GL_FALSE;
}
glUseProgram(program->id);
return GL_TRUE;
}
GLboolean
glisyProgramDelete(GlisyProgram *program) {
if (!program) return GL_FALSE;
if (program->id == 0) return GL_FALSE;
glDeleteProgram(program->id);
return GL_TRUE;
}