1 #ifndef MSP_GL_PROGRAM_H_
2 #define MSP_GL_PROGRAM_H_
6 #include <msp/datafile/objectloader.h>
9 #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::CollectionObjectLoader<Program>
27 Loader(Program &, Collection &);
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 &);
35 void module(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::map<std::string, UniformInfo> UniformMap;
71 typedef std::map<std::string, UniformBlockInfo> UniformBlockMap;
72 typedef std::map<std::string, AttributeInfo> AttributeMap;
76 std::vector<unsigned> shader_ids;
79 UniformBlockMap uniform_blocks;
81 LayoutHash uniform_layout_hash;
82 AttributeMap attributes;
85 /// Constructs an empty Program with no Shaders attached.
88 /// Constructs a Program from unified source code using ProgramCompiler.
89 Program(const std::string &);
91 /// Constructs a Program from vertex and fragment shader source code.
92 DEPRECATED Program(const std::string &, const std::string &);
99 void add_stages(const Module &);
101 DEPRECATED void attach_shader(Shader &shader);
102 DEPRECATED void attach_shader_owned(Shader *shader);
103 DEPRECATED void detach_shader(Shader &shader);
104 DEPRECATED const std::vector<Shader *> &get_attached_shaders() const;
106 DEPRECATED void bind_attribute(unsigned, const std::string &);
107 DEPRECATED void bind_attribute(VertexComponent, const std::string &);
108 DEPRECATED void bind_fragment_data(unsigned, const std::string &);
112 static void require_type(GLenum);
113 void query_uniforms();
114 void query_uniform_blocks(const std::vector<UniformInfo *> &);
115 void query_attributes();
116 static LayoutHash compute_layout_hash(const std::vector<const UniformInfo *> &);
117 static bool uniform_location_compare(const UniformInfo *, const UniformInfo *);
119 bool is_linked() const { return linked; }
120 DEPRECATED std::string get_info_log() const;
122 LayoutHash get_uniform_layout_hash() const { return uniform_layout_hash; }
123 const UniformBlockMap &get_uniform_blocks() const { return uniform_blocks; }
124 const UniformBlockInfo &get_uniform_block_info(const std::string &) const;
125 const UniformMap &get_uniforms() const { return uniforms; }
126 const UniformInfo &get_uniform_info(const std::string &) const;
127 int get_uniform_location(const std::string &) const;
128 const AttributeMap &get_attributes() const { return attributes; }
129 const AttributeInfo &get_attribute_info(const std::string &) const;
130 int get_attribute_location(const std::string &) const;
133 static void unbind();