1 #ifndef MSP_GL_PROGRAM_H_
2 #define MSP_GL_PROGRAM_H_
6 #include <msp/datafile/objectloader.h>
11 #include "vertexformat.h"
19 A complete shader program. Programs can be assembled of individual Shaders or
20 generated with a set of standard features.
22 class Program: public Bindable<Program>
25 class Loader: public DataFile::CollectionObjectLoader<Program>
28 Loader(Program &, Collection &);
31 virtual void finish();
33 void attribute(unsigned, const std::string &);
34 void fragment_shader(const std::string &);
35 void geometry_shader(const std::string &);
36 void module(const std::string &);
37 void vertex_shader(const std::string &);
41 class SpecializationLoader: public DataFile::Loader
44 std::map<std::string, int> &spec_values;
46 static ActionMap shared_actions;
49 SpecializationLoader(std::map<std::string, int> &);
52 virtual void init_actions();
54 void specialize_bool(const std::string &, bool);
55 void specialize_int(const std::string &, int);
59 typedef unsigned LayoutHash;
60 struct UniformBlockInfo;
65 const UniformBlockInfo *block;
72 unsigned array_stride;
73 unsigned matrix_stride;
79 struct UniformBlockInfo
84 std::vector<const UniformInfo *> uniforms;
85 LayoutHash layout_hash;
103 std::map<std::string, unsigned> textures;
104 std::map<std::string, unsigned> blocks;
108 std::vector<unsigned> stage_ids;
109 const Module *module;
112 std::vector<UniformBlockInfo> uniform_blocks;
113 std::vector<UniformInfo> uniforms;
114 LayoutHash uniform_layout_hash;
115 std::vector<AttributeInfo> attributes;
118 /// Constructs an empty Program with no shader stages attached.
121 /// Constructs a Program from unified source code using ProgramCompiler.
122 DEPRECATED Program(const std::string &);
124 /// Constructs a Program from vertex and fragment shader source code.
125 DEPRECATED Program(const std::string &, const std::string &);
127 /// Constructs a Program from a Module, with specialization constants.
128 Program(const Module &, const std::map<std::string, int> & = std::map<std::string, int>());
135 void add_stages(const Module &, const std::map<std::string, int> & = std::map<std::string, int>());
137 unsigned add_stage(GLenum);
138 void add_glsl_stages(const GlslModule &, const std::map<std::string, int> &);
139 void compile_glsl_stage(unsigned);
140 void add_spirv_stages(const SpirVModule &, const std::map<std::string, int> &);
143 DEPRECATED void attach_shader(Shader &shader);
144 DEPRECATED void attach_shader_owned(Shader *shader);
145 DEPRECATED void detach_shader(Shader &shader);
146 DEPRECATED const std::vector<Shader *> &get_attached_shaders() const;
148 DEPRECATED void bind_attribute(unsigned, const std::string &);
149 DEPRECATED void bind_attribute(VertexAttribute, const std::string &);
150 DEPRECATED void bind_fragment_data(unsigned, const std::string &);
154 void query_uniforms();
155 void query_uniform_blocks(const std::vector<UniformInfo *> &);
156 void query_attributes();
157 void collect_uniforms();
158 void collect_block_uniforms(const SpirVModule::Structure &, const std::string &, unsigned, std::vector<std::string> &);
159 void collect_attributes();
160 void update_layout_hash();
161 static LayoutHash compute_layout_hash(const std::vector<const UniformInfo *> &);
162 static bool uniform_location_compare(const UniformInfo *, const UniformInfo *);
163 static bool uniform_name_compare(const UniformInfo &, const UniformInfo &);
165 static bool name_search(const T &, const std::string &);
167 bool is_linked() const { return linked; }
168 DEPRECATED std::string get_info_log() const;
170 LayoutHash get_uniform_layout_hash() const { return uniform_layout_hash; }
171 const std::vector<UniformBlockInfo> &get_uniform_blocks() const { return uniform_blocks; }
172 const UniformBlockInfo &get_uniform_block_info(const std::string &) const;
173 const std::vector<UniformInfo> &get_uniforms() const { return uniforms; }
174 const UniformInfo &get_uniform_info(const std::string &) const;
175 int get_uniform_location(const std::string &) const;
176 const std::vector<AttributeInfo> &get_attributes() const { return attributes; }
177 const AttributeInfo &get_attribute_info(const std::string &) const;
178 int get_attribute_location(const std::string &) const;
181 static void unbind();