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 &);
40 class SpecializationLoader: public DataFile::Loader
43 std::map<std::string, int> &spec_values;
45 static ActionMap shared_actions;
48 SpecializationLoader(std::map<std::string, int> &);
51 virtual void init_actions();
53 void specialize_bool(const std::string &, bool);
54 void specialize_int(const std::string &, int);
58 typedef unsigned LayoutHash;
59 struct UniformBlockInfo;
64 const UniformBlockInfo *block;
67 unsigned array_stride;
68 unsigned matrix_stride;
72 struct UniformBlockInfo
77 std::vector<const UniformInfo *> uniforms;
78 LayoutHash layout_hash;
89 typedef std::map<std::string, UniformInfo> UniformMap;
90 typedef std::map<std::string, UniformBlockInfo> UniformBlockMap;
91 typedef std::map<std::string, AttributeInfo> AttributeMap;
95 std::vector<unsigned> shader_ids;
98 UniformBlockMap uniform_blocks;
100 LayoutHash uniform_layout_hash;
101 AttributeMap attributes;
104 /// Constructs an empty Program with no shader stages attached.
107 /// Constructs a Program from unified source code using ProgramCompiler.
108 DEPRECATED Program(const std::string &);
110 /// Constructs a Program from vertex and fragment shader source code.
111 DEPRECATED Program(const std::string &, const std::string &);
113 /// Constructs a Program from a Module, with specialization constants.
114 Program(const Module &, const std::map<std::string, int> & = std::map<std::string, int>());
121 void add_stages(const Module &, const std::map<std::string, int> & = std::map<std::string, int>());
123 DEPRECATED void attach_shader(Shader &shader);
124 DEPRECATED void attach_shader_owned(Shader *shader);
125 DEPRECATED void detach_shader(Shader &shader);
126 DEPRECATED const std::vector<Shader *> &get_attached_shaders() const;
128 DEPRECATED void bind_attribute(unsigned, const std::string &);
129 DEPRECATED void bind_attribute(VertexAttribute, const std::string &);
130 DEPRECATED void bind_fragment_data(unsigned, const std::string &);
134 static void require_type(GLenum);
135 void query_uniforms();
136 void query_uniform_blocks(const std::vector<UniformInfo *> &);
137 void query_attributes();
138 static LayoutHash compute_layout_hash(const std::vector<const UniformInfo *> &);
139 static bool uniform_location_compare(const UniformInfo *, const UniformInfo *);
141 bool is_linked() const { return linked; }
142 DEPRECATED std::string get_info_log() const;
144 LayoutHash get_uniform_layout_hash() const { return uniform_layout_hash; }
145 const UniformBlockMap &get_uniform_blocks() const { return uniform_blocks; }
146 const UniformBlockInfo &get_uniform_block_info(const std::string &) const;
147 const UniformMap &get_uniforms() const { return uniforms; }
148 const UniformInfo &get_uniform_info(const std::string &) const;
149 int get_uniform_location(const std::string &) const;
150 const AttributeMap &get_attributes() const { return attributes; }
151 const AttributeInfo &get_attribute_info(const std::string &) const;
152 int get_attribute_location(const std::string &) const;
155 static void unbind();