return stage_id;
}
-void OpenGLProgram::add_glsl_stages(const GlslModule &mod, const map<string, int> &spec_values, TransientData &transient)
+void OpenGLProgram::add_glsl_stages(const GlslModule &mod, const map<string, int> &spec_values)
{
SL::Compiler compiler(Device::get_current().get_info().glsl_features);
compiler.set_source(mod.get_prepared_source(), "<module>");
compile_glsl_stage(mod, stage_id);
}
- transient.textures = compiler.get_texture_bindings();
- transient.blocks = compiler.get_uniform_block_bindings();
-
ReflectData &rd = static_cast<Program *>(this)->reflect_data;
rd.n_clip_distances = compiler.get_n_clip_distances();
+
+ link(mod);
+ query_uniforms();
+ query_attributes();
+
+ const map<string, unsigned> &block_bindings = compiler.get_uniform_block_bindings();
+ if(!block_bindings.empty())
+ {
+ for(unsigned i=0; i<rd.uniform_blocks.size(); ++i)
+ {
+ auto j = block_bindings.find(rd.uniform_blocks[i].name);
+ if(j!=block_bindings.end())
+ {
+ glUniformBlockBinding(id, i, j->second);
+ rd.uniform_blocks[i].bind_point = j->second;
+ }
+ }
+ }
+
+ const map<string, unsigned> &tex_bindings = compiler.get_texture_bindings();
+ if(!tex_bindings.empty())
+ {
+ if(!ARB_separate_shader_objects)
+ glUseProgram(id);
+ for(const auto &kvp: tex_bindings)
+ {
+ int location = static_cast<const Program *>(this)->get_uniform_location(kvp.first);
+ if(location>=0)
+ {
+ if(ARB_separate_shader_objects)
+ glProgramUniform1i(id, location, kvp.second);
+ else
+ glUniform1i(location, kvp.second);
+ }
+ }
+ }
}
void OpenGLProgram::compile_glsl_stage(const GlslModule &mod, unsigned stage_id)
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]);
+
+ link(mod);
}
-void OpenGLProgram::finalize(const Module &mod, TransientData &transient)
+void OpenGLProgram::link(const Module &mod)
{
glLinkProgram(id);
int status = 0;
if(!info_log.empty())
IO::print("Program link info log:\n%s", info_log);
#endif
-
- if(mod.get_format()==Module::GLSL)
- {
- query_uniforms();
- query_attributes();
- apply_bindings(transient);
- }
}
void OpenGLProgram::query_uniforms()
}
}
-void OpenGLProgram::apply_bindings(const TransientData &transient)
-{
- ReflectData &rd = static_cast<Program *>(this)->reflect_data;
-
- for(unsigned i=0; i<rd.uniform_blocks.size(); ++i)
- {
- auto j = transient.blocks.find(rd.uniform_blocks[i].name);
- if(j!=transient.blocks.end())
- {
- glUniformBlockBinding(id, i, j->second);
- rd.uniform_blocks[i].bind_point = j->second;
- }
- }
-
- if(!ARB_separate_shader_objects)
- glUseProgram(id);
- for(const auto &kvp: transient.textures)
- {
- int location = static_cast<const Program *>(this)->get_uniform_location(kvp.first);
- if(location>=0)
- {
- if(ARB_separate_shader_objects)
- glProgramUniform1i(id, location, kvp.second);
- else
- glUniform1i(location, kvp.second);
- }
- }
-}
-
void OpenGLProgram::finalize_uniforms()
{
ReflectData &rd = static_cast<Program *>(this)->reflect_data;
MAX_STAGES
};
- struct TransientData
- {
- std::map<std::string, unsigned> textures;
- std::map<std::string, unsigned> blocks;
- };
-
struct UniformCall
{
using FuncPtr = void (*)(unsigned, unsigned, const void *);
bool has_stages() const;
unsigned add_stage(Stage);
- void add_glsl_stages(const GlslModule &, const std::map<std::string, int> &, TransientData &);
+ void add_glsl_stages(const GlslModule &, const std::map<std::string, int> &);
void compile_glsl_stage(const GlslModule &, unsigned);
void add_spirv_stages(const SpirVModule &, const std::map<std::string, int> &);
- void finalize(const Module &, TransientData &);
+ void link(const Module &);
void query_uniforms();
void query_uniform_blocks(const std::vector<ReflectData::UniformInfo *> &);
void query_attributes();
- void apply_bindings(const TransientData &);
void finalize_uniforms();
void set_debug_name(const std::string &);