9cedab6de0450abdc85998a5f86fb0ebeae1578b
[ipdf/code.git] / src / shaderprogram.h
1 #ifndef _SHADERPROGRAM_H
2 #define _SHADERPROGRAM_H
3
4 #include <vector>
5 #include "gl_core44.h"
6
7
8 namespace IPDF
9 {
10         /**
11          * The "Shader" class represents a GLSL program made from shaders.
12          */
13         class ShaderProgram
14         {
15         public:
16                 ShaderProgram() : m_program(0) {}
17                 ~ShaderProgram();
18
19                 inline bool AttachGeometryProgram(const char * geometry_file) {return AttachShader(geometry_file, GL_GEOMETRY_SHADER);}
20                 inline bool AttachVertexProgram(const char * vertex_file) {return AttachShader(vertex_file, GL_VERTEX_SHADER);}
21                 inline bool AttachFragmentProgram(const char * fragment_file) {return AttachShader(fragment_file, GL_FRAGMENT_SHADER);}
22
23                 /** Read shaders from files and attach them
24                  * @returns false if any of the shaders cannot be attached
25                  */
26                 inline bool AttachShaderPrograms(const char * geometry_file, const char * vertex_file, const char * fragment_file)
27                 {
28                         return AttachGeometryProgram(geometry_file) && AttachVertexProgram(vertex_file) && AttachFragmentProgram(fragment_file);
29                 }
30                 bool Link(); // currently always returns true?
31                 const void Use() const;
32                 // Unfortunately, we don't require GL 4.3/ARB_explicit_uniform_location
33                 // which would make this obsolete. One uday Mesa will support it.
34                 // NOTE: We could actually get away with this by only using UBOs, as
35                 // Mesa supports ARB_shading_language_420pack, but that'd be a bit more
36                 // work right with the way some of our uniforms are laid out at the moment.
37                 const GLint GetUniformLocation(const char *uniform_name) const;
38
39         private:
40                 void LazyCreateProgram();
41                 /** Read shader source from src_file and attach it as type **/
42                 bool AttachShader(const char * src_file, GLenum type);
43                 char * GetShaderSource(const char * src_file) const;
44                 GLuint m_program;
45                 struct Shader
46                 {
47                         GLenum type;
48                         GLuint obj;
49                 };
50                 std::vector<Shader> m_shaders;
51         };
52
53 }
54
55 #endif // _SHADERPROGRAM_H

UCC git Repository :: git.ucc.asn.au