]> git.tdb.fi Git - libs/gl.git/blob - source/program.h
Drop Id tags and copyright notices from files
[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
47                 StandardFeatures();
48
49                 std::string create_flags() const;
50         };
51
52         struct UniformInfo
53         {
54                 std::string name;
55                 int location;
56                 int size;
57                 GLenum type;
58         };
59
60 private:
61         unsigned id;
62         std::list<Shader *> shaders;
63         bool del_shaders;
64         bool linked;
65         std::map<std::string, UniformInfo> uniforms;
66
67 public:
68         Program();
69         Program(const StandardFeatures &);
70         Program(const std::string &, const std::string &);
71 private:
72         void init();
73 public:
74         virtual ~Program();
75
76         void attach_shader(Shader &shader);
77         void detach_shader(Shader &shader);
78         void add_standard_shaders(const StandardFeatures &);
79 private:
80         static std::string process_standard_source(const char **, const std::string &);
81 public:
82         const std::list<Shader *> &get_shaders() const { return shaders; }
83         void set_del_shaders(bool);
84         void bind_attribute(unsigned, const std::string &);
85         void link();
86         bool is_linked() const { return linked; }
87         std::string get_info_log() const;
88         void bind() const;
89         int get_uniform_location(const std::string &) const;
90
91         static void unbind();
92 };
93
94 } // namespace GL
95 } // namespace Msp
96
97 #endif