]> git.tdb.fi Git - libs/gl.git/blobdiff - source/program.cpp
Store information about attributes in Program
[libs/gl.git] / source / program.cpp
index c3625f4159589916f0e83e7c9f88135266e91b49..d8827ab5d0f5f095fed0d53424571aff7147f472 100644 (file)
@@ -283,7 +283,18 @@ void Program::query_attributes()
                int size;
                GLenum type;
                glGetActiveAttrib(id, i, sizeof(name), &len, &size, &type, name);
-               if(len && !strncmp(name, "gl_", 3))
+               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;
+               }
+               else
                        legacy_vars = true;
        }
 }
@@ -333,6 +344,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)