X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fcore%2Fprogram.cpp;h=dd22033e7e4369df1fa7818dbc59f70f29436bb1;hb=7c069241318b7133ac2df65ee13cb1d2968c5974;hp=6cad69c4e322200b86b7f439f239e01113fa90ea;hpb=4c705a6fba590514bc3fab2a324c24fddc30cac6;p=libs%2Fgl.git diff --git a/source/core/program.cpp b/source/core/program.cpp index 6cad69c4..dd22033e 100644 --- a/source/core/program.cpp +++ b/source/core/program.cpp @@ -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,18 @@ Program::~Program() glDeleteProgram(id); } +void Program::add_stages(const Module &mod, const map &spec_values) +{ + if(!stage_ids.empty()) + throw invalid_operation("Program::add_stages"); + + switch(mod.get_format()) + { + case Module::GLSL: return add_glsl_stages(static_cast(mod), spec_values); + default: throw invalid_argument("Program::add_stages"); + } +} + unsigned Program::add_stage(GLenum type) { switch(type) @@ -95,12 +107,12 @@ unsigned Program::add_stage(GLenum type) return stage_id; } -void Program::add_stages(const Module &mod, const map &spec_values) +void Program::add_glsl_stages(const GlslModule &mod, const map &spec_values) { module = &mod; SL::Compiler compiler; - compiler.set_source(module->get_prepared_source(), ""); + compiler.set_source(mod.get_prepared_source(), ""); compiler.specialize(spec_values); compiler.compile(SL::Compiler::PROGRAM); #ifdef DEBUG @@ -140,11 +152,11 @@ void Program::add_stages(const Module &mod, const map &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 +165,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(module)->get_source_map().translate_errors(info_log); if(!compiled) throw compile_error(info_log); @@ -172,7 +184,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) @@ -211,6 +223,9 @@ void Program::bind_fragment_data(unsigned index, const string &name) void Program::link() { + if(stage_ids.empty()) + throw invalid_operation("Program::link"); + uniforms.clear(); glLinkProgram(id); @@ -220,7 +235,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(module)->get_source_map().translate_errors(info_log); if(!linked) throw compile_error(info_log); @@ -238,21 +254,6 @@ void Program::link() require_type(i->second.type); } -void Program::require_type(GLenum t) -{ - switch(t) - { - case GL_FLOAT_MAT2x3: - case GL_FLOAT_MAT2x4: - case GL_FLOAT_MAT3x2: - case GL_FLOAT_MAT3x4: - case GL_FLOAT_MAT4x2: - case GL_FLOAT_MAT4x3: - { static Require _req(NV_non_square_matrices); } - break; - } -} - void Program::query_uniforms() { unsigned count = get_program_i(id, GL_ACTIVE_UNIFORMS); @@ -274,10 +275,10 @@ void Program::query_uniforms() UniformInfo &info = uniforms[name]; info.block = 0; info.name = name; - info.size = size; + info.array_size = size; info.array_stride = 0; info.matrix_stride = 0; - info.type = type; + info.type = from_gl_type(type); uniforms_by_index[i] = &info; } } @@ -342,7 +343,7 @@ void Program::query_uniform_blocks(const vector &uniforms_by_inde indices2.clear(); for(vector::iterator j=indices.begin(); j!=indices.end(); ++j) - if(uniforms_by_index[*j]->size>1) + if(uniforms_by_index[*j]->array_size>1) indices2.push_back(*j); if(!indices2.empty()) { @@ -354,10 +355,8 @@ void Program::query_uniform_blocks(const vector &uniforms_by_inde indices2.clear(); for(vector::iterator j=indices.begin(); j!=indices.end(); ++j) { - GLenum t = uniforms_by_index[*j]->type; - if(t==GL_FLOAT_MAT4 || t==GL_FLOAT_MAT3 || t==GL_FLOAT_MAT2 || - t==GL_FLOAT_MAT2x3 || t==GL_FLOAT_MAT2x4 || t==GL_FLOAT_MAT3x2 || - t==GL_FLOAT_MAT3x4 || t==GL_FLOAT_MAT4x2 || t==GL_FLOAT_MAT4x3) + DataType t = uniforms_by_index[*j]->type; + if(is_matrix(t)) indices2.push_back(*j); } if(!indices2.empty()) @@ -396,8 +395,8 @@ void Program::query_attributes() AttributeInfo &info = attributes[name]; info.name = name; info.location = glGetAttribLocation(id, name); - info.size = size; - info.type = type; + info.array_size = size; + info.type = from_gl_type(type); } } } @@ -406,7 +405,7 @@ Program::LayoutHash Program::compute_layout_hash(const vector::const_iterator i = uniforms.begin(); i!=uniforms.end(); ++i) - layout_descriptor += format("%d:%s:%x:%d\n", (*i)->location, (*i)->name, (*i)->type, (*i)->size); + layout_descriptor += format("%d:%s:%x:%d\n", (*i)->location, (*i)->name, (*i)->type, (*i)->array_size); return hash32(layout_descriptor); }