summaryrefslogtreecommitdiff
path: root/src/mbgl/gl/attribute.cpp
diff options
context:
space:
mode:
authorLauren Budorick <lauren@mapbox.com>2017-06-29 11:29:48 -0700
committerGitHub <noreply@github.com>2017-06-29 11:29:48 -0700
commitb5fed1172d77bac0ba122c73a9d30739a51e5028 (patch)
tree525af4167d907342f3c1ff00d9cf5ef7bbc6f385 /src/mbgl/gl/attribute.cpp
parentf836425be467ac9830d8f6b4caa98700ce87c19b (diff)
downloadqtlocation-mapboxgl-b5fed1172d77bac0ba122c73a9d30739a51e5028.tar.gz
[core] Bind only active attributes in order to avoid exceeding attribute limits (#9373)
Introducing two new attributes to enable property functions for line-width (#9250) pushed the attribute count over GL_MAX_VERTEX_ATTRIBS on some devices. Now we selectively bind only attributes that are used, making it unlikely to surpass GL_MAX_VERTEX_ATTRIBS.
Diffstat (limited to 'src/mbgl/gl/attribute.cpp')
-rw-r--r--src/mbgl/gl/attribute.cpp46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/mbgl/gl/attribute.cpp b/src/mbgl/gl/attribute.cpp
index e05ca75866..4e6f78e689 100644
--- a/src/mbgl/gl/attribute.cpp
+++ b/src/mbgl/gl/attribute.cpp
@@ -2,14 +2,55 @@
#include <mbgl/gl/context.hpp>
#include <mbgl/gl/gl.hpp>
+#include <cstring>
+
namespace mbgl {
namespace gl {
AttributeLocation bindAttributeLocation(ProgramID id, AttributeLocation location, const char* name) {
+ assert(location < 8);
MBGL_CHECK_ERROR(glBindAttribLocation(id, location, name));
return location;
}
+int32_t getActiveAttributeCount(ProgramID id) {
+ GLint numAttributes;
+ MBGL_CHECK_ERROR(glGetProgramiv(id, GL_ACTIVE_ATTRIBUTES, &numAttributes));
+ return numAttributes;
+}
+
+int32_t getMaxAttributeNameLength(ProgramID id) {
+ GLint nameLength;
+ MBGL_CHECK_ERROR(glGetProgramiv(id, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &nameLength));
+ return nameLength;
+}
+
+std::string getAttributeName(ProgramID id, int32_t maxLength, AttributeLocation location) {
+ std::string attributeName;
+ attributeName.resize(maxLength);
+ GLsizei actualLength;
+ GLint size;
+ GLenum type;
+ MBGL_CHECK_ERROR(glGetActiveAttrib(id, static_cast<GLuint>(location),
+ static_cast<GLsizei>(maxLength), &actualLength, &size, &type,
+ const_cast<char*>(attributeName.data())));
+ attributeName.resize(actualLength);
+ return attributeName;
+}
+
+std::set<std::string> getActiveAttributes(ProgramID id) {
+ std::set<std::string> activeAttributes;
+
+ GLint attributeCount = getActiveAttributeCount(id);
+ GLint maxAttributeLength = getMaxAttributeNameLength(id);
+
+ for (int32_t i = 0; i < attributeCount; i++) {
+ activeAttributes.emplace(getAttributeName(id, maxAttributeLength, i));
+ }
+
+ return activeAttributes;
+}
+
void DisabledAttribute::bind(Context&, AttributeLocation location, std::size_t) const {
MBGL_CHECK_ERROR(glDisableVertexAttribArray(location));
}
@@ -25,6 +66,11 @@ template <> DataType DataTypeOf<float> = DataType::Float;
template <class T, std::size_t N>
void AttributeBinding<T, N>::bind(Context& context, AttributeLocation location, std::size_t vertexOffset) const {
+ // FillProgram will attempt to bind at location -1 because it includes
+ // a fill-outline-color paint property but does not use it or have an
+ // a_outline_color shader attribute - in this case, we have nothing to bind.
+ if (location == -1) return;
+
context.vertexBuffer = vertexBuffer;
MBGL_CHECK_ERROR(glEnableVertexAttribArray(location));
MBGL_CHECK_ERROR(glVertexAttribPointer(