From: Mikko Rasa Date: Thu, 20 Jun 2019 21:50:41 +0000 (+0300) Subject: Store information about attributes in Program X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=a170be7d2b295c4a3bbcea6585634bece3e1638b;p=libs%2Fgl.git Store information about attributes in Program --- diff --git a/source/program.cpp b/source/program.cpp index c3625f41..d8827ab5 100644 --- a/source/program.cpp +++ b/source/program.cpp @@ -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) diff --git a/source/program.h b/source/program.h index 826a4963..d2032a5c 100644 --- a/source/program.h +++ b/source/program.h @@ -59,9 +59,18 @@ public: LayoutHash layout_hash; }; + struct AttributeInfo + { + std::string name; + unsigned location; + unsigned size; + GLenum type; + }; + typedef std::vector ShaderList; typedef std::map UniformMap; typedef std::map UniformBlockMap; + typedef std::map 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; }