]> git.tdb.fi Git - libs/gl.git/blob - source/program.h
Add a hidden option to disable progress meter
[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 #include "programbuilder.h"
10 #include "vertexformat.h"
11
12 namespace Msp {
13 namespace GL {
14
15 class Shader;
16
17 /**
18 A complete shader program.  Programs can be assembled of individual Shaders or
19 generated with a set of standard features.
20 */
21 class Program: public Bindable<Program>
22 {
23 public:
24         class Loader: public DataFile::ObjectLoader<Program>
25         {
26         public:
27                 Loader(Program &);
28
29         private:
30                 virtual void finish();
31
32                 void attribute(unsigned, const std::string &);
33                 void fragment_shader(const std::string &);
34                 void standard();
35                 void vertex_shader(const std::string &);
36         };
37
38         struct UniformBlockInfo;
39
40         struct UniformInfo
41         {
42                 std::string name;
43                 const UniformBlockInfo *block;
44                 unsigned location;
45                 unsigned size;
46                 unsigned array_stride;
47                 unsigned matrix_stride;
48                 GLenum type;
49         };
50
51         struct UniformBlockInfo
52         {
53                 std::string name;
54                 unsigned data_size;
55                 unsigned bind_point;
56                 std::vector<const UniformInfo *> uniforms;
57                 unsigned layout_hash;
58         };
59
60         typedef std::list<Shader *> ShaderList;
61         typedef std::map<std::string, UniformInfo> UniformMap;
62         typedef std::map<std::string, UniformBlockInfo> UniformBlockMap;
63
64 private:
65         unsigned id;
66         ShaderList shaders;
67         ShaderList owned_data;
68         bool linked;
69         UniformBlockMap uniform_blocks;
70         UniformMap uniforms;
71         unsigned uniform_layout_hash;
72         bool legacy_vars;
73
74 public:
75         /// Constructs an empty Program with no Shaders attached.
76         Program();
77
78         /// Constructs a Program with standard features.
79         Program(const ProgramBuilder::StandardFeatures &);
80
81         /// Constructs a Program from vertex and fragment shader source code.
82         Program(const std::string &, const std::string &);
83
84 private:
85         void init();
86 public:
87         virtual ~Program();
88
89         void attach_shader(Shader &shader);
90         void attach_shader_owned(Shader *shader);
91         void detach_shader(Shader &shader);
92         const ShaderList &get_shaders() const { return shaders; }
93
94         void bind_attribute(unsigned, const std::string &);
95         void bind_attribute(VertexComponent, const std::string &);
96         void bind_fragment_data(unsigned, const std::string &);
97
98         void link();
99 private:
100         static unsigned compute_layout_hash(const std::vector<const UniformInfo *> &);
101         static bool uniform_location_compare(const UniformInfo *, const UniformInfo *);
102 public:
103         bool is_linked() const { return linked; }
104         std::string get_info_log() const;
105
106         unsigned get_uniform_layout_hash() const { return uniform_layout_hash; }
107         const UniformBlockMap &get_uniform_blocks() const { return uniform_blocks; }
108         const UniformBlockInfo &get_uniform_block_info(const std::string &) const;
109         const UniformMap &get_uniforms() const { return uniforms; }
110         const UniformInfo &get_uniform_info(const std::string &) const;
111         int get_uniform_location(const std::string &) const;
112
113         bool uses_legacy_variables() const { return legacy_vars; }
114
115         void bind() const;
116         static void unbind();
117 };
118
119 } // namespace GL
120 } // namespace Msp
121
122 #endif