diff options
author | Daria Volvenkova <d.volvenkova@corp.mail.ru> | 2016-12-08 14:02:53 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-12-08 14:02:53 +0300 |
commit | 6a7faa2a059092d23d331713e4cb172d122dcdac (patch) | |
tree | d7b79e9952bde116f9da21318654d65c65f83d7f /drape_frontend | |
parent | c2942a3296fa43b286285095207f77888a29e8dd (diff) | |
parent | bcffa5d2487f23f724278180d83a6c05c86cfed4 (diff) |
Merge pull request #4909 from rokuz/fixed-two-way-offset
Fixed calculation of two-way roads offsets
Diffstat (limited to 'drape_frontend')
-rw-r--r-- | drape_frontend/rule_drawer.cpp | 3 | ||||
-rw-r--r-- | drape_frontend/traffic_generator.cpp | 58 | ||||
-rw-r--r-- | drape_frontend/traffic_renderer.cpp | 53 | ||||
-rw-r--r-- | drape_frontend/traffic_renderer.hpp | 3 |
4 files changed, 70 insertions, 47 deletions
diff --git a/drape_frontend/rule_drawer.cpp b/drape_frontend/rule_drawer.cpp index ccd1613f38..1d0ea7d7c2 100644 --- a/drape_frontend/rule_drawer.cpp +++ b/drape_frontend/rule_drawer.cpp @@ -61,11 +61,10 @@ void ExtractTrafficGeometry(FeatureType const & f, df::RoadClass const & roadCla // Calculate road offset for two-way roads. The offset is available since a zoom level in // kMinOffsetZoomLevels. double twoWayOffset = 0.0; - double const kOffsetScalar = 0.5 * df::VisualParams::Instance().GetVisualScale(); static vector<int> const kMinOffsetZoomLevels = { 13, 11, 10 }; bool const needTwoWayOffset = !oneWay && zoomLevel > kMinOffsetZoomLevels[static_cast<int>(roadClass)]; if (needTwoWayOffset) - twoWayOffset = kOffsetScalar * pixelToGlobalScale * df::TrafficRenderer::GetPixelWidth(roadClass, zoomLevel); + twoWayOffset = pixelToGlobalScale * 0.5 * df::TrafficRenderer::GetPixelWidth(roadClass, zoomLevel); static vector<uint8_t> directions = {traffic::TrafficInfo::RoadSegmentId::kForwardDirection, traffic::TrafficInfo::RoadSegmentId::kReverseDirection}; diff --git a/drape_frontend/traffic_generator.cpp b/drape_frontend/traffic_generator.cpp index 819408bfa0..40794bdb5e 100644 --- a/drape_frontend/traffic_generator.cpp +++ b/drape_frontend/traffic_generator.cpp @@ -11,7 +11,6 @@ #include "drape/glsl_func.hpp" #include "drape/shader_def.hpp" #include "drape/texture_manager.hpp" -#include "drape/support_manager.hpp" #include "indexer/map_style_reader.hpp" @@ -219,8 +218,6 @@ void TrafficGenerator::FlushSegmentsGeometry(TileKey const & tileKey, TrafficSeg static vector<RoadClass> const kRoadClasses = {RoadClass::Class0, RoadClass::Class1, RoadClass::Class2}; static float const kDepths[] = {2.0f, 1.0f, 0.0f}; static vector<int> const kGenerateCapsZoomLevel = {14, 14, 16}; - static vector<int> const kLineDrawerRoadClass1 = {12, 13, 14}; - static vector<int> const kLineDrawerRoadClass2 = {15, 16}; for (auto geomIt = geom.begin(); geomIt != geom.end(); ++geomIt) { @@ -250,42 +247,29 @@ void TrafficGenerator::FlushSegmentsGeometry(TileKey const & tileKey, TrafficSeg dp::TextureManager::ColorRegion const & colorRegion = m_colorsCache[static_cast<size_t>(segmentColoringIt->second)]; glsl::vec2 const uv = glsl::ToVec2(colorRegion.GetTexRect().Center()); - bool generatedAsLine = false; - vector<int> const * lineDrawer = nullptr; - if (g.m_roadClass == RoadClass::Class1) - lineDrawer = &kLineDrawerRoadClass1; - else if (g.m_roadClass == RoadClass::Class2) - lineDrawer = &kLineDrawerRoadClass2; - - if (lineDrawer != nullptr) + int width = 0; + if (TrafficRenderer::CanBeRendereredAsLine(g.m_roadClass, tileKey.m_zoomLevel, width)) { - auto lineDrawerIt = find(lineDrawer->begin(), lineDrawer->end(), tileKey.m_zoomLevel); - int const w = static_cast<int>(TrafficRenderer::GetPixelWidth(g.m_roadClass, tileKey.m_zoomLevel)); - if (lineDrawerIt != lineDrawer->end() && w > 0 && w <= dp::SupportManager::Instance().GetMaxLineWidth()) - { - vector<TrafficLineStaticVertex> staticGeometry; - vector<TrafficDynamicVertex> dynamicGeometry; - GenerateLineSegment(colorRegion, g.m_polyline, tileKey.GetGlobalRect().Center(), depth, - staticGeometry, dynamicGeometry); - ASSERT_EQUAL(staticGeometry.size(), dynamicGeometry.size(), ()); - - if ((staticGeometry.size() + dynamicGeometry.size()) == 0) - continue; - - drape_ptr<dp::OverlayHandle> handle = make_unique_dp<TrafficHandle>(sid, g.m_roadClass, g.m_polyline.GetLimitRect(), uv, - staticGeometry.size()); - m_providerLines.Reset(staticGeometry.size()); - m_providerLines.UpdateStream(0 /* stream index */, make_ref(staticGeometry.data())); - m_providerLines.UpdateStream(1 /* stream index */, make_ref(dynamicGeometry.data())); - - dp::GLState curLineState = lineState; - curLineState.SetLineWidth(w * df::VisualParams::Instance().GetVisualScale()); - batcher->InsertLineStrip(curLineState, make_ref(&m_providerLines), move(handle)); - generatedAsLine = true; - } - } + vector<TrafficLineStaticVertex> staticGeometry; + vector<TrafficDynamicVertex> dynamicGeometry; + GenerateLineSegment(colorRegion, g.m_polyline, tileKey.GetGlobalRect().Center(), depth, + staticGeometry, dynamicGeometry); + ASSERT_EQUAL(staticGeometry.size(), dynamicGeometry.size(), ()); - if (!generatedAsLine) + if ((staticGeometry.size() + dynamicGeometry.size()) == 0) + continue; + + drape_ptr<dp::OverlayHandle> handle = make_unique_dp<TrafficHandle>(sid, g.m_roadClass, g.m_polyline.GetLimitRect(), uv, + staticGeometry.size()); + m_providerLines.Reset(staticGeometry.size()); + m_providerLines.UpdateStream(0 /* stream index */, make_ref(staticGeometry.data())); + m_providerLines.UpdateStream(1 /* stream index */, make_ref(dynamicGeometry.data())); + + dp::GLState curLineState = lineState; + curLineState.SetLineWidth(width); + batcher->InsertLineStrip(curLineState, make_ref(&m_providerLines), move(handle)); + } + else { vector<TrafficStaticVertex> staticGeometry; vector<TrafficDynamicVertex> dynamicGeometry; diff --git a/drape_frontend/traffic_renderer.cpp b/drape_frontend/traffic_renderer.cpp index fd4c94a201..853148892a 100644 --- a/drape_frontend/traffic_renderer.cpp +++ b/drape_frontend/traffic_renderer.cpp @@ -4,6 +4,7 @@ #include "drape/glsl_func.hpp" #include "drape/shader_def.hpp" +#include "drape/support_manager.hpp" #include "drape/vertex_array_buffer.hpp" #include "indexer/map_style_reader.hpp" @@ -30,7 +31,7 @@ float const kLeftWidthInPixel[] = // 1 2 3 4 5 6 7 8 9 10 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, //11 12 13 14 15 16 17 18 19 20 - 0.5f, 0.5f, 0.5f, 0.5f, 2.0f, 2.5f, 3.0f, 4.0f, 4.0f, 7.0f + 0.5f, 0.5f, 0.5f, 0.5f, 2.0f, 2.5f, 3.0f, 4.0f, 4.0f, 4.0f }; float const kRightWidthInPixel[] = @@ -38,25 +39,29 @@ float const kRightWidthInPixel[] = // 1 2 3 4 5 6 7 8 9 10 2.0f, 2.0f, 2.0f, 2.0f, 2.0f, 2.0f, 2.0f, 2.0f, 3.0f, 3.0f, //11 12 13 14 15 16 17 18 19 20 - 3.0f, 3.0f, 4.0f, 4.0f, 2.0f, 2.5f, 3.0f, 4.0f, 4.0f, 7.0f + 3.0f, 3.0f, 4.0f, 4.0f, 2.0f, 2.5f, 3.0f, 4.0f, 4.0f, 4.0f }; float const kRoadClass1WidthScalar[] = { // 1 2 3 4 5 6 7 8 9 10 - 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.2, + 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.3, //11 12 13 14 15 16 17 18 19 20 - 0.2, 0.2f, 0.4f, 0.5f, 0.6f, 0.6f, 1.0f, 1.0f, 1.0f, 1.0f + 0.3, 0.3f, 0.4f, 0.5f, 0.6f, 0.6f, 1.0f, 1.0f, 1.0f, 1.0f }; float const kRoadClass2WidthScalar[] = { // 1 2 3 4 5 6 7 8 9 10 - 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.2f, + 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.3f, //11 12 13 14 15 16 17 18 19 20 - 0.2f, 0.2f, 0.2f, 0.2f, 0.5f, 0.5f, 0.5f, 0.8f, 0.9f, 1.0f + 0.3f, 0.3f, 0.3f, 0.3f, 0.5f, 0.5f, 0.5f, 0.8f, 0.9f, 1.0f }; +vector<int> const kLineDrawerRoadClass1 = {12, 13, 14}; + +vector<int> const kLineDrawerRoadClass2 = {15, 16}; + float CalculateHalfWidth(ScreenBase const & screen, RoadClass const & roadClass, bool left) { double const zoomLevel = GetZoomLevel(screen.GetScale()); @@ -283,6 +288,16 @@ void TrafficRenderer::Clear(MwmSet::MwmId const & mwmId) // static float TrafficRenderer::GetPixelWidth(RoadClass const & roadClass, int zoomLevel) { + int width = 0; + if (CanBeRendereredAsLine(roadClass, zoomLevel, width)) + return static_cast<float>(width); + + return GetPixelWidthInternal(roadClass, zoomLevel); +} + +// static +float TrafficRenderer::GetPixelWidthInternal(RoadClass const & roadClass, int zoomLevel) +{ ASSERT_GREATER(zoomLevel, 1, ()); ASSERT_LESS_OR_EQUAL(zoomLevel, scales::GetUpperStyleScale(), ()); float const * widthScalar = nullptr; @@ -291,9 +306,31 @@ float TrafficRenderer::GetPixelWidth(RoadClass const & roadClass, int zoomLevel) else if (roadClass == RoadClass::Class2) widthScalar = kRoadClass2WidthScalar; - float const baseWidth = kLeftWidthInPixel[zoomLevel] + kRightWidthInPixel[zoomLevel]; - return (widthScalar != nullptr) ? (baseWidth * widthScalar[zoomLevel]) : baseWidth; + int const index = zoomLevel - 1; + float const baseWidth = (kLeftWidthInPixel[index] + kRightWidthInPixel[index]) * + df::VisualParams::Instance().GetVisualScale(); + return (widthScalar != nullptr) ? (baseWidth * widthScalar[index]) : baseWidth; } +// static +bool TrafficRenderer::CanBeRendereredAsLine(RoadClass const & roadClass, int zoomLevel, int & width) +{ + if (roadClass == RoadClass::Class0) + return false; + + vector<int> const * lineDrawer = nullptr; + if (roadClass == RoadClass::Class1) + lineDrawer = &kLineDrawerRoadClass1; + else if (roadClass == RoadClass::Class2) + lineDrawer = &kLineDrawerRoadClass2; + + ASSERT(lineDrawer != nullptr, ()); + auto it = find(lineDrawer->begin(), lineDrawer->end(), zoomLevel); + if (it == lineDrawer->end()) + return false; + + width = max(1, my::rounds(TrafficRenderer::GetPixelWidthInternal(roadClass, zoomLevel))); + return width <= dp::SupportManager::Instance().GetMaxLineWidth(); +} } // namespace df diff --git a/drape_frontend/traffic_renderer.hpp b/drape_frontend/traffic_renderer.hpp index 916d1a69cf..b1bdc2f86e 100644 --- a/drape_frontend/traffic_renderer.hpp +++ b/drape_frontend/traffic_renderer.hpp @@ -41,8 +41,11 @@ public: void OnGeometryReady(int currentZoomLevel); static float GetPixelWidth(RoadClass const & roadClass, int zoomLevel); + static bool CanBeRendereredAsLine(RoadClass const & roadClass, int zoomLevel, int & width); private: + static float GetPixelWidthInternal(RoadClass const & roadClass, int zoomLevel); + vector<TrafficRenderData> m_renderData; TrafficTexCoords m_texCoords; }; |