]> git.tdb.fi Git - libs/gl.git/blobdiff - source/core/program.cpp
Split Module into a base class and format-specific class
[libs/gl.git] / source / core / program.cpp
index 6cad69c4e322200b86b7f439f239e01113fa90ea..789fa32473392d75a0bd34a13aac7208ddf14637 100644 (file)
@@ -35,7 +35,7 @@ Program::Program(const std::string &source)
 {
        init();
 
-       Module mod;
+       GlslModule mod;
        mod.set_source(source);
        add_stages(mod);
 
@@ -78,6 +78,15 @@ Program::~Program()
        glDeleteProgram(id);
 }
 
+void Program::add_stages(const Module &mod, const map<string, int> &spec_values)
+{
+       switch(mod.get_format())
+       {
+       case Module::GLSL: return add_glsl_stages(static_cast<const GlslModule &>(mod), spec_values);
+       default: throw invalid_argument("Program::add_stages");
+       }
+}
+
 unsigned Program::add_stage(GLenum type)
 {
        switch(type)
@@ -95,12 +104,12 @@ unsigned Program::add_stage(GLenum type)
        return stage_id;
 }
 
-void Program::add_stages(const Module &mod, const map<string, int> &spec_values)
+void Program::add_glsl_stages(const GlslModule &mod, const map<string, int> &spec_values)
 {
        module = &mod;
 
        SL::Compiler compiler;
-       compiler.set_source(module->get_prepared_source(), "<module>");
+       compiler.set_source(mod.get_prepared_source(), "<module>");
        compiler.specialize(spec_values);
        compiler.compile(SL::Compiler::PROGRAM);
 #ifdef DEBUG
@@ -140,11 +149,11 @@ void Program::add_stages(const Module &mod, const map<string, int> &spec_values)
                                glBindFragDataLocation(id, j->second, j->first.c_str());
                }
 
-               compile_stage(stage_id);
+               compile_glsl_stage(stage_id);
        }
 }
 
-void Program::compile_stage(unsigned stage_id)
+void Program::compile_glsl_stage(unsigned stage_id)
 {
        glCompileShader(stage_id);
        bool compiled = get_shader_i(stage_id, GL_COMPILE_STATUS);
@@ -153,8 +162,8 @@ void Program::compile_stage(unsigned stage_id)
        string info_log(info_log_len+1, 0);
        glGetShaderInfoLog(stage_id, info_log_len+1, &info_log_len, &info_log[0]);
        info_log.erase(info_log_len);
-       if(module)
-               info_log = module->get_source_map().translate_errors(info_log);
+       if(module && module->get_format()==Module::GLSL)
+               info_log = static_cast<const GlslModule *>(module)->get_source_map().translate_errors(info_log);
 
        if(!compiled)
                throw compile_error(info_log);
@@ -172,7 +181,7 @@ void Program::attach_shader(Shader &shader)
        if(!shader_id)
                throw invalid_argument("Program::attach_shader");
        stage_ids.push_back(shader_id);
-       compile_stage(shader_id);
+       compile_glsl_stage(shader_id);
 }
 
 void Program::attach_shader_owned(Shader *shader)
@@ -220,7 +229,8 @@ void Program::link()
        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);
-       info_log = module->get_source_map().translate_errors(info_log);
+       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);