X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fprogram.cpp;h=6313043ea84361c3f7fbc543324c997eb56d5fc6;hb=47bfbdc8cf844aa079995fca34a3b906b49a4f66;hp=c3625f4159589916f0e83e7c9f88135266e91b49;hpb=edc2ea855300df08d9f68f2e67316385b003dba6;p=libs%2Fgl.git diff --git a/source/program.cpp b/source/program.cpp index c3625f41..6313043e 100644 --- a/source/program.cpp +++ b/source/program.cpp @@ -28,6 +28,8 @@ Program::Program() init(); } +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" Program::Program(const ProgramBuilder::StandardFeatures &features) { init(); @@ -36,6 +38,7 @@ Program::Program(const ProgramBuilder::StandardFeatures &features) builder.add_shaders(*this); link(); } +#pragma GCC diagnostic pop Program::Program(const std::string &source) { @@ -129,7 +132,6 @@ void Program::link() (*i)->compile(); uniforms.clear(); - legacy_vars = false; glLinkProgram(id); linked = get_program_i(id, GL_LINK_STATUS); @@ -144,6 +146,26 @@ void Program::link() query_uniforms(); query_attributes(); + + for(UniformMap::const_iterator i=uniforms.begin(); i!=uniforms.end(); ++i) + require_type(i->second.type); + for(AttributeMap::const_iterator i=attributes.begin(); i!=attributes.end(); ++i) + 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() @@ -173,8 +195,6 @@ void Program::query_uniforms() info.type = type; uniforms_by_index[i] = &info; } - else - legacy_vars = true; } if(ARB_uniform_buffer_object) @@ -283,8 +303,17 @@ void Program::query_attributes() int size; GLenum type; glGetActiveAttrib(id, i, sizeof(name), &len, &size, &type, name); - if(len && !strncmp(name, "gl_", 3)) - legacy_vars = true; + if(len && strncmp(name, "gl_", 3)) + { + if(len>3 && !strcmp(name+len-3, "[0]")) + name[len-3] = 0; + + AttributeInfo &info = attributes[name]; + info.name = name; + info.location = glGetAttribLocation(id, name); + info.size = size; + info.type = type; + } } } @@ -304,10 +333,9 @@ bool Program::uniform_location_compare(const UniformInfo *uni1, const UniformInf string Program::get_info_log() const { GLsizei len = get_program_i(id, GL_INFO_LOG_LENGTH); - char *buf = new char[len+1]; - glGetProgramInfoLog(id, len+1, &len, buf); - string log(buf, len); - delete[] buf; + string log(len+1, 0); + glGetProgramInfoLog(id, len+1, &len, &log[0]); + log.erase(len); return log; } @@ -333,6 +361,20 @@ int Program::get_uniform_location(const string &n) const return i->second.block->bind_point<0 ? i->second.location : -1; } +const Program::AttributeInfo &Program::get_attribute_info(const string &name) const +{ + return get_item(attributes, name); +} + +int Program::get_attribute_location(const string &n) const +{ + if(n[n.size()-1]==']') + throw invalid_argument("Program::get_attribute_location"); + + AttributeMap::const_iterator i = attributes.find(n); + return i!=attributes.end() ? i->second.location : -1; +} + void Program::bind() const { if(!linked) @@ -385,10 +427,13 @@ void Program::Loader::geometry_shader(const string &src) void Program::Loader::standard() { +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" ProgramBuilder::StandardFeatures feat; load_sub(feat); ProgramBuilder builder(feat); builder.add_shaders(obj); +#pragma GCC diagnostic pop } void Program::Loader::vertex_shader(const string &src)