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 #pragma GCC diagnostic push
90 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
91 /// Constructs a Program with standard features.
92 DEPRECATED Program(const ProgramBuilder::StandardFeatures &);
93 #pragma GCC diagnostic pop
95 /// Constructs a Program from unified source code using ProgramCompiler.
96 Program(const std::string &);
98 /// Constructs a Program from vertex and fragment shader source code.
99 Program(const std::string &, const std::string &);
106 void attach_shader(Shader &shader);
107 void attach_shader_owned(Shader *shader);
108 void detach_shader(Shader &shader);
109 const ShaderList &get_attached_shaders() const { return shaders; }
111 void bind_attribute(unsigned, const std::string &);
112 void bind_attribute(VertexComponent, const std::string &);
113 void bind_fragment_data(unsigned, const std::string &);
117 static void require_type(GLenum);
118 void query_uniforms();
119 void query_uniform_blocks(const std::vector<UniformInfo *> &);
120 void query_attributes();
121 static LayoutHash compute_layout_hash(const std::vector<const UniformInfo *> &);
122 static bool uniform_location_compare(const UniformInfo *, const UniformInfo *);
124 bool is_linked() const { return linked; }
125 std::string get_info_log() const;
127 LayoutHash get_uniform_layout_hash() const { return uniform_layout_hash; }
128 const UniformBlockMap &get_uniform_blocks() const { return uniform_blocks; }
129 const UniformBlockInfo &get_uniform_block_info(const std::string &) const;
130 const UniformMap &get_uniforms() const { return uniforms; }
131 const UniformInfo &get_uniform_info(const std::string &) const;
132 int get_uniform_location(const std::string &) const;
133 const AttributeMap &get_attributes() const { return attributes; }
134 const AttributeInfo &get_attribute_info(const std::string &) const;
135 int get_attribute_location(const std::string &) const;
138 static void unbind();