-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshader_object.cpp
91 lines (80 loc) · 2.25 KB
/
shader_object.cpp
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
struct shader
{
GLuint VertexID;
GLuint GeometryID;
GLuint FragmentID;
GLuint ID;
char* VertexSource;
char* GeometrySource;
char* FragmentSource;
char* Name;
};
void compileShader(shader* Shader)
{
Shader->VertexID = glCreateShader(GL_VERTEX_SHADER);
Shader->FragmentID = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource(Shader->VertexID, 1,
&Shader->VertexSource, NULL);
glShaderSource(Shader->FragmentID, 1,
&Shader->FragmentSource, NULL);
glCompileShader(Shader->VertexID);
glCompileShader(Shader->FragmentID);
GLint Success;
GLchar InfoLog[512];
{
glGetShaderiv(Shader->FragmentID, GL_COMPILE_STATUS, &Success);
if(!Success)
{
glGetShaderInfoLog(Shader->FragmentID, 512, NULL, InfoLog);
printf("Fragment Shader Compilation Failure: %s\n"
"--: %s", Shader->Name, InfoLog);
}
glGetShaderiv(Shader->VertexID, GL_COMPILE_STATUS, &Success);
if(!Success)
{
glGetShaderInfoLog(Shader->VertexID, 512, NULL, InfoLog);
printf("Vertex Shader Compilation Failure: %s\n"
"--: %s", Shader->Name, InfoLog);
}
}
if(Shader->GeometrySource != NULL)
{
Shader->GeometryID = glCreateShader(GL_GEOMETRY_SHADER);
glShaderSource(Shader->GeometryID, 1,
&Shader->GeometrySource, NULL);
glCompileShader(Shader->GeometryID);
{
glGetShaderiv(Shader->GeometryID, GL_COMPILE_STATUS, &Success);
if(!Success)
{
glGetShaderInfoLog(Shader->GeometryID, 512, NULL, InfoLog);
printf("Geometry Shader Compilation Failure: %s\n"
"--: %s", Shader->Name, InfoLog);
}
}
}
}
void linkShader(shader* Shader)
{
Shader->ID = glCreateProgram();
glAttachShader(Shader->ID,
Shader->VertexID);
glAttachShader(Shader->ID,
Shader->FragmentID);
if(Shader->GeometrySource != NULL)
{
glAttachShader(Shader->ID,
Shader->GeometryID);
}
glLinkProgram(Shader->ID);
{
GLint Success;
GLchar InfoLog[512];
glGetProgramiv(Shader->ID, GL_LINK_STATUS, &Success);
if(!Success)
{
glGetProgramInfoLog(Shader->ID, 512, NULL, InfoLog);
printf("Shader Program Link Failure: %s", InfoLog);
}
}
}