From 7fb6ef01af2916a3480ddb90b1d73e7d5e3c457d Mon Sep 17 00:00:00 2001 From: "r.kuznetsov" Date: Fri, 25 Nov 2016 15:16:04 +0300 Subject: [PATCH] Added outline min zoom level --- drape_frontend/apply_feature_functors.cpp | 10 ++++-- drape_frontend/apply_feature_functors.hpp | 3 +- drape_frontend/area_shape.cpp | 41 ++++++++++++----------- drape_frontend/area_shape.hpp | 1 + drape_frontend/rule_drawer.cpp | 5 ++- 5 files changed, 36 insertions(+), 24 deletions(-) diff --git a/drape_frontend/apply_feature_functors.cpp b/drape_frontend/apply_feature_functors.cpp index 802a6b874a..26d95983fc 100644 --- a/drape_frontend/apply_feature_functors.cpp +++ b/drape_frontend/apply_feature_functors.cpp @@ -426,12 +426,13 @@ void ApplyPointFeature::Finish() ApplyAreaFeature::ApplyAreaFeature(m2::PointD const & tileCenter, TInsertShapeFn const & insertShape, FeatureID const & id, m2::RectD const & clipRect, bool isBuilding, float minPosZ, - float posZ, int minVisibleScale, uint8_t rank, + float posZ, int minVisibleScale, uint8_t rank, bool generateOutline, CaptionDescription const & captions) : TBase(tileCenter, insertShape, id, minVisibleScale, rank, captions, posZ) , m_minPosZ(minPosZ) , m_isBuilding(isBuilding) , m_clipRect(clipRect) + , m_generateOutline(generateOutline) {} void ApplyAreaFeature::operator()(m2::PointD const & p1, m2::PointD const & p2, m2::PointD const & p3) @@ -598,10 +599,13 @@ void ApplyAreaFeature::ProcessRule(Stylist::TRuleWrapper const & rule) params.m_posZ = m_posZ; BuildingOutline outline; - bool const calculateNormals = m_posZ > 0.0; if (m_isBuilding) + { + outline.m_generateOutline = m_generateOutline; + bool const calculateNormals = m_posZ > 0.0; CalculateBuildingOutline(calculateNormals, outline); - params.m_is3D = !outline.m_indices.empty() && calculateNormals; + params.m_is3D = !outline.m_indices.empty() && calculateNormals; + } m_insertShape(make_unique_dp(move(m_triangles), move(outline), params)); } diff --git a/drape_frontend/apply_feature_functors.hpp b/drape_frontend/apply_feature_functors.hpp index b52b20fe9d..e84d9f28a4 100644 --- a/drape_frontend/apply_feature_functors.hpp +++ b/drape_frontend/apply_feature_functors.hpp @@ -102,7 +102,7 @@ public: ApplyAreaFeature(m2::PointD const & tileCenter, TInsertShapeFn const & insertShape, FeatureID const & id, m2::RectD const & clipRect, bool isBuilding, float minPosZ, - float posZ, int minVisibleScale, uint8_t rank, + float posZ, int minVisibleScale, uint8_t rank, bool generateOutline, CaptionDescription const & captions); using TBase::operator (); @@ -128,6 +128,7 @@ private: float const m_minPosZ; bool const m_isBuilding; m2::RectD m_clipRect; + bool m_generateOutline; }; class ApplyLineFeature : public BaseApplyFeature diff --git a/drape_frontend/area_shape.cpp b/drape_frontend/area_shape.cpp index 57d82f80f3..b04b9c446e 100644 --- a/drape_frontend/area_shape.cpp +++ b/drape_frontend/area_shape.cpp @@ -70,7 +70,7 @@ void AreaShape::DrawArea(ref_ptr batcher, m2::PointD const & colorU batcher->InsertTriangleList(state, make_ref(&provider)); // Generate outline. - if (!m_buildingOutline.m_indices.empty()) + if (m_buildingOutline.m_generateOutline && !m_buildingOutline.m_indices.empty()) { glsl::vec2 const ouv = glsl::ToVec2(outlineUv); @@ -96,7 +96,7 @@ void AreaShape::DrawArea(ref_ptr batcher, m2::PointD const & colorU void AreaShape::DrawArea3D(ref_ptr batcher, m2::PointD const & colorUv, m2::PointD const & outlineUv, ref_ptr texture) const { - ASSERT(!m_buildingOutline.m_indices.empty(), ()); + ASSERT(m_buildingOutline.m_generateOutline && !m_buildingOutline.m_indices.empty(), ()); ASSERT(!m_buildingOutline.m_normals.empty(), ()); glsl::vec2 const uv = glsl::ToVec2(colorUv); @@ -140,25 +140,28 @@ void AreaShape::DrawArea3D(ref_ptr batcher, m2::PointD const & colo batcher->InsertTriangleList(state, make_ref(&provider)); // Generate outline. - glsl::vec2 const ouv = glsl::ToVec2(outlineUv); - - dp::GLState outlineState(gpu::AREA_3D_OUTLINE_PROGRAM, dp::GLState::GeometryLayer); - outlineState.SetColorTexture(texture); - outlineState.SetBlending(dp::Blending(false /* isEnabled */)); - outlineState.SetDrawAsLine(true); - - vector vertices; - vertices.reserve(m_buildingOutline.m_vertices.size()); - for (size_t i = 0; i < m_buildingOutline.m_vertices.size(); i++) + if (m_buildingOutline.m_generateOutline) { - glsl::vec2 const pos = glsl::ToVec2(ConvertToLocal(m_buildingOutline.m_vertices[i], - m_params.m_tileCenter, kShapeCoordScalar)); - vertices.emplace_back(gpu::AreaVertex(glsl::vec3(pos, -m_params.m_posZ), ouv)); - } + glsl::vec2 const ouv = glsl::ToVec2(outlineUv); - dp::AttributeProvider outlineProvider(1, vertices.size()); - outlineProvider.InitStream(0, gpu::AreaVertex::GetBindingInfo(), make_ref(vertices.data())); - batcher->InsertLineRaw(outlineState, make_ref(&outlineProvider), m_buildingOutline.m_indices); + dp::GLState outlineState(gpu::AREA_3D_OUTLINE_PROGRAM, dp::GLState::GeometryLayer); + outlineState.SetColorTexture(texture); + outlineState.SetBlending(dp::Blending(false /* isEnabled */)); + outlineState.SetDrawAsLine(true); + + vector vertices; + vertices.reserve(m_buildingOutline.m_vertices.size()); + for (size_t i = 0; i < m_buildingOutline.m_vertices.size(); i++) + { + glsl::vec2 const pos = glsl::ToVec2(ConvertToLocal(m_buildingOutline.m_vertices[i], + m_params.m_tileCenter, kShapeCoordScalar)); + vertices.emplace_back(gpu::AreaVertex(glsl::vec3(pos, -m_params.m_posZ), ouv)); + } + + dp::AttributeProvider outlineProvider(1, vertices.size()); + outlineProvider.InitStream(0, gpu::AreaVertex::GetBindingInfo(), make_ref(vertices.data())); + batcher->InsertLineRaw(outlineState, make_ref(&outlineProvider), m_buildingOutline.m_indices); + } } } // namespace df diff --git a/drape_frontend/area_shape.hpp b/drape_frontend/area_shape.hpp index 32e5db7ba0..9b5d024d11 100644 --- a/drape_frontend/area_shape.hpp +++ b/drape_frontend/area_shape.hpp @@ -16,6 +16,7 @@ struct BuildingOutline buffer_vector m_vertices; vector m_indices; vector m_normals; + bool m_generateOutline = false; }; class AreaShape : public MapShape diff --git a/drape_frontend/rule_drawer.cpp b/drape_frontend/rule_drawer.cpp index 69c21481de..5f8b7697a7 100644 --- a/drape_frontend/rule_drawer.cpp +++ b/drape_frontend/rule_drawer.cpp @@ -27,6 +27,8 @@ namespace { +int constexpr kOutlineMinZoomLevel = 16; + df::BaseApplyFeature::HotelData ExtractHotelData(FeatureType const & f) { df::BaseApplyFeature::HotelData result; @@ -250,9 +252,10 @@ void RuleDrawer::operator()(FeatureType const & f) if (applyPointStyle || is3dBuilding) minVisibleScale = feature::GetMinDrawableScale(f); + bool const generateOutline = (zoomLevel >= kOutlineMinZoomLevel); ApplyAreaFeature apply(m_globalRect.Center(), insertShape, f.GetID(), m_globalRect, isBuilding, areaMinHeight, areaHeight, minVisibleScale, - f.GetRank(), s.GetCaptionDescription()); + f.GetRank(), generateOutline, s.GetCaptionDescription()); f.ForEachTriangle(apply, zoomLevel); apply.SetHotelData(ExtractHotelData(f)); if (applyPointStyle)