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 &);
35 void vertex_shader(const std::string &);
38 typedef unsigned LayoutHash;
39 struct UniformBlockInfo;
44 const UniformBlockInfo *block;
47 unsigned array_stride;
48 unsigned matrix_stride;
52 struct UniformBlockInfo
57 std::vector<const UniformInfo *> uniforms;
58 LayoutHash layout_hash;
61 typedef std::list<Shader *> ShaderList;
62 typedef std::map<std::string, UniformInfo> UniformMap;
63 typedef std::map<std::string, UniformBlockInfo> UniformBlockMap;
68 ShaderList owned_data;
70 UniformBlockMap uniform_blocks;
72 LayoutHash uniform_layout_hash;
76 /// Constructs an empty Program with no Shaders attached.
79 /// Constructs a Program with standard features.
80 Program(const ProgramBuilder::StandardFeatures &);
82 /// Constructs a Program from vertex and fragment shader source code.
83 Program(const std::string &, const std::string &);
90 void attach_shader(Shader &shader);
91 void attach_shader_owned(Shader *shader);
92 void detach_shader(Shader &shader);
93 const ShaderList &get_attached_shaders() const { return shaders; }
95 void bind_attribute(unsigned, const std::string &);
96 void bind_attribute(VertexComponent, const std::string &);
97 void bind_fragment_data(unsigned, const std::string &);
101 static LayoutHash compute_layout_hash(const std::vector<const UniformInfo *> &);
102 static bool uniform_location_compare(const UniformInfo *, const UniformInfo *);
104 bool is_linked() const { return linked; }
105 std::string get_info_log() const;
107 LayoutHash get_uniform_layout_hash() const { return uniform_layout_hash; }
108 const UniformBlockMap &get_uniform_blocks() const { return uniform_blocks; }
109 const UniformBlockInfo &get_uniform_block_info(const std::string &) const;
110 const UniformMap &get_uniforms() const { return uniforms; }
111 const UniformInfo &get_uniform_info(const std::string &) const;
112 int get_uniform_location(const std::string &) const;
114 bool uses_legacy_variables() const { return legacy_vars; }
117 static void unbind();