]> git.tdb.fi Git - libs/gl.git/commitdiff
Store information about attributes in Program
authorMikko Rasa <tdb@tdb.fi>
Thu, 20 Jun 2019 21:50:41 +0000 (00:50 +0300)
committerMikko Rasa <tdb@tdb.fi>
Fri, 21 Jun 2019 11:53:12 +0000 (14:53 +0300)
source/program.cpp
source/program.h

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)
index 826a49637bf9535caf0e30af2c3cdb7ca5ed222b..d2032a5cd46843e36def08c91f8a95d699025bd1 100644 (file)
@@ -59,9 +59,18 @@ public:
                LayoutHash layout_hash;
        };
 
+       struct AttributeInfo
+       {
+               std::string name;
+               unsigned location;
+               unsigned size;
+               GLenum type;
+       };
+
        typedef std::vector<Shader *> ShaderList;
        typedef std::map<std::string, UniformInfo> UniformMap;
        typedef std::map<std::string, UniformBlockInfo> UniformBlockMap;
+       typedef std::map<std::string, AttributeInfo> AttributeMap;
 
 private:
        unsigned id;
@@ -71,6 +80,7 @@ private:
        UniformBlockMap uniform_blocks;
        UniformMap uniforms;
        LayoutHash uniform_layout_hash;
+       AttributeMap attributes;
        bool legacy_vars;
 
 public:
@@ -117,6 +127,9 @@ public:
        const UniformMap &get_uniforms() const { return uniforms; }
        const UniformInfo &get_uniform_info(const std::string &) const;
        int get_uniform_location(const std::string &) const;
+       const AttributeMap &get_attributes() const { return attributes; }
+       const AttributeInfo &get_attribute_info(const std::string &) const;
+       int get_attribute_location(const std::string &) const;
 
        bool uses_legacy_variables() const { return legacy_vars; }