From b18bb32e378ea8429b1ee7c83c209d75c82f1e4e Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Wed, 19 Jul 2017 10:03:59 -0700 Subject: [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. --- src/mbgl/gl/attribute.cpp | 30 ++---------------------------- src/mbgl/gl/attribute.hpp | 18 ++---------------- src/mbgl/gl/program.hpp | 12 +++++------- 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 getActiveAttributes(ProgramID id) { - std::set 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 #include -#include #include #include #include @@ -214,8 +213,7 @@ const std::size_t Vertex::attributeOffsets[5] = { } // namespace detail -void bindAttributeLocation(ProgramID, AttributeLocation, const char * name); -std::set getActiveAttributes(ProgramID); +AttributeLocation bindAttributeLocation(ProgramID, AttributeLocation, const char * name); template class Attributes { @@ -235,19 +233,7 @@ public: static constexpr std::size_t Index = TypeIndex::value; static Locations bindLocations(const ProgramID& id) { - std::set activeAttributes = getActiveAttributes(id); - - AttributeLocation location = 0; - auto maybeBindLocation = [&](const char* name) -> optional { - if (activeAttributes.count(name)) { - bindAttributeLocation(id, location, name); - return location++; - } else { - return {}; - } - }; - - return Locations { maybeBindLocation(As::name())... }; + return Locations { bindAttributeLocation(id, Index, As::name())... }; } template 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 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 -- cgit v1.2.1