-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathshaders_errors.c
94 lines (77 loc) · 1.91 KB
/
shaders_errors.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <stdlib.h>
#include <stdio.h>
#include "shaders_errors.h"
/* Based on: see LINKS file: [1]. */
void printInfoLog(FILE * stream, GLuint obj)
{
int infoLogLength = 0;
char * infoLog = NULL;
int charsWritten = 0;
if (! glIsShader(obj) && ! glIsProgram(obj))
{
fprintf(stream,
"Cannot print InfoLog, \
object is not shader or shader program.");
return;
}
if (glIsShader(obj))
{
glGetShaderiv(obj, GL_INFO_LOG_LENGTH, &infoLogLength);
}
else if (glIsProgram(obj))
{
glGetProgramiv(obj, GL_INFO_LOG_LENGTH, &infoLogLength);
}
fprintf(stream, "InfoLog length: %d.\n", infoLogLength);
if (infoLogLength <= 0)
{
return;
}
infoLog = (char *) malloc(infoLogLength * sizeof(char));
if (glIsShader(obj))
{
glGetShaderInfoLog(obj, infoLogLength,
&charsWritten, infoLog);
}
else if (glIsProgram(obj))
{
glGetProgramInfoLog(obj, infoLogLength,
&charsWritten, infoLog);
}
fprintf(stream, "%s\n", infoLog);
free(infoLog);
}
void checkCompileStatus(GLuint obj)
{
GLint ok;
glGetShaderiv(obj, GL_COMPILE_STATUS, &ok);
if (ok == GL_FALSE)
{
fprintf(stderr,
"==== Compile shader or shader program failed ====\n");
printInfoLog(stderr, obj);
exit(EXIT_FAILURE);
}
}
void checkLinkStatus(GLuint obj)
{
GLint ok;
glGetProgramiv(obj, GL_LINK_STATUS, &ok);
if (ok == GL_FALSE)
{
fprintf(stderr, "==== Link shader program failed ====\n");
printInfoLog(stderr, obj);
exit(EXIT_FAILURE);
}
}
void validateShaderProgram(GLuint obj)
{
GLint status;
glValidateProgram(obj);
glGetProgramiv(obj, GL_VALIDATE_STATUS, &status);
if (status == GL_FALSE)
{
fprintf(stderr, "Shader program validate failed.\n");
exit(EXIT_FAILURE);
}
}