diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2019-03-13 11:45:54 +0100 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2019-03-21 13:48:14 +0100 |
commit | 6758ae1c6228e691edb65c3d754e2b44fed1cdc7 (patch) | |
tree | 7d1fa7295a46f1eb4063f1fa217a421031f12f5e | |
parent | 40b5e45682729d9c5ce23d4041bcd3e9c23614ba (diff) | |
download | qtlocation-mapboxgl-6758ae1c6228e691edb65c3d754e2b44fed1cdc7.tar.gz |
[core] gl::Attributes -> gl::AttributeLocations
-rw-r--r-- | src/mbgl/gl/attribute.hpp | 60 | ||||
-rw-r--r-- | src/mbgl/gl/program.hpp | 11 |
2 files changed, 36 insertions, 35 deletions
diff --git a/src/mbgl/gl/attribute.hpp b/src/mbgl/gl/attribute.hpp index 9115bf5e43..c4fe8b993f 100644 --- a/src/mbgl/gl/attribute.hpp +++ b/src/mbgl/gl/attribute.hpp @@ -18,45 +18,49 @@ namespace mbgl { namespace gl { using AttributeBindingArray = std::vector<optional<gfx::AttributeBinding>>; +using NamedAttributeLocations = std::vector<std::pair<const std::string, AttributeLocation>>; class Context; void bindAttributeLocation(Context&, ProgramID, AttributeLocation, const char * name); std::set<std::string> getActiveAttributes(ProgramID); template <class> -class Attributes; +class AttributeLocations; template <class... As> -class Attributes<TypeList<As...>> final { -public: - using Locations = IndexedTuple< - TypeList<As...>, - TypeList<ExpandToType<As, optional<AttributeLocation>>...>>; - using NamedLocations = std::vector<std::pair<const std::string, AttributeLocation>>; - - static Locations bindLocations(Context& context, 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(context, id, location, name); - return location++; - } else { - return {}; - } - }; +class AttributeLocations<TypeList<As...>> final { +private: + using Locations = + IndexedTuple<TypeList<As...>, TypeList<ExpandToType<As, optional<AttributeLocation>>...>>; - return Locations { maybeBindLocation(As::name())... }; + Locations locations; + +public: + AttributeLocations(Context& context, const ProgramID& id) + : locations([&] { + std::set<std::string> activeAttributes = getActiveAttributes(id); + + AttributeLocation location = 0; + auto maybeBindLocation = [&](const char* name) -> optional<AttributeLocation> { + if (activeAttributes.count(name)) { + bindAttributeLocation(context, id, location, name); + return location++; + } else { + return {}; + } + }; + + return Locations{ maybeBindLocation(As::name())... }; + }()) { } - template <class Program> - static Locations loadNamedLocations(const Program& program) { - return Locations{ program.attributeLocation(As::name())... }; + template <class BinaryProgram> + AttributeLocations(const BinaryProgram& program) + : locations{ program.attributeLocation(As::name())... } { } - static NamedLocations getNamedLocations(const Locations& locations) { - NamedLocations result; + NamedAttributeLocations getNamedLocations() const { + NamedAttributeLocations result; auto maybeAddLocation = [&] (const std::string& name, const optional<AttributeLocation>& location) { if (location) { @@ -69,9 +73,7 @@ public: return result; } - static AttributeBindingArray - toBindingArray(const Locations& locations, - const typename gfx::AttributeBindings<TypeList<As...>>& bindings) { + AttributeBindingArray toBindingArray(const gfx::AttributeBindings<TypeList<As...>>& bindings) const { AttributeBindingArray result; result.resize(sizeof...(As)); diff --git a/src/mbgl/gl/program.hpp b/src/mbgl/gl/program.hpp index b96dd5d9b0..815be75736 100644 --- a/src/mbgl/gl/program.hpp +++ b/src/mbgl/gl/program.hpp @@ -33,7 +33,6 @@ public: using UniformValues = gfx::UniformValues<UniformList>; using TextureBindings = gfx::TextureBindings<TextureList>; - using Attributes = gl::Attributes<AttributeList>; using Uniforms = gl::Uniforms<UniformList>; Program(Context& context, const std::string& vertexSource, const std::string& fragmentSource) @@ -41,7 +40,7 @@ public: context.createProgram(context.createShader(ShaderType::Vertex, vertexSource), context.createShader(ShaderType::Fragment, fragmentSource))), uniformsState((context.linkProgram(program), Uniforms::bindLocations(program))), - attributeLocations(gl::Attributes<AttributeList>::bindLocations(context, program)) { + attributeLocations(context, program) { // Re-link program after manually binding only active attributes in Attributes::bindLocations context.linkProgram(program); @@ -57,7 +56,7 @@ public: Program(Context& context, const BinaryProgram& binaryProgram) : program(context.createProgram(binaryProgram.format(), binaryProgram.code())), uniformsState(Uniforms::loadNamedLocations(binaryProgram)), - attributeLocations(Attributes::loadNamedLocations(binaryProgram)) { + attributeLocations(binaryProgram) { textures.loadNamedLocations(binaryProgram); } @@ -115,7 +114,7 @@ public: optional<BinaryProgram> get(Context& context, const std::string& identifier) const { if (auto binaryProgram = context.getBinaryProgram(program)) { return BinaryProgram{ binaryProgram->first, std::move(binaryProgram->second), - identifier, Attributes::getNamedLocations(attributeLocations), + identifier, attributeLocations.getNamedLocations(), Uniforms::getNamedLocations(uniformsState), textures.getNamedLocations() }; } @@ -154,7 +153,7 @@ public: auto& vertexArray = reinterpret_cast<gl::DrawScopeResource&>(*drawScope.resource).vertexArray; vertexArray.bind(context, indexBuffer, - Attributes::toBindingArray(attributeLocations, attributeBindings)); + attributeLocations.toBindingArray(attributeBindings)); context.draw(drawMode.primitiveType, indexOffset, @@ -165,7 +164,7 @@ private: UniqueProgram program; typename Uniforms::State uniformsState; - typename Attributes::Locations attributeLocations; + gl::AttributeLocations<AttributeList> attributeLocations; gl::Textures<TextureList> textures; }; |