-
Notifications
You must be signed in to change notification settings - Fork 5
/
FragmentShader.cpp
80 lines (61 loc) · 1.63 KB
/
FragmentShader.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
#include "client.h"
#include "FragmentShader.h"
int FragmentShader::idgen = 1;
#if !(TARGET_IPHONE_SIMULATOR ||TARGET_OS_IPHONE || defined(__linux__))
static bool shaderCompile(GLuint shader, const char *src){
GLsizei len = strlen(src), size;
GLint compiled;
glShaderSource(shader, 1, (const GLchar**) & src, (GLint*)&len );
// ƒVƒF[ƒ_‚̃Rƒ“ƒpƒCƒ‹
glCompileShader(shader);
glGetShaderiv( shader, GL_COMPILE_STATUS, &compiled );
if ( compiled == GL_FALSE ){
print( "couldn't compile shader: %s \n ", src );
glGetProgramiv( shader, GL_INFO_LOG_LENGTH, &size );
if ( size > 0 ){
GLchar *buf;
buf = (char *)MALLOC(size);
glGetShaderInfoLog( shader, size, &len, buf);
printf("%s",buf);
FREE(buf);
}
return false;
}
return true;
}
static bool link( GLuint prog ){
GLsizei size, len;
GLint linked;
char *infoLog ;
glLinkProgram( prog );
glGetProgramiv( prog, GL_LINK_STATUS, &linked );
if ( linked == GL_FALSE ){
print("couldnt link shader:\n");
glGetProgramiv( prog, GL_INFO_LOG_LENGTH, &size );
if ( size > 0 ){
infoLog = (char *)MALLOC(size);
glGetProgramInfoLog( prog, size, &len, infoLog );
printf("%s",infoLog);
FREE(infoLog);
}
return false;
}
return true;
}
#endif
bool FragmentShader::load( const char *src) {
#if !(TARGET_IPHONE_SIMULATOR ||TARGET_OS_IPHONE || defined(__linux__) )
GLuint shader = glCreateShader( GL_FRAGMENT_SHADER );
if(!shaderCompile( shader, src)){
glDeleteShader(shader);
return false;
}
program = glCreateProgram();
glAttachShader( program, shader );
glDeleteShader(shader);
if(!link( program ) ){
return false;
}
#endif
return true;
}