- const vector<SpirVModule::EntryPoint> &entry_points = mod.get_entry_points();
- unsigned n_stages = 0;
- unsigned used_stage_ids[MAX_STAGES];
- for(vector<SpirVModule::EntryPoint>::const_iterator i=entry_points.begin(); i!=entry_points.end(); ++i)
- {
- unsigned stage_id = 0;
- switch(i->stage)
- {
- case SpirVModule::VERTEX: stage_id = add_stage(VERTEX); break;
- case SpirVModule::GEOMETRY: stage_id = add_stage(GEOMETRY); break;
- case SpirVModule::FRAGMENT: stage_id = add_stage(FRAGMENT); break;
- default: throw invalid_operation("Program::add_spirv_stages");
- }
-
- used_stage_ids[n_stages++] = stage_id;
- }
-
- const vector<UInt32> &code = mod.get_code();
- glShaderBinary(n_stages, used_stage_ids, GL_SHADER_BINARY_FORMAT_SPIR_V, &code[0], code.size()*4);
-
- if(!spec_values.empty() && !transient)
- transient = new TransientData;
-
- const vector<SpirVModule::Constant> &spec_consts = mod.get_spec_constants();
- vector<unsigned> spec_id_array;
- vector<unsigned> spec_value_array;
- spec_id_array.reserve(spec_consts.size());
- spec_value_array.reserve(spec_consts.size());
- for(vector<SpirVModule::Constant>::const_iterator i=spec_consts.begin(); i!=spec_consts.end(); ++i)
- {
- map<string, int>::const_iterator j = spec_values.find(i->name);
- if(j!=spec_values.end())
- {
- spec_id_array.push_back(i->constant_id);
- spec_value_array.push_back(j->second);
- transient->spec_values[i->constant_id] = j->second;
- }
- }
-
- vector<SpirVModule::EntryPoint>::const_iterator j=entry_points.begin();
- for(unsigned i=0; i<MAX_STAGES; ++i)
- if(stage_ids[i])
- glSpecializeShader(stage_ids[i], j->name.c_str(), spec_id_array.size(), &spec_id_array[0], &spec_value_array[0]);
-}
-
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
-void Program::attach_shader(Shader &shader)
-{
- unsigned shader_id = shader.steal_id();
- if(!shader_id)
- throw invalid_argument("Program::attach_shader");
-
- int type;
- glGetShaderiv(shader_id, GL_SHADER_TYPE, &type);
- switch(type)
- {
- case GL_VERTEX_SHADER: stage_ids[VERTEX] = shader_id; break;
- case GL_GEOMETRY_SHADER: stage_ids[GEOMETRY] = shader_id; break;
- case GL_FRAGMENT_SHADER: stage_ids[FRAGMENT] = shader_id; break;
- }
-
- glAttachShader(id, shader_id);
- compile_glsl_stage(shader_id);
-}
-
-void Program::attach_shader_owned(Shader *shader)
-{
- attach_shader(*shader);
- delete shader;
-}
-
-void Program::detach_shader(Shader &)
-{
-}
-
-const vector<Shader *> &Program::get_attached_shaders() const
-{
- static vector<Shader *> dummy;
- return dummy;
-}
-
-void Program::bind_attribute(unsigned index, const string &name)
-{
- static Require _req(ARB_vertex_shader);
- glBindAttribLocation(id, index, name.c_str());
-}
-
-void Program::bind_attribute(VertexAttribute attr, const string &name)
-{
- bind_attribute(get_attribute_semantic(attr), name);
-}
-
-void Program::bind_fragment_data(unsigned index, const string &name)
-{
- static Require _req(EXT_gpu_shader4);
- glBindFragDataLocation(id, index, name.c_str());
-}
-#pragma GCC diagnostic pop
-
-void Program::link()
-{
- if(!has_stages())
- throw invalid_operation("Program::link");
-
- uniforms.clear();
- uniform_blocks.clear();
- attributes.clear();
-
- glLinkProgram(id);
- linked = get_program_i(id, GL_LINK_STATUS);
-
- GLsizei info_log_len = get_program_i(id, GL_INFO_LOG_LENGTH);
- string info_log(info_log_len+1, 0);
- glGetProgramInfoLog(id, info_log_len+1, &info_log_len, &info_log[0]);
- info_log.erase(info_log_len);
- if(module && module->get_format()==Module::GLSL)
- info_log = static_cast<const GlslModule *>(module)->get_source_map().translate_errors(info_log);
-
- if(!linked)
- throw compile_error(info_log);
-#ifdef DEBUG
- if(!info_log.empty())
- IO::print("Program link info log:\n%s", info_log);
-#endif
-
- if(module->get_format()==Module::GLSL)