Unofficial OpenGL Software Development Kit: C:/Projects/distro/glsdk_0_5_1/glutil/include/glutil/Shader.h Source File

Unofficial OpenGL Software Development Kit 0.5.0

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Shader.h
Go to the documentation of this file.
1
2 #ifndef SHADER_UTIL_H
3 #define SHADER_UTIL_H
4
10 #include <exception>
11 #include <string>
12 #include <vector>
13 #include "array_ref.h"
14 #include <boost/utility/string_ref.hpp>
15 #include <boost/noncopyable.hpp>
16
17 namespace glutil
18 {
21
23 class ShaderException : public std::exception
24 {
25 public:
26 virtual ~ShaderException() throw() {}
27
28 virtual const char *what() const throw() {return message.c_str();}
29
30 protected:
31 std::string message;
32
33 ShaderException() {}
34 ShaderException(const char *msg) : message(msg) {}
35 };
36
38 class SeparateShaderNotSupported : public ShaderException
39 {
40 public:
41 SeparateShaderNotSupported();
42 };
43
45 class CompileLinkException : public ShaderException
46 {
47 public:
48 CompileLinkException(GLuint shader);
49 CompileLinkException(GLuint program, bool);
50
51 virtual ~CompileLinkException() throw() {}
52 };
54
57
64
65
79 GLuint CompileShader(GLenum shaderType, boost::string_ref shaderText);
80
84 GLuint CompileShader(GLenum shaderType, refs::array_ref<const char *> shaderList);
85
89 GLuint CompileShader(GLenum shaderType, const std::vector<std::string> &shaderList);
91
100
101
116 GLuint LinkProgram(GLuint shaderOne, GLuint shaderTwo);
117
119 GLuint LinkProgram(GLuint program, GLuint shaderOne, GLuint shaderTwo);
120
135 GLuint LinkProgram(boost::string_ref vertexShader, boost::string_ref fragmentShader);
136
138 GLuint LinkProgram(GLuint program, boost::string_ref vertexShader, boost::string_ref fragmentShader);
139
140
155 GLuint LinkProgram(GLuint shader, bool isSeparable = false);
156
160 GLuint LinkProgram(refs::array_ref<GLuint> shaders, bool isSeparable = false);
161
170 GLuint LinkProgram(GLuint program, refs::array_ref<GLuint> shaders);
172
180
181
194 GLuint MakeSeparableProgram(GLenum shaderType, const char *shaderText);
195
197 GLuint MakeSeparableProgram(GLenum shaderType, const std::string &shaderText);
198
202 GLuint MakeSeparableProgram(GLenum shaderType, refs::array_ref<const char *> shaderList);
203
207 GLuint MakeSeparableProgram(GLenum shaderType, const std::vector<std::string> &shaderList);
209
225 class UniqueShader : public boost::noncopyable
226 {
227 public:
229 UniqueShader() : m_shader(0) {}
231 explicit UniqueShader(GLuint shader) : m_shader(shader) {}
233 ~UniqueShader() {Disengage();}
234
236 void swap(UniqueShader &other)
237 {
238 using std::swap;
239 swap(m_shader, other.m_shader);
240 }
241
243 operator GLuint() const {return m_shader;}
244
246 void reset(GLuint newShader = 0)
247 {
248 Disengage();
249 m_shader = newShader;
250 }
251
260 GLuint release()
261 {
262 GLuint shaderName = m_shader;
263 m_shader = 0;
264 return shaderName;
265 }
266
267 private:
268 GLuint m_shader;
269
270 void Disengage();
271 };
272
288 class UniqueProgram : public boost::noncopyable
289 {
290 public:
292 UniqueProgram() : m_program(0) {}
294 explicit UniqueProgram(GLuint program) : m_program(program) {}
296 ~UniqueProgram() {Disengage();}
297
299 void swap(UniqueProgram &other)
300 {
301 using std::swap;
302 swap(m_program, other.m_program);
303 }
304
306 operator GLuint () const {return m_program;}
307
309 void reset(GLuint newProgram = 0)
310 {
311 Disengage();
312 m_program = newProgram;
313 }
314
323 GLuint release()
324 {
325 GLuint programName = m_program;
326 m_program = 0;
327 return programName;
328 }
329
330 private:
331 GLuint m_program;
332
333 void Disengage();
334 };
335
336 inline void swap(UniqueShader &lhs, UniqueShader &rhs) {lhs.swap(rhs);}
337 inline void swap(UniqueProgram &lhs, UniqueProgram &rhs) {lhs.swap(rhs);}
338
340 }
341
342 #endif //SHADER_UTIL_H