-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathshader.cpp
More file actions
131 lines (103 loc) · 2.39 KB
/
shader.cpp
File metadata and controls
131 lines (103 loc) · 2.39 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#include <string>
#include <cassert>
#include <iostream>
#include <fstream>
#include <sstream>
#include <cstdlib>
#include <GL/glew.h>
#include <GL/gl.h>
#include "shader.h"
using namespace std;
namespace EZGraphics {
/* ------------------------------------------- */
Shader::Shader ( const Shader &a )
{
cerr << "Attempting to copy Shader objects" << endl;
exit(1);
}
/* ------------------------------------------- */
Shader::Shader ( const ShaderType t, const string source )
{
tp = t;
switch(t)
{
case Vert:
handle = glCreateShader(GL_VERTEX_SHADER);
break;
case Frag:
handle = glCreateShader(GL_FRAGMENT_SHADER);
break;
case Geom:
handle = glCreateShader(GL_GEOMETRY_SHADER);
break;
case TessE:
handle = glCreateShader(GL_TESS_EVALUATION_SHADER);
break;
case TessC:
handle = glCreateShader(GL_TESS_CONTROL_SHADER);
break;
default:
assert(0);
}
const GLchar *ssrc = source.c_str();
glShaderSource(handle,1,&ssrc,NULL);
glCompileShader(handle);
}
/* ------------------------------------------- */
Shader::~Shader()
{
if (!handle)
return;
// delete the buffer
assert(glIsShader(handle));
glDeleteShader(handle);
handle = 0;
}
/* ------------------------------------------- */
Shader & Shader::operator= ( const Shader & rhs )
{
cerr << "Attempting assignment of Shader objects" << endl;
exit(1);
}
/* ------------------------------------------- */
ShaderType Shader::getType() const
{
return tp;
}
/* ------------------------------------------- */
GLuint Shader::getHandle() const
{
return handle;
}
void Shader::printLog ()
{
int infologLength = 0;
int maxLength;
glGetShaderiv(handle,GL_INFO_LOG_LENGTH,&maxLength);
char infoLog[maxLength];
glGetShaderInfoLog(handle, maxLength, &infologLength, infoLog);
if (infologLength > 0)
cout << infoLog << endl;
}
/* ------------------------------------------- */
string ReadFromFile ( const char *name )
{
ifstream ifs(name);
if (!ifs)
{
cout << "Can't open " << name << endl;
return string("");
}
stringstream sstr;
sstr << ifs.rdbuf();
return sstr.str();
}
/* ------------------------------------------- */
Shader::operator bool()
{
GLint status;
glGetShaderiv(handle,GL_COMPILE_STATUS,&status);
return status==GL_TRUE;
}
/* ------------------------------------------- */
};