3 #include <msp/core/algorithm.h>
4 #include <msp/core/hash.h>
5 #include <msp/core/maputils.h>
6 #include <msp/core/raii.h>
7 #include <msp/gl/extensions/arb_es2_compatibility.h>
8 #include <msp/gl/extensions/arb_fragment_shader.h>
9 #include <msp/gl/extensions/arb_gl_spirv.h>
10 #include <msp/gl/extensions/arb_geometry_shader4.h>
11 #include <msp/gl/extensions/arb_separate_shader_objects.h>
12 #include <msp/gl/extensions/arb_shader_objects.h>
13 #include <msp/gl/extensions/arb_uniform_buffer_object.h>
14 #include <msp/gl/extensions/arb_vertex_shader.h>
15 #include <msp/gl/extensions/ext_gpu_shader4.h>
16 #include <msp/gl/extensions/nv_non_square_matrices.h>
17 #include <msp/io/print.h>
18 #include <msp/strings/format.h>
23 #include "resources.h"
25 #include "glsl/compiler.h"
37 Program::Program(const string &source)
42 mod.set_source(source);
49 Program::Program(const string &vert, const string &frag)
53 #pragma GCC diagnostic push
54 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
55 attach_shader_owned(new VertexShader(vert));
56 attach_shader_owned(new FragmentShader(frag));
57 #pragma GCC diagnostic pop
61 Program::Program(const Module &mod, const map<string, int> &spec_values)
64 add_stages(mod, spec_values);
70 static Require _req(ARB_shader_objects);
72 id = glCreateProgram();
73 fill(stage_ids, stage_ids+MAX_STAGES, 0);
81 for(unsigned i=0; i<MAX_STAGES; ++i)
83 glDeleteShader(stage_ids[i]);
87 void Program::add_stages(const Module &mod, const map<string, int> &spec_values)
90 throw invalid_operation("Program::add_stages");
92 switch(mod.get_format())
94 case Module::GLSL: return add_glsl_stages(static_cast<const GlslModule &>(mod), spec_values);
95 case Module::SPIR_V: return add_spirv_stages(static_cast<const SpirVModule &>(mod), spec_values);
96 default: throw invalid_argument("Program::add_stages");
100 bool Program::has_stages() const
102 for(unsigned i=0; i<MAX_STAGES; ++i)
108 unsigned Program::add_stage(Stage type)
113 case VERTEX: { static Require _req(ARB_vertex_shader); gl_type = GL_VERTEX_SHADER; } break;
114 case GEOMETRY: { static Require _req(ARB_geometry_shader4); gl_type = GL_GEOMETRY_SHADER; } break;
115 case FRAGMENT: { static Require _req(ARB_fragment_shader); gl_type = GL_FRAGMENT_SHADER; } break;
116 default: throw invalid_argument("Program::add_stage");
120 throw invalid_operation("Program::add_stage");
122 unsigned stage_id = glCreateShader(gl_type);
123 stage_ids[type] = stage_id;
124 glAttachShader(id, stage_id);
129 void Program::add_glsl_stages(const GlslModule &mod, const map<string, int> &spec_values)
133 SL::Compiler compiler;
134 compiler.set_source(mod.get_prepared_source(), "<module>");
135 compiler.specialize(spec_values);
136 compiler.compile(SL::Compiler::PROGRAM);
138 string diagnostics = compiler.get_diagnostics();
139 if(!diagnostics.empty())
140 IO::print("Program diagnostics:\n%s\n", diagnostics);
143 vector<SL::Stage::Type> stages = compiler.get_stages();
144 for(vector<SL::Stage::Type>::const_iterator i=stages.begin(); i!=stages.end(); ++i)
146 unsigned stage_id = 0;
149 case SL::Stage::VERTEX: stage_id = add_stage(VERTEX); break;
150 case SL::Stage::GEOMETRY: stage_id = add_stage(GEOMETRY); break;
151 case SL::Stage::FRAGMENT: stage_id = add_stage(FRAGMENT); break;
152 default: throw invalid_operation("Program::add_glsl_stages");
155 string stage_src = compiler.get_stage_glsl(*i);
156 const char *src_ptr = stage_src.data();
157 int src_len = stage_src.size();
158 glShaderSource(stage_id, 1, &src_ptr, &src_len);
160 if(*i==SL::Stage::VERTEX)
162 const map<string, unsigned> &attribs = compiler.get_vertex_attributes();
163 for(map<string, unsigned>::const_iterator j=attribs.begin(); j!=attribs.end(); ++j)
164 glBindAttribLocation(id, j->second, j->first.c_str());
167 if(*i==SL::Stage::FRAGMENT && EXT_gpu_shader4)
169 const map<string, unsigned> &frag_outs = compiler.get_fragment_outputs();
170 for(map<string, unsigned>::const_iterator j=frag_outs.begin(); j!=frag_outs.end(); ++j)
171 glBindFragDataLocation(id, j->second, j->first.c_str());
174 compile_glsl_stage(stage_id);
178 transient = new TransientData;
179 transient->textures = compiler.get_texture_bindings();
180 transient->blocks = compiler.get_uniform_block_bindings();
183 void Program::compile_glsl_stage(unsigned stage_id)
185 glCompileShader(stage_id);
186 bool compiled = get_shader_i(stage_id, GL_COMPILE_STATUS);
188 GLsizei info_log_len = get_shader_i(stage_id, GL_INFO_LOG_LENGTH);
189 string info_log(info_log_len+1, 0);
190 glGetShaderInfoLog(stage_id, info_log_len+1, &info_log_len, &info_log[0]);
191 info_log.erase(info_log_len);
192 if(module && module->get_format()==Module::GLSL)
193 info_log = static_cast<const GlslModule *>(module)->get_source_map().translate_errors(info_log);
196 throw compile_error(info_log);
198 if(!info_log.empty())
199 IO::print("Shader compile info log:\n%s", info_log);
203 void Program::add_spirv_stages(const SpirVModule &mod, const map<string, int> &spec_values)
205 static Require _req(ARB_gl_spirv);
206 static Require _req2(ARB_ES2_compatibility);
210 const vector<SpirVModule::EntryPoint> &entry_points = mod.get_entry_points();
211 unsigned n_stages = 0;
212 unsigned used_stage_ids[MAX_STAGES];
213 for(vector<SpirVModule::EntryPoint>::const_iterator i=entry_points.begin(); i!=entry_points.end(); ++i)
215 unsigned stage_id = 0;
218 case SpirVModule::VERTEX: stage_id = add_stage(VERTEX); break;
219 case SpirVModule::GEOMETRY: stage_id = add_stage(GEOMETRY); break;
220 case SpirVModule::FRAGMENT: stage_id = add_stage(FRAGMENT); break;
221 default: throw invalid_operation("Program::add_spirv_stages");
224 used_stage_ids[n_stages++] = stage_id;
227 const vector<UInt32> &code = mod.get_code();
228 glShaderBinary(n_stages, used_stage_ids, GL_SHADER_BINARY_FORMAT_SPIR_V, &code[0], code.size()*4);
230 if(!spec_values.empty() && !transient)
231 transient = new TransientData;
233 const vector<SpirVModule::Constant> &spec_consts = mod.get_spec_constants();
234 vector<unsigned> spec_id_array;
235 vector<unsigned> spec_value_array;
236 spec_id_array.reserve(spec_consts.size());
237 spec_value_array.reserve(spec_consts.size());
238 for(vector<SpirVModule::Constant>::const_iterator i=spec_consts.begin(); i!=spec_consts.end(); ++i)
240 map<string, int>::const_iterator j = spec_values.find(i->name);
241 if(j!=spec_values.end())
243 spec_id_array.push_back(i->constant_id);
244 spec_value_array.push_back(j->second);
245 transient->spec_values[i->constant_id] = j->second;
249 vector<SpirVModule::EntryPoint>::const_iterator j=entry_points.begin();
250 for(unsigned i=0; i<MAX_STAGES; ++i)
252 glSpecializeShader(stage_ids[i], j->name.c_str(), spec_id_array.size(), &spec_id_array[0], &spec_value_array[0]);
255 #pragma GCC diagnostic push
256 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
257 void Program::attach_shader(Shader &shader)
259 unsigned shader_id = shader.steal_id();
261 throw invalid_argument("Program::attach_shader");
264 glGetShaderiv(shader_id, GL_SHADER_TYPE, &type);
267 case GL_VERTEX_SHADER: stage_ids[VERTEX] = shader_id; break;
268 case GL_GEOMETRY_SHADER: stage_ids[GEOMETRY] = shader_id; break;
269 case GL_FRAGMENT_SHADER: stage_ids[FRAGMENT] = shader_id; break;
272 glAttachShader(id, shader_id);
273 compile_glsl_stage(shader_id);
276 void Program::attach_shader_owned(Shader *shader)
278 attach_shader(*shader);
282 void Program::detach_shader(Shader &)
286 const vector<Shader *> &Program::get_attached_shaders() const
288 static vector<Shader *> dummy;
292 void Program::bind_attribute(unsigned index, const string &name)
294 static Require _req(ARB_vertex_shader);
295 glBindAttribLocation(id, index, name.c_str());
298 void Program::bind_attribute(VertexAttribute attr, const string &name)
300 bind_attribute(get_attribute_semantic(attr), name);
303 void Program::bind_fragment_data(unsigned index, const string &name)
305 static Require _req(EXT_gpu_shader4);
306 glBindFragDataLocation(id, index, name.c_str());
308 #pragma GCC diagnostic pop
313 throw invalid_operation("Program::link");
316 uniform_blocks.clear();
320 linked = get_program_i(id, GL_LINK_STATUS);
322 GLsizei info_log_len = get_program_i(id, GL_INFO_LOG_LENGTH);
323 string info_log(info_log_len+1, 0);
324 glGetProgramInfoLog(id, info_log_len+1, &info_log_len, &info_log[0]);
325 info_log.erase(info_log_len);
326 if(module && module->get_format()==Module::GLSL)
327 info_log = static_cast<const GlslModule *>(module)->get_source_map().translate_errors(info_log);
330 throw compile_error(info_log);
332 if(!info_log.empty())
333 IO::print("Program link info log:\n%s", info_log);
336 if(module->get_format()==Module::GLSL)
342 for(unsigned i=0; i<uniform_blocks.size(); ++i)
344 map<string, unsigned>::const_iterator j = transient->blocks.find(uniform_blocks[i].name);
345 if(j!=transient->blocks.end())
347 glUniformBlockBinding(id, i, j->second);
348 uniform_blocks[i].bind_point = j->second;
352 Conditional<BindRestore> _bind(!ARB_separate_shader_objects, this);
353 for(map<string, unsigned>::const_iterator i=transient->textures.begin(); i!=transient->textures.end(); ++i)
355 int location = get_uniform_location(i->first);
358 if(ARB_separate_shader_objects)
359 glProgramUniform1i(id, location, i->second);
361 glUniform1i(location, i->second);
366 else if(module->get_format()==Module::SPIR_V)
369 collect_attributes();
375 for(vector<UniformInfo>::const_iterator i=uniforms.begin(); i!=uniforms.end(); ++i)
376 require_type(i->type);
377 for(vector<AttributeInfo>::const_iterator i=attributes.begin(); i!=attributes.end(); ++i)
378 require_type(i->type);
381 void Program::query_uniforms()
383 unsigned count = get_program_i(id, GL_ACTIVE_UNIFORMS);
384 uniforms.reserve(count);
385 vector<string> uniform_names(count);
386 for(unsigned i=0; i<count; ++i)
392 glGetActiveUniform(id, i, sizeof(name), &len, &size, &type, name);
393 if(len && strncmp(name, "gl_", 3))
395 /* Some implementations report the first element of a uniform array,
396 others report just the name of the array itself. */
397 if(len>3 && !strcmp(name+len-3, "[0]"))
400 uniforms.push_back(UniformInfo());
401 UniformInfo &info = uniforms.back();
404 info.array_size = size;
405 info.type = from_gl_type(type);
406 uniform_names[i] = name;
410 sort_member(uniforms, &UniformInfo::tag);
412 if(ARB_uniform_buffer_object)
414 vector<UniformInfo *> uniforms_by_index(count);
415 for(unsigned i=0; i<count; ++i)
416 if(!uniform_names[i].empty())
417 // The element is already known to be present
418 uniforms_by_index[i] = &*lower_bound_member(uniforms, Tag(uniform_names[i]), &UniformInfo::tag);
419 query_uniform_blocks(uniforms_by_index);
422 uniform_blocks.push_back(UniformBlockInfo());
423 UniformBlockInfo &default_block = uniform_blocks.back();
425 for(vector<UniformInfo>::iterator i=uniforms.begin(); i!=uniforms.end(); ++i)
428 i->location = glGetUniformLocation(id, i->name.c_str());
429 i->block = &default_block;
430 default_block.uniforms.push_back(&*i);
432 if(is_image(i->type) && i->location>=0)
433 glGetUniformiv(id, i->location, &i->binding);
436 default_block.layout_hash = compute_layout_hash(default_block.uniforms);
438 update_layout_hash();
441 void Program::query_uniform_blocks(const vector<UniformInfo *> &uniforms_by_index)
443 unsigned count = get_program_i(id, GL_ACTIVE_UNIFORM_BLOCKS);
444 // Reserve an extra index for the default block
445 uniform_blocks.reserve(count+1);
446 for(unsigned i=0; i<count; ++i)
450 glGetActiveUniformBlockName(id, i, sizeof(name), &len, name);
451 uniform_blocks.push_back(UniformBlockInfo());
452 UniformBlockInfo &info = uniform_blocks.back();
456 glGetActiveUniformBlockiv(id, i, GL_UNIFORM_BLOCK_DATA_SIZE, &value);
457 info.data_size = value;
459 glGetActiveUniformBlockiv(id, i, GL_UNIFORM_BLOCK_BINDING, &value);
460 info.bind_point = value;
462 glGetActiveUniformBlockiv(id, i, GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS, &value);
463 vector<int> indices(value);
464 glGetActiveUniformBlockiv(id, i, GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES, &indices[0]);
465 for(vector<int>::iterator j=indices.begin(); j!=indices.end(); ++j)
467 if(!uniforms_by_index[*j])
468 throw logic_error("Program::link");
469 info.uniforms.push_back(uniforms_by_index[*j]);
470 uniforms_by_index[*j]->block = &info;
473 vector<unsigned> query_indices(indices.begin(), indices.end());
474 vector<int> values(indices.size());
475 glGetActiveUniformsiv(id, query_indices.size(), &query_indices[0], GL_UNIFORM_OFFSET, &values[0]);
476 for(unsigned j=0; j<indices.size(); ++j)
477 uniforms_by_index[indices[j]]->offset = values[j];
479 query_indices.clear();
480 for(vector<int>::iterator j=indices.begin(); j!=indices.end(); ++j)
481 if(uniforms_by_index[*j]->array_size>1)
482 query_indices.push_back(*j);
483 if(!query_indices.empty())
485 glGetActiveUniformsiv(id, query_indices.size(), &query_indices[0], GL_UNIFORM_ARRAY_STRIDE, &values[0]);
486 for(unsigned j=0; j<query_indices.size(); ++j)
487 uniforms_by_index[query_indices[j]]->array_stride = values[j];
490 query_indices.clear();
491 for(vector<int>::iterator j=indices.begin(); j!=indices.end(); ++j)
493 DataType t = uniforms_by_index[*j]->type;
495 query_indices.push_back(*j);
497 if(!query_indices.empty())
499 glGetActiveUniformsiv(id, query_indices.size(), &query_indices[0], GL_UNIFORM_MATRIX_STRIDE, &values[0]);
500 for(unsigned j=0; j<query_indices.size(); ++j)
501 uniforms_by_index[query_indices[j]]->matrix_stride = values[j];
504 sort(info.uniforms, uniform_location_compare);
505 info.layout_hash = compute_layout_hash(info.uniforms);
509 void Program::query_attributes()
511 unsigned count = get_program_i(id, GL_ACTIVE_ATTRIBUTES);
512 attributes.reserve(count);
513 for(unsigned i=0; i<count; ++i)
519 glGetActiveAttrib(id, i, sizeof(name), &len, &size, &type, name);
520 if(len && strncmp(name, "gl_", 3))
522 if(len>3 && !strcmp(name+len-3, "[0]"))
525 attributes.push_back(AttributeInfo());
526 AttributeInfo &info = attributes.back();
528 info.location = glGetAttribLocation(id, name);
529 info.array_size = size;
530 info.type = from_gl_type(type);
535 void Program::collect_uniforms()
537 const SpirVModule &mod = static_cast<const SpirVModule &>(*module);
539 // Prepare the default block
540 uniform_blocks.push_back(UniformBlockInfo());
541 vector<vector<string> > block_uniform_names(1);
543 const vector<SpirVModule::Variable> &variables = mod.get_variables();
544 for(vector<SpirVModule::Variable>::const_iterator i=variables.begin(); i!=variables.end(); ++i)
546 if(i->storage==SpirVModule::UNIFORM && i->struct_type)
548 uniform_blocks.push_back(UniformBlockInfo());
549 UniformBlockInfo &info = uniform_blocks.back();
550 info.name = i->struct_type->name;
551 info.bind_point = i->binding;
552 info.data_size = i->struct_type->size;
556 prefix = i->struct_type->name+".";
557 block_uniform_names.push_back(vector<string>());
558 collect_block_uniforms(*i->struct_type, prefix, 0, block_uniform_names.back());
560 else if(i->storage==SpirVModule::UNIFORM_CONSTANT && i->location>=0)
562 block_uniform_names[0].push_back(i->name);
563 uniforms.push_back(UniformInfo());
564 UniformInfo &info = uniforms.back();
567 info.location = i->location;
568 info.binding = i->binding;
569 info.array_size = i->array_size;
574 sort_member(uniforms, &UniformInfo::tag);
576 for(unsigned i=0; i<uniform_blocks.size(); ++i)
578 UniformBlockInfo &block = uniform_blocks[i];
579 const vector<string> &names = block_uniform_names[i];
580 for(vector<string>::const_iterator j=names.begin(); j!=names.end(); ++j)
582 // The element is already known to be present
583 UniformInfo &uni = *lower_bound_member(uniforms, Tag(*j), &UniformInfo::tag);
584 block.uniforms.push_back(&uni);
587 sort(block.uniforms, uniform_location_compare);
588 block.layout_hash = compute_layout_hash(block.uniforms);
591 update_layout_hash();
594 void Program::collect_block_uniforms(const SpirVModule::Structure &strct, const string &prefix, unsigned base_offset, vector<string> &uniform_names)
596 for(vector<SpirVModule::StructMember>::const_iterator i=strct.members.begin(); i!=strct.members.end(); ++i)
598 unsigned offset = base_offset+i->offset;
601 unsigned array_size = i->array_size;
602 if(i->array_size_spec)
604 array_size = i->array_size_spec->i_value;
607 map<unsigned, int>::const_iterator j = transient->spec_values.find(i->array_size_spec->constant_id);
608 if(j!=transient->spec_values.end())
609 array_size = j->second;
615 for(unsigned j=0; j<array_size; ++j, offset+=i->array_stride)
616 collect_block_uniforms(*i->struct_type, format("%s%s[%d].", prefix, i->name, j), offset, uniform_names);
619 collect_block_uniforms(*i->struct_type, prefix+i->name+".", offset, uniform_names);
623 string name = prefix+i->name;
624 uniform_names.push_back(name);
625 uniforms.push_back(UniformInfo());
626 UniformInfo &info = uniforms.back();
629 info.offset = offset;
630 info.array_size = i->array_size;
631 info.array_stride = i->array_stride;
632 info.matrix_stride = i->matrix_stride;
638 void Program::collect_attributes()
640 const SpirVModule &mod = static_cast<const SpirVModule &>(*module);
642 const vector<SpirVModule::EntryPoint> &entry_points = mod.get_entry_points();
643 for(vector<SpirVModule::EntryPoint>::const_iterator i=entry_points.begin(); i!=entry_points.end(); ++i)
644 if(i->stage==SpirVModule::VERTEX && i->name=="main")
646 for(vector<const SpirVModule::Variable *>::const_iterator j=i->globals.begin(); j!=i->globals.end(); ++j)
647 if((*j)->storage==SpirVModule::INPUT)
649 attributes.push_back(AttributeInfo());
650 AttributeInfo &info = attributes.back();
651 info.name = (*j)->name;
652 info.location = (*j)->location;
653 info.array_size = (*j)->array_size;
654 info.type = (*j)->type;
659 void Program::update_layout_hash()
661 string layout_descriptor;
662 for(vector<UniformBlockInfo>::const_iterator i=uniform_blocks.begin(); i!=uniform_blocks.end(); ++i)
663 layout_descriptor += format("%d:%x\n", i->bind_point, i->layout_hash);
664 uniform_layout_hash = hash32(layout_descriptor);
667 Program::LayoutHash Program::compute_layout_hash(const vector<const UniformInfo *> &uniforms)
669 string layout_descriptor;
670 for(vector<const UniformInfo *>::const_iterator i = uniforms.begin(); i!=uniforms.end(); ++i)
671 layout_descriptor += format("%d:%s:%x:%d\n", (*i)->location, (*i)->name, (*i)->type, (*i)->array_size);
672 return hash32(layout_descriptor);
675 bool Program::uniform_location_compare(const UniformInfo *uni1, const UniformInfo *uni2)
677 return uni1->location<uni2->location;
680 string Program::get_info_log() const
682 GLsizei len = get_program_i(id, GL_INFO_LOG_LENGTH);
683 string log(len+1, 0);
684 glGetProgramInfoLog(id, len+1, &len, &log[0]);
689 const Program::UniformBlockInfo &Program::get_uniform_block_info(const string &name) const
691 for(vector<UniformBlockInfo>::const_iterator i=uniform_blocks.begin(); i!=uniform_blocks.end(); ++i)
694 throw key_error(name);
697 const Program::UniformInfo &Program::get_uniform_info(const string &name) const
699 vector<UniformInfo>::const_iterator i = lower_bound_member(uniforms, Tag(name), &UniformInfo::tag);
700 if(i==uniforms.end() || i->name!=name)
701 throw key_error(name);
705 const Program::UniformInfo &Program::get_uniform_info(Tag tag) const
707 vector<UniformInfo>::const_iterator i = lower_bound_member(uniforms, tag, &UniformInfo::tag);
708 if(i==uniforms.end() || i->tag!=tag)
709 throw key_error(tag);
713 int Program::get_uniform_location(const string &name) const
715 if(name[name.size()-1]==']')
716 throw invalid_argument("Program::get_uniform_location");
718 vector<UniformInfo>::const_iterator i = lower_bound_member(uniforms, Tag(name), &UniformInfo::tag);
719 return i!=uniforms.end() && i->name==name && i->block->bind_point<0 ? i->location : -1;
722 int Program::get_uniform_location(Tag tag) const
724 vector<UniformInfo>::const_iterator i = lower_bound_member(uniforms, tag, &UniformInfo::tag);
725 return i!=uniforms.end() && i->tag==tag && i->block->bind_point<0 ? i->location : -1;
728 int Program::get_uniform_binding(Tag tag) const
730 vector<UniformInfo>::const_iterator i = lower_bound_member(uniforms, tag, &UniformInfo::tag);
731 return i!=uniforms.end() && i->tag==tag ? i->binding : -1;
734 const Program::AttributeInfo &Program::get_attribute_info(const string &name) const
736 vector<AttributeInfo>::const_iterator i = lower_bound_member(attributes, name, &AttributeInfo::name);
737 if(i==attributes.end() || i->name!=name)
738 throw key_error(name);
742 int Program::get_attribute_location(const string &name) const
744 if(name[name.size()-1]==']')
745 throw invalid_argument("Program::get_attribute_location");
747 vector<AttributeInfo>::const_iterator i = lower_bound_member(attributes, name, &AttributeInfo::name);
748 return i!=attributes.end() && i->name==name ? i->location : -1;
751 void Program::bind() const
754 throw invalid_operation("Program::bind");
756 if(!set_current(this))
762 void Program::unbind()
771 Program::UniformInfo::UniformInfo():
782 Program::UniformBlockInfo::UniformBlockInfo():
789 Program::AttributeInfo::AttributeInfo():
796 Program::Loader::Loader(Program &p, Collection &c):
797 DataFile::CollectionObjectLoader<Program>(p, &c)
799 add("module", &Loader::module);
802 add("attribute", &Loader::attribute);
803 add("fragment_shader", &Loader::fragment_shader);
804 add("geometry_shader", &Loader::geometry_shader);
805 add("vertex_shader", &Loader::vertex_shader);
808 void Program::Loader::finish()
813 void Program::Loader::module(const string &n)
815 map<string, int> spec_values;
816 SpecializationLoader ldr(spec_values);
818 obj.add_stages(get_collection().get<Module>(n), spec_values);
821 #pragma GCC diagnostic push
822 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
823 void Program::Loader::attribute(unsigned i, const string &n)
825 obj.bind_attribute(i, n);
828 void Program::Loader::fragment_shader(const string &src)
830 obj.attach_shader_owned(new FragmentShader(src));
833 void Program::Loader::geometry_shader(const string &src)
835 obj.attach_shader_owned(new GeometryShader(src));
838 void Program::Loader::vertex_shader(const string &src)
840 obj.attach_shader_owned(new VertexShader(src));
842 #pragma GCC diagnostic pop
845 DataFile::Loader::ActionMap Program::SpecializationLoader::shared_actions;
847 Program::SpecializationLoader::SpecializationLoader(map<string, int> &sv):
850 set_actions(shared_actions);
853 void Program::SpecializationLoader::init_actions()
855 add("specialize", &SpecializationLoader::specialize_bool);
856 add("specialize", &SpecializationLoader::specialize_int);
859 void Program::SpecializationLoader::specialize_bool(const string &name, bool value)
861 spec_values[name] = value;
864 void Program::SpecializationLoader::specialize_int(const string &name, int value)
866 spec_values[name] = value;