1 #ifndef MSP_GL_PROGRAM_H_
2 #define MSP_GL_PROGRAM_H_
6 #include <msp/datafile/objectloader.h>
9 #include "programbuilder.h"
10 #include "vertexformat.h"
18 A complete shader program. Programs can be assembled of individual Shaders or
19 generated with a set of standard features.
21 class Program: public Bindable<Program>
24 class Loader: public DataFile::ObjectLoader<Program>
30 virtual void finish();
32 void attribute(unsigned, const std::string &);
33 void fragment_shader(const std::string &);
34 void geometry_shader(const std::string &);
36 void vertex_shader(const std::string &);
39 typedef unsigned LayoutHash;
40 struct UniformBlockInfo;
45 const UniformBlockInfo *block;
48 unsigned array_stride;
49 unsigned matrix_stride;
53 struct UniformBlockInfo
58 std::vector<const UniformInfo *> uniforms;
59 LayoutHash layout_hash;
70 typedef std::vector<Shader *> ShaderList;
71 typedef std::map<std::string, UniformInfo> UniformMap;
72 typedef std::map<std::string, UniformBlockInfo> UniformBlockMap;
73 typedef std::map<std::string, AttributeInfo> AttributeMap;
78 ShaderList owned_data;
80 UniformBlockMap uniform_blocks;
82 LayoutHash uniform_layout_hash;
83 AttributeMap attributes;
86 /// Constructs an empty Program with no Shaders attached.
89 /// Constructs a Program with standard features.
90 Program(const ProgramBuilder::StandardFeatures &);
92 /// Constructs a Program from unified source code using ProgramCompiler.
93 Program(const std::string &);
95 /// Constructs a Program from vertex and fragment shader source code.
96 Program(const std::string &, const std::string &);
103 void attach_shader(Shader &shader);
104 void attach_shader_owned(Shader *shader);
105 void detach_shader(Shader &shader);
106 const ShaderList &get_attached_shaders() const { return shaders; }
108 void bind_attribute(unsigned, const std::string &);
109 void bind_attribute(VertexComponent, const std::string &);
110 void bind_fragment_data(unsigned, const std::string &);
114 static void require_type(GLenum);
115 void query_uniforms();
116 void query_uniform_blocks(const std::vector<UniformInfo *> &);
117 void query_attributes();
118 static LayoutHash compute_layout_hash(const std::vector<const UniformInfo *> &);
119 static bool uniform_location_compare(const UniformInfo *, const UniformInfo *);
121 bool is_linked() const { return linked; }
122 std::string get_info_log() const;
124 LayoutHash get_uniform_layout_hash() const { return uniform_layout_hash; }
125 const UniformBlockMap &get_uniform_blocks() const { return uniform_blocks; }
126 const UniformBlockInfo &get_uniform_block_info(const std::string &) const;
127 const UniformMap &get_uniforms() const { return uniforms; }
128 const UniformInfo &get_uniform_info(const std::string &) const;
129 int get_uniform_location(const std::string &) const;
130 const AttributeMap &get_attributes() const { return attributes; }
131 const AttributeInfo &get_attribute_info(const std::string &) const;
132 int get_attribute_location(const std::string &) const;
135 static void unbind();