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