1 #include <mbgl/gl/attribute.hpp>
2 #include <mbgl/gl/context.hpp>
3 #include <mbgl/gl/gl.hpp>
4 
5 namespace mbgl {
6 namespace gl {
7 
bindAttributeLocation(Context & context,ProgramID id,AttributeLocation location,const char * name)8 void bindAttributeLocation(Context& context, ProgramID id, AttributeLocation location, const char* name) {
9     // We're using sequentially numberered attribute locations starting with 0. Therefore we can use
10     // the location as a proxy for the number of attributes.
11     if (location >= context.maximumVertexBindingCount) {
12         // Don't bind the location on this hardware since it exceeds the limit (otherwise we'd get
13         // an OpenGL error). This means we'll see rendering errors, and possibly slow rendering due
14         // to unbound attributes.
15     } else {
16         MBGL_CHECK_ERROR(glBindAttribLocation(id, location, name));
17     }
18 }
19 
getActiveAttributes(ProgramID id)20 std::set<std::string> getActiveAttributes(ProgramID id) {
21     std::set<std::string> activeAttributes;
22 
23     GLint attributeCount;
24     MBGL_CHECK_ERROR(glGetProgramiv(id, GL_ACTIVE_ATTRIBUTES, &attributeCount));
25 
26     GLint maxAttributeLength;
27     MBGL_CHECK_ERROR(glGetProgramiv(id, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &maxAttributeLength));
28 
29     std::string attributeName;
30     attributeName.resize(maxAttributeLength);
31 
32     GLsizei actualLength;
33     GLint size;
34     GLenum type;
35 
36     for (int32_t i = 0; i < attributeCount; i++) {
37         MBGL_CHECK_ERROR(glGetActiveAttrib(id, i, maxAttributeLength, &actualLength, &size, &type, &attributeName[0]));
38         activeAttributes.emplace(std::string(attributeName, 0, actualLength));
39     }
40 
41     return activeAttributes;
42 }
43 
44 } // namespace gl
45 } // namespace mbgl
46