summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarim Naaji <karim.naaji@gmail.com>2020-06-04 10:46:13 -0700
committerKarim Naaji <karim.naaji@gmail.com>2020-06-04 11:22:35 -0700
commit03b0797f571ec31a274c7c8dca5c006df6675948 (patch)
treeaef7c199143bb37048579b546f344c5eef00d79a
parent6a54aff64e790e43d09790cf9ea781a6c162c04b (diff)
downloadqtlocation-mapboxgl-03b0797f571ec31a274c7c8dca5c006df6675948.tar.gz
-rw-r--r--platform/glfw/glfw_view.cpp20
-rw-r--r--src/mbgl/gl/renderer_backend.cpp3
-rw-r--r--src/mbgl/programs/collision_box_program.hpp2
-rw-r--r--src/mbgl/programs/line_program.cpp8
-rw-r--r--src/mbgl/programs/line_program.hpp31
-rw-r--r--src/mbgl/renderer/buckets/line_bucket.cpp20
-rw-r--r--src/mbgl/renderer/layers/render_line_layer.cpp53
-rw-r--r--src/mbgl/renderer/layers/render_line_layer.hpp5
-rw-r--r--src/mbgl/renderer/layers/render_symbol_layer.cpp3
-rw-r--r--test/gl/bucket.test.cpp2
10 files changed, 66 insertions, 81 deletions
diff --git a/platform/glfw/glfw_view.cpp b/platform/glfw/glfw_view.cpp
index 2488c1ce3b..3d2dfd3a38 100644
--- a/platform/glfw/glfw_view.cpp
+++ b/platform/glfw/glfw_view.cpp
@@ -9,6 +9,8 @@
#include <mbgl/gfx/backend_scope.hpp>
#include <mbgl/map/camera.hpp>
#include <mbgl/renderer/renderer.hpp>
+#include <mbgl/style/conversion/color_ramp_property_value.hpp>
+#include <mbgl/style/conversion/json.hpp>
#include <mbgl/style/expression/dsl.hpp>
#include <mbgl/style/image.hpp>
#include <mbgl/style/layers/fill_extrusion_layer.hpp>
@@ -25,8 +27,6 @@
#include <mbgl/util/logging.hpp>
#include <mbgl/util/platform.hpp>
#include <mbgl/util/string.hpp>
-#include <mbgl/style/conversion/color_ramp_property_value.hpp>
-#include <mbgl/style/conversion/json.hpp>
#include <mapbox/cheap_ruler.hpp>
#include <mapbox/geometry.hpp>
@@ -415,10 +415,13 @@ void GLFWView::onKey(GLFWwindow *window, int key, int /*scancode*/, int action,
using namespace mbgl::style;
auto &style = view->map->getStyle();
if (!style.getSource("line-gradient-source")) {
- std::string url = "https://gist.githubusercontent.com/karimnaaji/0ea3016a825a4c2883fce309183f0c20/raw/9f67d55c3c797b8b1183dc27a26ec705ac619198/polylines.geojson";
+ std::string url =
+ "https://gist.githubusercontent.com/karimnaaji/0ea3016a825a4c2883fce309183f0c20/raw/"
+ "9f67d55c3c797b8b1183dc27a26ec705ac619198/polylines.geojson";
GeoJSONOptions options;
options.lineMetrics = true;
- auto source = std::make_unique<GeoJSONSource>("line-gradient-source", Immutable<GeoJSONOptions>(makeMutable<GeoJSONOptions>(options)));
+ auto source = std::make_unique<GeoJSONSource>(
+ "line-gradient-source", Immutable<GeoJSONOptions>(makeMutable<GeoJSONOptions>(options)));
source->setURL(url);
style.addSource(std::move(source));
@@ -433,15 +436,16 @@ void GLFWView::onKey(GLFWwindow *window, int key, int /*scancode*/, int action,
if (!style.getLayer("line-gradient")) {
auto lineLayer = std::make_unique<LineLayer>("line-gradient", "line-gradient-source");
lineLayer->setLineWidth(PropertyValue<float>(14.0f));
- std::string rawValue = R"JSON(["step",["line-progress"],"rgba(0, 0, 255, 0.1)",0.25,"red",0.6,"yellow"])JSON";
- //std::string rawValue = R"JSON(["interpolate",["linear"],["line-progress"],0,"rgba(0, 0, 255, 0)",0.1,"royalblue",0.3,"cyan",0.5,"lime",0.7,"yellow",1,"red"])JSON";
+ std::string rawValue =
+ R"JSON(["step",["line-progress"],"rgba(0, 0, 255, 0.1)",0.25,"red",0.6,"yellow"])JSON";
+ // std::string rawValue = R"JSON(["interpolate",["linear"],["line-progress"],0,"rgba(0, 0, 255,
+ // 0)",0.1,"royalblue",0.3,"cyan",0.5,"lime",0.7,"yellow",1,"red"])JSON";
conversion::Error error;
auto ramp = conversion::convertJSON<ColorRampPropertyValue>(rawValue, error);
lineLayer->setLineGradient(ramp.value());
style.addLayer(std::move(lineLayer));
}
- }
- break;
+ } break;
case GLFW_KEY_F: {
using namespace mbgl;
using namespace mbgl::style;
diff --git a/src/mbgl/gl/renderer_backend.cpp b/src/mbgl/gl/renderer_backend.cpp
index 04e123e38d..4e44096157 100644
--- a/src/mbgl/gl/renderer_backend.cpp
+++ b/src/mbgl/gl/renderer_backend.cpp
@@ -15,8 +15,7 @@ RendererBackend::RendererBackend(const gfx::ContextMode contextMode_)
std::unique_ptr<gfx::Context> RendererBackend::createContext() {
auto result = std::make_unique<gl::Context>(*this);
result->enableDebugging();
- result->initialize(
- std::bind(&RendererBackend::getExtensionFunctionPointer, this, std::placeholders::_1));
+ result->initialize(std::bind(&RendererBackend::getExtensionFunctionPointer, this, std::placeholders::_1));
return result;
}
diff --git a/src/mbgl/programs/collision_box_program.hpp b/src/mbgl/programs/collision_box_program.hpp
index 43d57303e1..bca6478496 100644
--- a/src/mbgl/programs/collision_box_program.hpp
+++ b/src/mbgl/programs/collision_box_program.hpp
@@ -55,7 +55,7 @@ public:
};
}
- template <class DrawMode>
+ template <class DrawMode>
void draw(gfx::Context& context,
gfx::RenderPass& renderPass,
const DrawMode& drawMode,
diff --git a/src/mbgl/programs/line_program.cpp b/src/mbgl/programs/line_program.cpp
index 6ea38deed7..59c774cc60 100644
--- a/src/mbgl/programs/line_program.cpp
+++ b/src/mbgl/programs/line_program.cpp
@@ -117,13 +117,7 @@ LineGradientProgram::LayoutUniformValues LineGradientProgram::layoutUniformValue
const float pixelRatio,
const float imageHeight) {
return makeValues<LineGradientProgram::LayoutUniformValues>(
- properties,
- tile,
- state,
- pixelsToGLUnits,
- pixelRatio,
- imageHeight
- );
+ properties, tile, state, pixelsToGLUnits, pixelRatio, imageHeight);
}
} // namespace mbgl
diff --git a/src/mbgl/programs/line_program.hpp b/src/mbgl/programs/line_program.hpp
index 8b9eaf76a8..06055414cb 100644
--- a/src/mbgl/programs/line_program.hpp
+++ b/src/mbgl/programs/line_program.hpp
@@ -37,10 +37,7 @@ using LineLayoutAttributes = TypeList<
attributes::pos_normal,
attributes::data<uint8_t, 4>>;
-using LineLayoutAttributesExt = TypeList<
- attributes::line_progress,
- attributes::line_clip,
- attributes::split_index>;
+using LineLayoutAttributesExt = TypeList<attributes::line_progress, attributes::line_clip, attributes::split_index>;
class LineProgram : public Program<
LineProgram,
@@ -173,21 +170,17 @@ using LineLayoutVertex = LineProgram::LayoutVertex;
using LineAttributes = LineProgram::AttributeList;
using LineLayoutVertexExt = gfx::Vertex<LineLayoutAttributesExt>;
-class LineGradientProgram : public Program<
- LineGradientProgram,
- gfx::PrimitiveType::Triangle,
- LineLayoutAttributes,
- TypeList<
- uniforms::matrix,
- uniforms::ratio,
- uniforms::units_to_pixels,
- uniforms::device_pixel_ratio,
- uniforms::image_height>,
- TypeList<
- textures::image>,
- style::LinePaintProperties,
- LineLayoutAttributesExt>
-{
+class LineGradientProgram : public Program<LineGradientProgram,
+ gfx::PrimitiveType::Triangle,
+ LineLayoutAttributes,
+ TypeList<uniforms::matrix,
+ uniforms::ratio,
+ uniforms::units_to_pixels,
+ uniforms::device_pixel_ratio,
+ uniforms::image_height>,
+ TypeList<textures::image>,
+ style::LinePaintProperties,
+ LineLayoutAttributesExt> {
public:
using Program::Program;
diff --git a/src/mbgl/renderer/buckets/line_bucket.cpp b/src/mbgl/renderer/buckets/line_bucket.cpp
index 1cd1f13851..0bda994160 100644
--- a/src/mbgl/renderer/buckets/line_bucket.cpp
+++ b/src/mbgl/renderer/buckets/line_bucket.cpp
@@ -148,7 +148,7 @@ void LineBucket::addGeometry(const GeometryCoordinates& coordinates,
maxLineLength = std::max<double>(maxLineLength, total_length);
lineDistances = Distances{
*numericValue<double>(clip_start_it->second), *numericValue<double>(clip_end_it->second), total_length};
- lineClips.push_back(LineClip{ lineDistances->clipStart, lineDistances->clipEnd });
+ lineClips.push_back(LineClip{lineDistances->clipStart, lineDistances->clipEnd});
}
const LineJoinType joinType = layout.evaluate<LineJoin>(zoom, feature, canonical);
@@ -478,11 +478,10 @@ void LineBucket::addCurrentVertex(const GeometryCoordinate& currentCoordinate,
extrude = extrude - (util::perp(normal) * endLeft);
vertices.emplace_back(LineProgram::layoutVertex(currentCoordinate, extrude, round, false, endLeft, scaledDistance * LINE_DISTANCE_SCALE));
if (lineDistances) {
- vertices2.emplace_back(LineLayoutVertexExt {
- { static_cast<float>(lineDistances->lineDistance(distance) - lineDistances->clipStart) },
- { static_cast<float>(lineDistances->clipEnd - lineDistances->clipStart) },
- { static_cast<uint32_t>(lineClips.size()) }
- });
+ vertices2.emplace_back(
+ LineLayoutVertexExt{{static_cast<float>(lineDistances->lineDistance(distance) - lineDistances->clipStart)},
+ {static_cast<float>(lineDistances->clipEnd - lineDistances->clipStart)},
+ {static_cast<uint32_t>(lineClips.size())}});
}
e3 = vertices.elements() - 1 - startVertex;
if (e1 >= 0 && e2 >= 0) {
@@ -496,11 +495,10 @@ void LineBucket::addCurrentVertex(const GeometryCoordinate& currentCoordinate,
extrude = extrude - (util::perp(normal) * endRight);
vertices.emplace_back(LineProgram::layoutVertex(currentCoordinate, extrude, round, true, -endRight, scaledDistance * LINE_DISTANCE_SCALE));
if (lineDistances) {
- vertices2.emplace_back(LineLayoutVertexExt {
- { static_cast<float>(lineDistances->lineDistance(distance) - lineDistances->clipStart) },
- { static_cast<float>(lineDistances->clipEnd - lineDistances->clipStart) },
- { static_cast<uint32_t>(lineClips.size()) }
- });
+ vertices2.emplace_back(
+ LineLayoutVertexExt{{static_cast<float>(lineDistances->lineDistance(distance) - lineDistances->clipStart)},
+ {static_cast<float>(lineDistances->clipEnd - lineDistances->clipStart)},
+ {static_cast<uint32_t>(lineClips.size())}});
}
e3 = vertices.elements() - 1 - startVertex;
if (e1 >= 0 && e2 >= 0) {
diff --git a/src/mbgl/renderer/layers/render_line_layer.cpp b/src/mbgl/renderer/layers/render_line_layer.cpp
index b0ff011447..25ed647aae 100644
--- a/src/mbgl/renderer/layers/render_line_layer.cpp
+++ b/src/mbgl/renderer/layers/render_line_layer.cpp
@@ -1,6 +1,8 @@
#include <mbgl/geometry/feature_index.hpp>
#include <mbgl/geometry/line_atlas.hpp>
#include <mbgl/gfx/cull_face_mode.hpp>
+#include <mbgl/math/clamp.hpp>
+#include <mbgl/math/log2.hpp>
#include <mbgl/programs/line_program.hpp>
#include <mbgl/programs/programs.hpp>
#include <mbgl/renderer/buckets/line_bucket.hpp>
@@ -15,8 +17,6 @@
#include <mbgl/tile/tile.hpp>
#include <mbgl/util/intersection_tests.hpp>
#include <mbgl/util/math.hpp>
-#include <mbgl/math/log2.hpp>
-#include <mbgl/math/clamp.hpp>
namespace mbgl {
@@ -76,8 +76,8 @@ void RenderLineLayer::prepare(const LayerPrepareParameters& params) {
const auto& evaluated = getEvaluated<LineLayerProperties>(renderData->layerProperties);
auto& bucket = static_cast<LineBucket&>(*renderData->bucket);
if (!evaluated.get<LineDasharray>().from.empty()) {
- const LinePatternCap cap = bucket.layout.get<LineCap>() == LineCapType::Round
- ? LinePatternCap::Round : LinePatternCap::Square;
+ const LinePatternCap cap =
+ bucket.layout.get<LineCap>() == LineCapType::Round ? LinePatternCap::Round : LinePatternCap::Square;
// Ensures that the dash data gets added to the atlas.
params.lineAtlas.getDashPatternTexture(
evaluated.get<LineDasharray>().from, evaluated.get<LineDasharray>().to, cap);
@@ -88,8 +88,7 @@ void RenderLineLayer::prepare(const LayerPrepareParameters& params) {
}
void RenderLineLayer::upload(gfx::UploadPass& uploadPass) {
- if (unevaluated.get<LineGradient>().getValue().isUndefined())
- return;
+ if (unevaluated.get<LineGradient>().getValue().isUndefined()) return;
for (const RenderTile& tile : *renderTiles) {
const LayerRenderData* renderData = tile.getLayerRenderData(*baseImpl);
@@ -207,30 +206,25 @@ void RenderLineLayer::render(PaintParameters& parameters) {
assert(bucket.gradientTexture);
auto& programInstance = parameters.programs.getLineLayerPrograms().lineGradient;
- auto&& uniformValues = LineGradientProgram::layoutUniformValues(
- evaluated,
- tile,
- parameters.state,
- parameters.pixelsToGLUnits,
- parameters.pixelRatio,
- bucket.lineClips.size());
+ auto&& uniformValues = LineGradientProgram::layoutUniformValues(evaluated,
+ tile,
+ parameters.state,
+ parameters.pixelsToGLUnits,
+ parameters.pixelRatio,
+ bucket.lineClips.size());
auto&& textureBindings = LineGradientProgram::TextureBindings{
- textures::image::Value{ bucket.gradientTexture->getResource(), samplerFiler },
+ textures::image::Value{bucket.gradientTexture->getResource(), samplerFiler},
};
const auto& paintPropertyBinders = bucket.paintPropertyBinders.at(getID());
const auto allUniformValues =
- programInstance.computeAllUniformValues(std::forward<decltype(uniformValues)>(uniformValues),
- paintPropertyBinders,
- evaluated,
- parameters.state.getZoom());
+ LineGradientProgram::computeAllUniformValues(std::forward<decltype(uniformValues)>(uniformValues),
+ paintPropertyBinders,
+ evaluated,
+ parameters.state.getZoom());
const auto allAttributeBindings = LineGradientProgram::computeAllAttributeBindings(
- *bucket.vertexBuffer,
- *bucket.vertexBuffer2,
- paintPropertyBinders,
- evaluated
- );
+ *bucket.vertexBuffer, *bucket.vertexBuffer2, paintPropertyBinders, evaluated);
- checkRenderability(parameters, programInstance.activeBindingCount(allAttributeBindings));
+ checkRenderability(parameters, LineGradientProgram::activeBindingCount(allAttributeBindings));
programInstance.draw(parameters.context,
*parameters.renderPass,
@@ -332,7 +326,10 @@ bool RenderLineLayer::queryIntersectsFeature(const GeometryCoordinates& queryGeo
halfWidth);
}
-void RenderLineLayer::updateColorRamp(LineBucket& lineBucket, const RenderTile& tile, const RenderSource& source, const TransformState& state) {
+void RenderLineLayer::updateColorRamp(LineBucket& lineBucket,
+ const RenderTile& tile,
+ const RenderSource& source,
+ const TransformState& state) {
auto colorValue = unevaluated.get<LineGradient>().getValue();
if (colorValue.isUndefined()) {
return;
@@ -344,14 +341,14 @@ void RenderLineLayer::updateColorRamp(LineBucket& lineBucket, const RenderTile&
if (isStepExpression) {
const uint8_t sourceMaxZoom = source.getMaxZoom();
const uint8_t zoomDiff = static_cast<uint8_t>(state.getMaxZoom()) - tile.id.canonical.z;
- const float potentialOverzoom = tile.id.canonical.z == sourceMaxZoom ?
- ceilf(static_cast<float>(1 << zoomDiff)) : 1.0f;
+ const float potentialOverzoom =
+ tile.id.canonical.z == sourceMaxZoom ? ceilf(static_cast<float>(1 << zoomDiff)) : 1.0f;
const float lineLength = lineBucket.maxLineLength / static_cast<float>(util::EXTENT);
// Logical pixel tile size is 512px, and 1024px right before current zoom + 1
const float maxTileSize = 1024;
// Maximum possible texture coverage heuristic, bound by hardware max texture size
const float maxTextureCoverage = lineLength * maxTileSize * potentialOverzoom;
- const uint32_t nextPowerOf2 = static_cast<uint32_t>(powf(2.0f, ceilf(util::log2<float>(maxTextureCoverage))));
+ const auto nextPowerOf2 = static_cast<uint32_t>(powf(2.0f, ceilf(util::log2<float>(maxTextureCoverage))));
textureResolution = util::clamp<uint32_t>(nextPowerOf2, 256, gfx::Context::maxTextureSize);
samplerFiler = gfx::TextureFilterType::Nearest;
diff --git a/src/mbgl/renderer/layers/render_line_layer.hpp b/src/mbgl/renderer/layers/render_line_layer.hpp
index 45592822d1..3079d0076f 100644
--- a/src/mbgl/renderer/layers/render_line_layer.hpp
+++ b/src/mbgl/renderer/layers/render_line_layer.hpp
@@ -41,7 +41,10 @@ private:
style::LinePaintProperties::Unevaluated unevaluated;
float getLineWidth(const GeometryTileFeature&, float, const FeatureState&) const;
- void updateColorRamp(LineBucket& lineBucket, const RenderTile& tile, const RenderSource& source, const TransformState& state);
+ void updateColorRamp(LineBucket& lineBucket,
+ const RenderTile& tile,
+ const RenderSource& source,
+ const TransformState& state);
uint32_t gradientVersion;
gfx::TextureFilterType samplerFiler;
diff --git a/src/mbgl/renderer/layers/render_symbol_layer.cpp b/src/mbgl/renderer/layers/render_symbol_layer.cpp
index 200a87fe9e..ddcff1eed5 100644
--- a/src/mbgl/renderer/layers/render_symbol_layer.cpp
+++ b/src/mbgl/renderer/layers/render_symbol_layer.cpp
@@ -410,8 +410,7 @@ void RenderSymbolLayer::render(PaintParameters& parameters) {
textureBindings,
this->getID() + "/" + suffix
);
- }
- );
+ });
};
for (const RenderTile& tile : *renderTiles) {
diff --git a/test/gl/bucket.test.cpp b/test/gl/bucket.test.cpp
index ab39d37540..75a09aedbf 100644
--- a/test/gl/bucket.test.cpp
+++ b/test/gl/bucket.test.cpp
@@ -266,7 +266,6 @@ TEST(Buckets, RasterBucketMaskNoChildren) {
}),
bucket.indices.vector());
-
SegmentVector expectedSegments;
expectedSegments.emplace_back(0, 0, 8, 12);
EXPECT_EQ(expectedSegments, bucket.segments);
@@ -346,7 +345,6 @@ TEST(Buckets, RasterBucketMaskNoChildren) {
}),
bucket.indices.vector());
-
SegmentVector expectedSegments;
expectedSegments.emplace_back(0, 0, 24, 36);
EXPECT_EQ(expectedSegments, bucket.segments);