summaryrefslogtreecommitdiff
path: root/src/mbgl/gl/attribute.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mbgl/gl/attribute.hpp')
-rw-r--r--src/mbgl/gl/attribute.hpp114
1 files changed, 33 insertions, 81 deletions
diff --git a/src/mbgl/gl/attribute.hpp b/src/mbgl/gl/attribute.hpp
index dc112c1ad8..c4fe8b993f 100644
--- a/src/mbgl/gl/attribute.hpp
+++ b/src/mbgl/gl/attribute.hpp
@@ -2,7 +2,6 @@
#include <mbgl/gfx/attribute.hpp>
#include <mbgl/gl/types.hpp>
-#include <mbgl/gfx/vertex_buffer.hpp>
#include <mbgl/util/ignore.hpp>
#include <mbgl/util/indexed_tuple.hpp>
#include <mbgl/util/optional.hpp>
@@ -18,83 +17,50 @@
namespace mbgl {
namespace gl {
-class AttributeBinding {
-public:
- gfx::AttributeDescriptor attribute;
- uint8_t vertexStride;
- const gfx::VertexBufferResource* vertexBufferResource;
- uint32_t vertexOffset;
-
- friend bool operator==(const AttributeBinding& lhs, const AttributeBinding& rhs) {
- return lhs.attribute == rhs.attribute &&
- lhs.vertexStride == rhs.vertexStride &&
- lhs.vertexBufferResource == rhs.vertexBufferResource &&
- lhs.vertexOffset == rhs.vertexOffset;
- }
-};
-
-using AttributeBindingArray = std::vector<optional<AttributeBinding>>;
-
- /*
- Create a binding for this attribute. The `attributeSize` parameter may be used to
- override the number of components available in the buffer for each vertex. Thus,
- a buffer with only one float for each vertex can be bound to a `vec2` attribute
- */
-template <std::size_t I, typename Vertex>
-AttributeBinding attributeBinding(const gfx::VertexBuffer<Vertex>& buffer) {
- static_assert(I < gfx::VertexDescriptorOf<Vertex>::data.count, "vertex attribute index out of range");
- return {
- gfx::VertexDescriptorOf<Vertex>::data.attributes[I],
- gfx::VertexDescriptorOf<Vertex>::data.stride,
- buffer.resource.get(),
- 0,
- };
-}
-
-optional<AttributeBinding> offsetAttributeBinding(const optional<AttributeBinding>& binding, std::size_t vertexOffset);
+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 Types = TypeList<As...>;
- using Locations = IndexedTuple<
- TypeList<As...>,
- TypeList<ExpandToType<As, optional<AttributeLocation>>...>>;
- using Bindings = IndexedTuple<
- TypeList<As...>,
- TypeList<ExpandToType<As, optional<AttributeBinding>>...>>;
- 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>>...>>;
+
+ Locations locations;
- return Locations { maybeBindLocation(As::name())... };
+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) {
@@ -107,20 +73,12 @@ public:
return result;
}
- static Bindings bindings(const gfx::VertexBuffer<gfx::Vertex<Types>>& buffer) {
- return Bindings { attributeBinding<TypeIndex<As, As...>::value>(buffer)... };
- }
-
- static Bindings offsetBindings(const Bindings& bindings, std::size_t vertexOffset) {
- return Bindings { offsetAttributeBinding(bindings.template get<As>(), vertexOffset)... };
- }
-
- static AttributeBindingArray toBindingArray(const Locations& locations, const Bindings& bindings) {
+ AttributeBindingArray toBindingArray(const gfx::AttributeBindings<TypeList<As...>>& bindings) const {
AttributeBindingArray result;
result.resize(sizeof...(As));
auto maybeAddBinding = [&] (const optional<AttributeLocation>& location,
- const optional<AttributeBinding>& binding) {
+ const optional<gfx::AttributeBinding>& binding) {
if (location) {
result.at(*location) = binding;
}
@@ -130,12 +88,6 @@ public:
return result;
}
-
- static uint32_t activeBindingCount(const Bindings& bindings) {
- uint32_t result = 0;
- util::ignore({ ((result += bool(bindings.template get<As>())), 0)... });
- return result;
- }
};
} // namespace gl