1 #ifndef MSP_GL_PROGRAM_H_
2 #define MSP_GL_PROGRAM_H_
6 #include <msp/datafile/objectloader.h>
12 #include "vertexformat.h"
20 A complete shader program. Programs can be assembled of individual Shaders or
21 generated with a set of standard features.
23 class Program: public Bindable<Program>
26 class Loader: public DataFile::CollectionObjectLoader<Program>
29 Loader(Program &, Collection &);
32 virtual void finish();
34 void attribute(unsigned, const std::string &);
35 void fragment_shader(const std::string &);
36 void geometry_shader(const std::string &);
37 void module(const std::string &);
38 void vertex_shader(const std::string &);
42 class SpecializationLoader: public DataFile::Loader
45 std::map<std::string, int> &spec_values;
47 static ActionMap shared_actions;
50 SpecializationLoader(std::map<std::string, int> &);
53 virtual void init_actions();
55 void specialize_bool(const std::string &, bool);
56 void specialize_int(const std::string &, int);
60 typedef unsigned LayoutHash;
61 struct UniformBlockInfo;
66 const UniformBlockInfo *block;
73 unsigned array_stride;
74 unsigned matrix_stride;
81 struct UniformBlockInfo
86 std::vector<const UniformInfo *> uniforms;
87 LayoutHash layout_hash;
105 std::map<std::string, unsigned> textures;
106 std::map<std::string, unsigned> blocks;
110 std::vector<unsigned> stage_ids;
111 const Module *module;
114 std::vector<UniformBlockInfo> uniform_blocks;
115 std::vector<UniformInfo> uniforms;
116 LayoutHash uniform_layout_hash;
117 std::vector<AttributeInfo> attributes;
120 /// Constructs an empty Program with no shader stages attached.
123 /// Constructs a Program from unified source code using ProgramCompiler.
124 DEPRECATED Program(const std::string &);
126 /// Constructs a Program from vertex and fragment shader source code.
127 DEPRECATED Program(const std::string &, const std::string &);
129 /// Constructs a Program from a Module, with specialization constants.
130 Program(const Module &, const std::map<std::string, int> & = std::map<std::string, int>());
137 void add_stages(const Module &, const std::map<std::string, int> & = std::map<std::string, int>());
139 unsigned add_stage(GLenum);
140 void add_glsl_stages(const GlslModule &, const std::map<std::string, int> &);
141 void compile_glsl_stage(unsigned);
142 void add_spirv_stages(const SpirVModule &, const std::map<std::string, int> &);
145 DEPRECATED void attach_shader(Shader &shader);
146 DEPRECATED void attach_shader_owned(Shader *shader);
147 DEPRECATED void detach_shader(Shader &shader);
148 DEPRECATED const std::vector<Shader *> &get_attached_shaders() const;
150 DEPRECATED void bind_attribute(unsigned, const std::string &);
151 DEPRECATED void bind_attribute(VertexAttribute, const std::string &);
152 DEPRECATED void bind_fragment_data(unsigned, const std::string &);
156 void query_uniforms();
157 void query_uniform_blocks(const std::vector<UniformInfo *> &);
158 void query_attributes();
159 void collect_uniforms();
160 void collect_block_uniforms(const SpirVModule::Structure &, const std::string &, unsigned, std::vector<std::string> &);
161 void collect_attributes();
162 void update_layout_hash();
163 static LayoutHash compute_layout_hash(const std::vector<const UniformInfo *> &);
164 static bool uniform_location_compare(const UniformInfo *, const UniformInfo *);
165 static bool uniform_tag_compare(const UniformInfo &, const UniformInfo &);
166 template<typename T, typename A, A T::*>
167 static bool search(const T &, const A &);
169 bool is_linked() const { return linked; }
170 DEPRECATED std::string get_info_log() const;
172 LayoutHash get_uniform_layout_hash() const { return uniform_layout_hash; }
173 const std::vector<UniformBlockInfo> &get_uniform_blocks() const { return uniform_blocks; }
174 const UniformBlockInfo &get_uniform_block_info(const std::string &) const;
175 const std::vector<UniformInfo> &get_uniforms() const { return uniforms; }
176 const UniformInfo &get_uniform_info(const std::string &) const;
177 const UniformInfo &get_uniform_info(Tag) const;
178 int get_uniform_location(const std::string &) const;
179 int get_uniform_location(Tag) const;
180 const std::vector<AttributeInfo> &get_attributes() const { return attributes; }
181 const AttributeInfo &get_attribute_info(const std::string &) const;
182 int get_attribute_location(const std::string &) const;
185 static void unbind();