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;
62 typedef std::vector<Shader *> ShaderList;
63 typedef std::map<std::string, UniformInfo> UniformMap;
64 typedef std::map<std::string, UniformBlockInfo> UniformBlockMap;
69 ShaderList owned_data;
71 UniformBlockMap uniform_blocks;
73 LayoutHash uniform_layout_hash;
77 /// Constructs an empty Program with no Shaders attached.
80 /// Constructs a Program with standard features.
81 Program(const ProgramBuilder::StandardFeatures &);
83 /// Constructs a Program from unified source code using ProgramCompiler.
84 Program(const std::string &);
86 /// Constructs a Program from vertex and fragment shader source code.
87 Program(const std::string &, const std::string &);
94 void attach_shader(Shader &shader);
95 void attach_shader_owned(Shader *shader);
96 void detach_shader(Shader &shader);
97 const ShaderList &get_attached_shaders() const { return shaders; }
99 void bind_attribute(unsigned, const std::string &);
100 void bind_attribute(VertexComponent, const std::string &);
101 void bind_fragment_data(unsigned, const std::string &);
105 void query_uniforms();
106 void query_uniform_blocks(const std::vector<UniformInfo *> &);
107 void query_attributes();
108 static LayoutHash compute_layout_hash(const std::vector<const UniformInfo *> &);
109 static bool uniform_location_compare(const UniformInfo *, const UniformInfo *);
111 bool is_linked() const { return linked; }
112 std::string get_info_log() const;
114 LayoutHash get_uniform_layout_hash() const { return uniform_layout_hash; }
115 const UniformBlockMap &get_uniform_blocks() const { return uniform_blocks; }
116 const UniformBlockInfo &get_uniform_block_info(const std::string &) const;
117 const UniformMap &get_uniforms() const { return uniforms; }
118 const UniformInfo &get_uniform_info(const std::string &) const;
119 int get_uniform_location(const std::string &) const;
121 bool uses_legacy_variables() const { return legacy_vars; }
124 static void unbind();