]> git.tdb.fi Git - libs/gl.git/blob - source/program.h
Move Program::bind to its proper place
[libs/gl.git] / source / program.h
1 #ifndef MSP_GL_PROGRAM_H_
2 #define MSP_GL_PROGRAM_H_
3
4 #include <list>
5 #include <string>
6 #include <msp/datafile/objectloader.h>
7 #include "bindable.h"
8 #include "gl.h"
9
10 namespace Msp {
11 namespace GL {
12
13 class Shader;
14
15 class Program: public Bindable<Program>
16 {
17 public:
18         class Loader: public DataFile::ObjectLoader<Program>
19         {
20         public:
21                 Loader(Program &);
22
23         private:
24                 virtual void finish();
25
26                 void attribute(unsigned, const std::string &);
27                 void fragment_shader(const std::string &);
28                 void standard();
29                 void vertex_shader(const std::string &);
30         };
31
32         struct StandardFeatures
33         {
34                 class Loader: public DataFile::ObjectLoader<StandardFeatures>
35                 {
36                 public:
37                         Loader(StandardFeatures &);
38                 };
39
40                 bool texture;
41                 bool material;
42                 bool lighting;
43                 bool specular;
44                 bool normalmap;
45                 bool shadow;
46                 bool reflection;
47                 bool transform;
48
49                 StandardFeatures();
50
51                 std::string create_flags() const;
52         };
53
54         struct UniformInfo
55         {
56                 std::string name;
57                 int location;
58                 int size;
59                 GLenum type;
60         };
61
62         typedef std::list<Shader *> ShaderList;
63         typedef std::map<std::string, UniformInfo> UniformMap;
64
65 private:
66         unsigned id;
67         ShaderList shaders;
68         ShaderList owned_data;
69         bool linked;
70         UniformMap uniforms;
71         unsigned uniform_layout_hash;
72
73 public:
74         Program();
75         Program(const StandardFeatures &);
76         Program(const std::string &, const std::string &);
77 private:
78         void init();
79 public:
80         virtual ~Program();
81
82         void attach_shader(Shader &shader);
83         void attach_shader_owned(Shader *shader);
84         void detach_shader(Shader &shader);
85         void add_standard_shaders(const StandardFeatures &);
86 private:
87         static std::string process_standard_source(const char **, const std::string &);
88 public:
89         const ShaderList &get_shaders() const { return shaders; }
90
91         void bind_attribute(unsigned, const std::string &);
92
93         void link();
94         bool is_linked() const { return linked; }
95         std::string get_info_log() const;
96
97         unsigned get_uniform_layout_hash() const { return uniform_layout_hash; }
98         int get_uniform_location(const std::string &) const;
99
100         void bind() const;
101         static void unbind();
102 };
103
104 } // namespace GL
105 } // namespace Msp
106
107 #endif