summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2017-07-19 10:03:59 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2017-07-19 10:44:00 -0700
commit441644166310314b5e8016405691110e69a0a3cd (patch)
tree4c284c2972b3998f8525c94790d8eed0d7360fa6
parente7f45e0b19eaa86b587e5269f85ecd0eb8a55de7 (diff)
downloadqtlocation-mapboxgl-441644166310314b5e8016405691110e69a0a3cd.tar.gz
[core] Revert conditional attribute binding
Reverts eed89fcf9d099266aa793375ad63493e880f8a80, which causes issues on certain Android devices. We don't actually need this change on this branch, I brought it over only to make the subsequent commits cleanly cherry-pickable.
-rw-r--r--src/mbgl/gl/attribute.cpp30
-rw-r--r--src/mbgl/gl/attribute.hpp18
-rw-r--r--src/mbgl/gl/program.hpp12
3 files changed, 9 insertions, 51 deletions
diff --git a/src/mbgl/gl/attribute.cpp b/src/mbgl/gl/attribute.cpp
index bb5b2ddc34..4dd102400d 100644
--- a/src/mbgl/gl/attribute.cpp
+++ b/src/mbgl/gl/attribute.cpp
@@ -4,35 +4,9 @@
namespace mbgl {
namespace gl {
-void bindAttributeLocation(ProgramID id, AttributeLocation location, const char* name) {
- if (location >= MAX_ATTRIBUTES) {
- throw gl::Error("too many vertex attributes");
- }
+AttributeLocation bindAttributeLocation(ProgramID id, AttributeLocation location, const char* name) {
MBGL_CHECK_ERROR(glBindAttribLocation(id, location, name));
-}
-
-std::set<std::string> getActiveAttributes(ProgramID id) {
- std::set<std::string> activeAttributes;
-
- GLint attributeCount;
- MBGL_CHECK_ERROR(glGetProgramiv(id, GL_ACTIVE_ATTRIBUTES, &attributeCount));
-
- GLint maxAttributeLength;
- MBGL_CHECK_ERROR(glGetProgramiv(id, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &maxAttributeLength));
-
- std::string attributeName;
- attributeName.resize(maxAttributeLength);
-
- GLsizei actualLength;
- GLint size;
- GLenum type;
-
- for (int32_t i = 0; i < attributeCount; i++) {
- MBGL_CHECK_ERROR(glGetActiveAttrib(id, i, maxAttributeLength, &actualLength, &size, &type, &attributeName[0]));
- activeAttributes.emplace(std::string(attributeName, 0, actualLength));
- }
-
- return activeAttributes;
+ return location;
}
} // namespace gl
diff --git a/src/mbgl/gl/attribute.hpp b/src/mbgl/gl/attribute.hpp
index a85b49c6a5..2d1d2386eb 100644
--- a/src/mbgl/gl/attribute.hpp
+++ b/src/mbgl/gl/attribute.hpp
@@ -8,7 +8,6 @@
#include <cstddef>
#include <vector>
-#include <set>
#include <functional>
#include <string>
#include <array>
@@ -214,8 +213,7 @@ const std::size_t Vertex<A1, A2, A3, A4, A5>::attributeOffsets[5] = {
} // namespace detail
-void bindAttributeLocation(ProgramID, AttributeLocation, const char * name);
-std::set<std::string> getActiveAttributes(ProgramID);
+AttributeLocation bindAttributeLocation(ProgramID, AttributeLocation, const char * name);
template <class... As>
class Attributes {
@@ -235,19 +233,7 @@ public:
static constexpr std::size_t Index = TypeIndex<A, As...>::value;
static Locations bindLocations(const ProgramID& id) {
- std::set<std::string> activeAttributes = getActiveAttributes(id);
-
- AttributeLocation location = 0;
- auto maybeBindLocation = [&](const char* name) -> optional<AttributeLocation> {
- if (activeAttributes.count(name)) {
- bindAttributeLocation(id, location, name);
- return location++;
- } else {
- return {};
- }
- };
-
- return Locations { maybeBindLocation(As::name())... };
+ return Locations { bindAttributeLocation(id, Index<As>, As::name())... };
}
template <class Program>
diff --git a/src/mbgl/gl/program.hpp b/src/mbgl/gl/program.hpp
index 3b54ec194a..1a429c6630 100644
--- a/src/mbgl/gl/program.hpp
+++ b/src/mbgl/gl/program.hpp
@@ -34,17 +34,15 @@ public:
: program(
context.createProgram(context.createShader(ShaderType::Vertex, vertexSource),
context.createShader(ShaderType::Fragment, fragmentSource))),
- uniformsState((context.linkProgram(program), Uniforms::bindLocations(program))),
- attributeLocations(Attributes::bindLocations(program)) {
- // Re-link program after manually binding only active attributes in Attributes::bindLocations
- context.linkProgram(program);
+ attributeLocations(Attributes::bindLocations(program)),
+ uniformsState((context.linkProgram(program), Uniforms::bindLocations(program))) {
}
template <class BinaryProgram>
Program(Context& context, const BinaryProgram& binaryProgram)
: program(context.createProgram(binaryProgram.format(), binaryProgram.code())),
- uniformsState(Uniforms::loadNamedLocations(binaryProgram)),
- attributeLocations(Attributes::loadNamedLocations(binaryProgram)) {
+ attributeLocations(Attributes::loadNamedLocations(binaryProgram)),
+ uniformsState(Uniforms::loadNamedLocations(binaryProgram)) {
}
static Program createProgram(gl::Context& context,
@@ -142,8 +140,8 @@ public:
private:
UniqueProgram program;
- typename Uniforms::State uniformsState;
typename Attributes::Locations attributeLocations;
+ typename Uniforms::State uniformsState;
};
} // namespace gl