link();
}
+Program::Program(const Module &mod, const map<string, int> &spec_values)
+{
+ init();
+ add_stages(mod, spec_values);
+ link();
+}
+
void Program::init()
{
static Require _req(ARB_shader_objects);
glDeleteProgram(id);
}
-void Program::add_stages(const Module &mod)
+void Program::add_stages(const Module &mod, const map<string, int> &spec_values)
{
module = &mod;
SL::Compiler compiler;
compiler.set_source(module->get_prepared_source(), "<module>");
+ compiler.specialize(spec_values);
compiler.compile(SL::Compiler::PROGRAM);
vector<SL::Stage::Type> stages = compiler.get_stages();
void Program::Loader::module(const string &n)
{
- obj.add_stages(get_collection().get<Module>(n));
+ map<string, int> spec_values;
+ SpecializationLoader ldr(spec_values);
+ load_sub_with(ldr);
+ obj.add_stages(get_collection().get<Module>(n), spec_values);
}
#pragma GCC diagnostic push
}
#pragma GCC diagnostic pop
+
+DataFile::Loader::ActionMap Program::SpecializationLoader::shared_actions;
+
+Program::SpecializationLoader::SpecializationLoader(map<string, int> &sv):
+ spec_values(sv)
+{
+ set_actions(shared_actions);
+}
+
+void Program::SpecializationLoader::init_actions()
+{
+ add("specialize", &SpecializationLoader::specialize_bool);
+ add("specialize", &SpecializationLoader::specialize_int);
+}
+
+void Program::SpecializationLoader::specialize_bool(const string &name, bool value)
+{
+ spec_values[name] = value;
+}
+
+void Program::SpecializationLoader::specialize_int(const string &name, int value)
+{
+ spec_values[name] = value;
+}
+
} // namespace GL
} // namespace Msp
void vertex_shader(const std::string &);
};
+private:
+ class SpecializationLoader: public DataFile::Loader
+ {
+ private:
+ std::map<std::string, int> &spec_values;
+
+ static ActionMap shared_actions;
+
+ public:
+ SpecializationLoader(std::map<std::string, int> &);
+
+ private:
+ virtual void init_actions();
+
+ void specialize_bool(const std::string &, bool);
+ void specialize_int(const std::string &, int);
+ };
+
+public:
typedef unsigned LayoutHash;
struct UniformBlockInfo;
AttributeMap attributes;
public:
- /// Constructs an empty Program with no Shaders attached.
+ /// Constructs an empty Program with no shader stages attached.
Program();
/// Constructs a Program from unified source code using ProgramCompiler.
- Program(const std::string &);
+ DEPRECATED Program(const std::string &);
/// Constructs a Program from vertex and fragment shader source code.
DEPRECATED Program(const std::string &, const std::string &);
+ /// Constructs a Program from a Module, with specialization constants.
+ Program(const Module &, const std::map<std::string, int> & = std::map<std::string, int>());
+
private:
void init();
public:
virtual ~Program();
- void add_stages(const Module &);
+ void add_stages(const Module &, const std::map<std::string, int> & = std::map<std::string, int>());
DEPRECATED void attach_shader(Shader &shader);
DEPRECATED void attach_shader_owned(Shader *shader);