summaryrefslogtreecommitdiff
path: root/src/mbgl/renderer
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2017-07-03 14:05:12 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2017-07-12 14:48:22 -0700
commitc61041b44cd9181641db2351f4657cc356300226 (patch)
tree6a5d115c1796a52d4270ca48fbb1a0e1ce3a2ad4 /src/mbgl/renderer
parentfedfaa2f6e582e87b190f5d423302f9f95d147d9 (diff)
downloadqtlocation-mapboxgl-c61041b44cd9181641db2351f4657cc356300226.tar.gz
[core] Rework attribute binding (again)
These changes are necessary for programs whose set of active attributes is not fixed at compile time by a template parameter pack, but rather varies based on the generated shader text at runtime. In such cases, the attribute location of a given named attribute may vary between instances of the same Program. Previously, attribute bindings were implicitly associated with a location based on template parameter order, and -1 was used to indicate an inactive attribute. This left us unable to disable the appropriate attribute when it went from active to inactive. Now, the state tracker for bindings explicitly associates locations and state, and an empty optional is used to indicate an inactive attribute. In addition, a gl::VertexArray class is now exposed, allowing more flexibility in the relationship between Programs, Segments, and attribute bindings. In this commit, that relationship does not change, but the subsequent commit adjusts it to match gl-js, reduce rebinds, and work around buggy VAO implementations. VertexArray uses a pimpl idiom in order to support implementations that lack the VAO extension. In that case, all VertexArrays share global binding state, reflecting the platform reality in the absence of VAOs, while still providing a uniform API.
Diffstat (limited to 'src/mbgl/renderer')
-rw-r--r--src/mbgl/renderer/buckets/circle_bucket.hpp4
-rw-r--r--src/mbgl/renderer/buckets/debug_bucket.hpp2
-rw-r--r--src/mbgl/renderer/buckets/fill_bucket.hpp6
-rw-r--r--src/mbgl/renderer/buckets/fill_extrusion_bucket.hpp4
-rw-r--r--src/mbgl/renderer/buckets/line_bucket.hpp4
-rw-r--r--src/mbgl/renderer/buckets/raster_bucket.hpp2
-rw-r--r--src/mbgl/renderer/buckets/symbol_bucket.hpp8
-rw-r--r--src/mbgl/renderer/layers/render_custom_layer.cpp2
-rw-r--r--src/mbgl/renderer/paint_property_binder.hpp15
-rw-r--r--src/mbgl/renderer/painter.cpp2
-rw-r--r--src/mbgl/renderer/painter.hpp8
11 files changed, 29 insertions, 28 deletions
diff --git a/src/mbgl/renderer/buckets/circle_bucket.hpp b/src/mbgl/renderer/buckets/circle_bucket.hpp
index b048fd7675..0f27e2a7e3 100644
--- a/src/mbgl/renderer/buckets/circle_bucket.hpp
+++ b/src/mbgl/renderer/buckets/circle_bucket.hpp
@@ -5,7 +5,7 @@
#include <mbgl/tile/geometry_tile_data.hpp>
#include <mbgl/gl/vertex_buffer.hpp>
#include <mbgl/gl/index_buffer.hpp>
-#include <mbgl/gl/segment.hpp>
+#include <mbgl/programs/segment.hpp>
#include <mbgl/programs/circle_program.hpp>
#include <mbgl/style/layers/circle_layer_properties.hpp>
@@ -29,7 +29,7 @@ public:
gl::VertexVector<CircleLayoutVertex> vertices;
gl::IndexVector<gl::Triangles> triangles;
- gl::SegmentVector<CircleAttributes> segments;
+ SegmentVector<CircleAttributes> segments;
optional<gl::VertexBuffer<CircleLayoutVertex>> vertexBuffer;
optional<gl::IndexBuffer<gl::Triangles>> indexBuffer;
diff --git a/src/mbgl/renderer/buckets/debug_bucket.hpp b/src/mbgl/renderer/buckets/debug_bucket.hpp
index 756e58a6de..fc3128e944 100644
--- a/src/mbgl/renderer/buckets/debug_bucket.hpp
+++ b/src/mbgl/renderer/buckets/debug_bucket.hpp
@@ -33,7 +33,7 @@ public:
const optional<Timestamp> expires;
const MapDebugOptions debugMode;
- gl::SegmentVector<DebugAttributes> segments;
+ SegmentVector<DebugAttributes> segments;
optional<gl::VertexBuffer<DebugLayoutVertex>> vertexBuffer;
optional<gl::IndexBuffer<gl::Lines>> indexBuffer;
};
diff --git a/src/mbgl/renderer/buckets/fill_bucket.hpp b/src/mbgl/renderer/buckets/fill_bucket.hpp
index 421d8b332b..d3cd92d451 100644
--- a/src/mbgl/renderer/buckets/fill_bucket.hpp
+++ b/src/mbgl/renderer/buckets/fill_bucket.hpp
@@ -4,7 +4,7 @@
#include <mbgl/tile/geometry_tile_data.hpp>
#include <mbgl/gl/vertex_buffer.hpp>
#include <mbgl/gl/index_buffer.hpp>
-#include <mbgl/gl/segment.hpp>
+#include <mbgl/programs/segment.hpp>
#include <mbgl/programs/fill_program.hpp>
#include <mbgl/style/layers/fill_layer_properties.hpp>
@@ -30,8 +30,8 @@ public:
gl::VertexVector<FillLayoutVertex> vertices;
gl::IndexVector<gl::Lines> lines;
gl::IndexVector<gl::Triangles> triangles;
- gl::SegmentVector<FillAttributes> lineSegments;
- gl::SegmentVector<FillAttributes> triangleSegments;
+ SegmentVector<FillAttributes> lineSegments;
+ SegmentVector<FillAttributes> triangleSegments;
optional<gl::VertexBuffer<FillLayoutVertex>> vertexBuffer;
optional<gl::IndexBuffer<gl::Lines>> lineIndexBuffer;
diff --git a/src/mbgl/renderer/buckets/fill_extrusion_bucket.hpp b/src/mbgl/renderer/buckets/fill_extrusion_bucket.hpp
index c54805d743..d1e695c5a3 100644
--- a/src/mbgl/renderer/buckets/fill_extrusion_bucket.hpp
+++ b/src/mbgl/renderer/buckets/fill_extrusion_bucket.hpp
@@ -4,7 +4,7 @@
#include <mbgl/tile/geometry_tile_data.hpp>
#include <mbgl/gl/vertex_buffer.hpp>
#include <mbgl/gl/index_buffer.hpp>
-#include <mbgl/gl/segment.hpp>
+#include <mbgl/programs/segment.hpp>
#include <mbgl/programs/fill_extrusion_program.hpp>
#include <mbgl/style/layers/fill_extrusion_layer_properties.hpp>
@@ -27,7 +27,7 @@ public:
gl::VertexVector<FillExtrusionLayoutVertex> vertices;
gl::IndexVector<gl::Triangles> triangles;
- gl::SegmentVector<FillExtrusionAttributes> triangleSegments;
+ SegmentVector<FillExtrusionAttributes> triangleSegments;
optional<gl::VertexBuffer<FillExtrusionLayoutVertex>> vertexBuffer;
optional<gl::IndexBuffer<gl::Triangles>> indexBuffer;
diff --git a/src/mbgl/renderer/buckets/line_bucket.hpp b/src/mbgl/renderer/buckets/line_bucket.hpp
index 34d8935953..c0a0614d33 100644
--- a/src/mbgl/renderer/buckets/line_bucket.hpp
+++ b/src/mbgl/renderer/buckets/line_bucket.hpp
@@ -4,7 +4,7 @@
#include <mbgl/tile/geometry_tile_data.hpp>
#include <mbgl/gl/vertex_buffer.hpp>
#include <mbgl/gl/index_buffer.hpp>
-#include <mbgl/gl/segment.hpp>
+#include <mbgl/programs/segment.hpp>
#include <mbgl/programs/line_program.hpp>
#include <mbgl/style/layers/line_layer_properties.hpp>
@@ -34,7 +34,7 @@ public:
gl::VertexVector<LineLayoutVertex> vertices;
gl::IndexVector<gl::Triangles> triangles;
- gl::SegmentVector<LineAttributes> segments;
+ SegmentVector<LineAttributes> segments;
optional<gl::VertexBuffer<LineLayoutVertex>> vertexBuffer;
optional<gl::IndexBuffer<gl::Triangles>> indexBuffer;
diff --git a/src/mbgl/renderer/buckets/raster_bucket.hpp b/src/mbgl/renderer/buckets/raster_bucket.hpp
index b5cf7997d5..44b9111b81 100644
--- a/src/mbgl/renderer/buckets/raster_bucket.hpp
+++ b/src/mbgl/renderer/buckets/raster_bucket.hpp
@@ -31,7 +31,7 @@ public:
// Raster Tile Sources use the default buffers from Painter
gl::VertexVector<RasterLayoutVertex> vertices;
gl::IndexVector<gl::Triangles> indices;
- gl::SegmentVector<RasterAttributes> segments;
+ SegmentVector<RasterAttributes> segments;
optional<gl::VertexBuffer<RasterLayoutVertex>> vertexBuffer;
optional<gl::IndexBuffer<gl::Triangles>> indexBuffer;
diff --git a/src/mbgl/renderer/buckets/symbol_bucket.hpp b/src/mbgl/renderer/buckets/symbol_bucket.hpp
index ffa22e9021..424c9d0f74 100644
--- a/src/mbgl/renderer/buckets/symbol_bucket.hpp
+++ b/src/mbgl/renderer/buckets/symbol_bucket.hpp
@@ -4,7 +4,7 @@
#include <mbgl/map/mode.hpp>
#include <mbgl/gl/vertex_buffer.hpp>
#include <mbgl/gl/index_buffer.hpp>
-#include <mbgl/gl/segment.hpp>
+#include <mbgl/programs/segment.hpp>
#include <mbgl/programs/symbol_program.hpp>
#include <mbgl/programs/collision_box_program.hpp>
#include <mbgl/text/glyph_range.hpp>
@@ -63,7 +63,7 @@ public:
gl::VertexVector<SymbolLayoutVertex> vertices;
gl::VertexVector<SymbolDynamicLayoutAttributes::Vertex> dynamicVertices;
gl::IndexVector<gl::Triangles> triangles;
- gl::SegmentVector<SymbolTextAttributes> segments;
+ SegmentVector<SymbolTextAttributes> segments;
std::vector<PlacedSymbol> placedSymbols;
optional<gl::VertexBuffer<SymbolLayoutVertex>> vertexBuffer;
@@ -77,7 +77,7 @@ public:
gl::VertexVector<SymbolLayoutVertex> vertices;
gl::VertexVector<SymbolDynamicLayoutAttributes::Vertex> dynamicVertices;
gl::IndexVector<gl::Triangles> triangles;
- gl::SegmentVector<SymbolIconAttributes> segments;
+ SegmentVector<SymbolIconAttributes> segments;
std::vector<PlacedSymbol> placedSymbols;
PremultipliedImage atlasImage;
@@ -89,7 +89,7 @@ public:
struct CollisionBoxBuffer {
gl::VertexVector<CollisionBoxVertex> vertices;
gl::IndexVector<gl::Lines> lines;
- gl::SegmentVector<CollisionBoxAttributes> segments;
+ SegmentVector<CollisionBoxAttributes> segments;
optional<gl::VertexBuffer<CollisionBoxVertex>> vertexBuffer;
optional<gl::VertexBuffer<SymbolDynamicLayoutAttributes::Vertex>> dynamicVertexBuffer;
diff --git a/src/mbgl/renderer/layers/render_custom_layer.cpp b/src/mbgl/renderer/layers/render_custom_layer.cpp
index 4d6084075d..81b8ac301b 100644
--- a/src/mbgl/renderer/layers/render_custom_layer.cpp
+++ b/src/mbgl/renderer/layers/render_custom_layer.cpp
@@ -48,7 +48,7 @@ void RenderCustomLayer::render(Painter& painter, PaintParameters& paintParameter
const TransformState& state = painter.state;
// Reset GL state to a known state so the CustomLayer always has a clean slate.
- context.vertexArrayObject = 0;
+ context.bindVertexArray = 0;
context.setDepthMode(painter.depthModeForSublayer(0, gl::DepthMode::ReadOnly));
context.setStencilMode(gl::StencilMode::disabled());
context.setColorMode(painter.colorModeForRenderPass());
diff --git a/src/mbgl/renderer/paint_property_binder.hpp b/src/mbgl/renderer/paint_property_binder.hpp
index f78147fc87..652948c8df 100644
--- a/src/mbgl/renderer/paint_property_binder.hpp
+++ b/src/mbgl/renderer/paint_property_binder.hpp
@@ -3,6 +3,7 @@
#include <mbgl/programs/attributes.hpp>
#include <mbgl/gl/attribute.hpp>
#include <mbgl/gl/uniform.hpp>
+#include <mbgl/gl/context.hpp>
#include <mbgl/util/type_list.hpp>
#include <mbgl/renderer/possibly_evaluated_property_value.hpp>
#include <mbgl/renderer/paint_property_statistics.hpp>
@@ -81,7 +82,7 @@ public:
virtual void populateVertexVector(const GeometryTileFeature& feature, std::size_t length) = 0;
virtual void upload(gl::Context& context) = 0;
- virtual AttributeBinding attributeBinding(const PossiblyEvaluatedPropertyValue<T>& currentValue) const = 0;
+ virtual optional<AttributeBinding> attributeBinding(const PossiblyEvaluatedPropertyValue<T>& currentValue) const = 0;
virtual float interpolationFactor(float currentZoom) const = 0;
virtual T uniformValue(const PossiblyEvaluatedPropertyValue<T>& currentValue) const = 0;
@@ -103,8 +104,8 @@ public:
void populateVertexVector(const GeometryTileFeature&, std::size_t) override {}
void upload(gl::Context&) override {}
- AttributeBinding attributeBinding(const PossiblyEvaluatedPropertyValue<T>&) const override {
- return gl::DisabledAttribute();
+ optional<AttributeBinding> attributeBinding(const PossiblyEvaluatedPropertyValue<T>&) const override {
+ return {};
}
float interpolationFactor(float) const override {
@@ -147,9 +148,9 @@ public:
vertexBuffer = context.createVertexBuffer(std::move(vertexVector));
}
- AttributeBinding attributeBinding(const PossiblyEvaluatedPropertyValue<T>& currentValue) const override {
+ optional<AttributeBinding> attributeBinding(const PossiblyEvaluatedPropertyValue<T>& currentValue) const override {
if (currentValue.isConstant()) {
- return gl::DisabledAttribute();
+ return {};
} else {
return Attribute::binding(*vertexBuffer, 0, BaseAttribute::Dimensions);
}
@@ -208,9 +209,9 @@ public:
vertexBuffer = context.createVertexBuffer(std::move(vertexVector));
}
- AttributeBinding attributeBinding(const PossiblyEvaluatedPropertyValue<T>& currentValue) const override {
+ optional<AttributeBinding> attributeBinding(const PossiblyEvaluatedPropertyValue<T>& currentValue) const override {
if (currentValue.isConstant()) {
- return gl::DisabledAttribute();
+ return {};
} else {
return Attribute::binding(*vertexBuffer, 0);
}
diff --git a/src/mbgl/renderer/painter.cpp b/src/mbgl/renderer/painter.cpp
index a3decdb603..35d03e7cb4 100644
--- a/src/mbgl/renderer/painter.cpp
+++ b/src/mbgl/renderer/painter.cpp
@@ -262,7 +262,7 @@ void Painter::render(RenderStyle& style, const FrameData& frame_, View& view) {
context.activeTexture = 0;
context.texture[0] = 0;
- context.vertexArrayObject = 0;
+ context.bindVertexArray = 0;
}
}
diff --git a/src/mbgl/renderer/painter.hpp b/src/mbgl/renderer/painter.hpp
index 7e966adefa..0b6ee3497e 100644
--- a/src/mbgl/renderer/painter.hpp
+++ b/src/mbgl/renderer/painter.hpp
@@ -172,10 +172,10 @@ public:
gl::IndexBuffer<gl::Triangles> quadTriangleIndexBuffer;
gl::IndexBuffer<gl::LineStrip> tileBorderIndexBuffer;
- gl::SegmentVector<FillAttributes> tileTriangleSegments;
- gl::SegmentVector<DebugAttributes> tileBorderSegments;
- gl::SegmentVector<RasterAttributes> rasterSegments;
- gl::SegmentVector<ExtrusionTextureAttributes> extrusionTextureSegments;
+ SegmentVector<FillAttributes> tileTriangleSegments;
+ SegmentVector<DebugAttributes> tileBorderSegments;
+ SegmentVector<RasterAttributes> rasterSegments;
+ SegmentVector<ExtrusionTextureAttributes> extrusionTextureSegments;
};
} // namespace mbgl