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 struct UniformBlockInfo;
43 const UniformBlockInfo *block;
46 unsigned array_stride;
47 unsigned matrix_stride;
51 struct UniformBlockInfo
56 std::vector<const UniformInfo *> uniforms;
60 typedef std::list<Shader *> ShaderList;
61 typedef std::map<std::string, UniformInfo> UniformMap;
62 typedef std::map<std::string, UniformBlockInfo> UniformBlockMap;
67 ShaderList owned_data;
69 UniformBlockMap uniform_blocks;
71 unsigned uniform_layout_hash;
75 /// Constructs an empty Program with no Shaders attached.
78 /// Constructs a Program with standard features.
79 Program(const ProgramBuilder::StandardFeatures &);
81 /// Constructs a Program from vertex and fragment shader source code.
82 Program(const std::string &, const std::string &);
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; }
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 &);
100 static unsigned compute_layout_hash(const std::vector<const UniformInfo *> &);
101 static bool uniform_location_compare(const UniformInfo *, const UniformInfo *);
103 bool is_linked() const { return linked; }
104 std::string get_info_log() const;
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;
113 bool uses_legacy_variables() const { return legacy_vars; }
116 static void unbind();