1 #ifndef MSP_GL_PROGRAM_H_
2 #define MSP_GL_PROGRAM_H_
6 #include <msp/datafile/objectloader.h>
9 #include "vertexformat.h"
17 A complete shader program. Programs can be assembled of individual Shaders or
18 generated with a set of standard features.
20 class Program: public Bindable<Program>
23 class Loader: public DataFile::ObjectLoader<Program>
29 virtual void finish();
31 void attribute(unsigned, const std::string &);
32 void fragment_shader(const std::string &);
33 void geometry_shader(const std::string &);
34 void vertex_shader(const std::string &);
37 typedef unsigned LayoutHash;
38 struct UniformBlockInfo;
43 const UniformBlockInfo *block;
46 unsigned array_stride;
47 unsigned matrix_stride;
51 struct UniformBlockInfo
56 std::vector<const UniformInfo *> uniforms;
57 LayoutHash layout_hash;
68 typedef std::vector<Shader *> ShaderList;
69 typedef std::map<std::string, UniformInfo> UniformMap;
70 typedef std::map<std::string, UniformBlockInfo> UniformBlockMap;
71 typedef std::map<std::string, AttributeInfo> AttributeMap;
76 ShaderList owned_data;
78 UniformBlockMap uniform_blocks;
80 LayoutHash uniform_layout_hash;
81 AttributeMap attributes;
84 /// Constructs an empty Program with no Shaders attached.
87 /// Constructs a Program from unified source code using ProgramCompiler.
88 Program(const std::string &);
90 /// Constructs a Program from vertex and fragment shader source code.
91 Program(const std::string &, const std::string &);
98 void attach_shader(Shader &shader);
99 void attach_shader_owned(Shader *shader);
100 void detach_shader(Shader &shader);
101 const ShaderList &get_attached_shaders() const { return shaders; }
103 void bind_attribute(unsigned, const std::string &);
104 void bind_attribute(VertexComponent, const std::string &);
105 void bind_fragment_data(unsigned, const std::string &);
109 static void require_type(GLenum);
110 void query_uniforms();
111 void query_uniform_blocks(const std::vector<UniformInfo *> &);
112 void query_attributes();
113 static LayoutHash compute_layout_hash(const std::vector<const UniformInfo *> &);
114 static bool uniform_location_compare(const UniformInfo *, const UniformInfo *);
116 bool is_linked() const { return linked; }
117 std::string get_info_log() const;
119 LayoutHash get_uniform_layout_hash() const { return uniform_layout_hash; }
120 const UniformBlockMap &get_uniform_blocks() const { return uniform_blocks; }
121 const UniformBlockInfo &get_uniform_block_info(const std::string &) const;
122 const UniformMap &get_uniforms() const { return uniforms; }
123 const UniformInfo &get_uniform_info(const std::string &) const;
124 int get_uniform_location(const std::string &) const;
125 const AttributeMap &get_attributes() const { return attributes; }
126 const AttributeInfo &get_attribute_info(const std::string &) const;
127 int get_attribute_location(const std::string &) const;
130 static void unbind();