]> git.tdb.fi Git - libs/gl.git/blob - source/program.h
Add a standard program feature for environment-mapped reflections
[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 private:
63         unsigned id;
64         std::list<Shader *> shaders;
65         std::list<Shader *> owned_data;
66         bool linked;
67         std::map<std::string, UniformInfo> uniforms;
68
69 public:
70         Program();
71         Program(const StandardFeatures &);
72         Program(const std::string &, const std::string &);
73 private:
74         void init();
75 public:
76         virtual ~Program();
77
78         void attach_shader(Shader &shader);
79         void attach_shader_owned(Shader *shader);
80         void detach_shader(Shader &shader);
81         void add_standard_shaders(const StandardFeatures &);
82 private:
83         static std::string process_standard_source(const char **, const std::string &);
84 public:
85         const std::list<Shader *> &get_shaders() const { return shaders; }
86         void bind_attribute(unsigned, const std::string &);
87         void link();
88         bool is_linked() const { return linked; }
89         std::string get_info_log() const;
90         void bind() const;
91         int get_uniform_location(const std::string &) const;
92
93         static void unbind();
94 };
95
96 } // namespace GL
97 } // namespace Msp
98
99 #endif