forked from organicmaps/organicmaps
User lines rendering.
This commit is contained in:
parent
2cd1db6066
commit
55b61e842f
13 changed files with 105 additions and 110 deletions
|
@ -264,7 +264,8 @@ void BackendRenderer::AcceptMessage(ref_ptr<Message> message)
|
|||
{
|
||||
ref_ptr<UpdateUserMarkLayerMessage> msg = message;
|
||||
size_t const layerId = msg->GetLayerId();
|
||||
m_userMarkGenerator->SetUserMarks(static_cast<GroupID>(layerId), msg->AcceptRenderParams());
|
||||
m_userMarkGenerator->SetUserMarks(static_cast<GroupID>(layerId), msg->AcceptMarkRenderParams());
|
||||
m_userMarkGenerator->SetUserLines(static_cast<GroupID>(layerId), msg->AcceptLineRenderParams());
|
||||
m_commutator->PostMessage(ThreadsCommutator::RenderThread,
|
||||
make_unique_dp<InvalidateUserMarksMessage>(layerId),
|
||||
MessagePriority::Normal);
|
||||
|
|
|
@ -209,11 +209,11 @@ void DrapeEngine::ChangeVisibilityUserMarksLayer(size_t layerId, bool isVisible)
|
|||
|
||||
void DrapeEngine::UpdateUserMarksLayer(size_t layerId, UserMarksProvider * provider)
|
||||
{
|
||||
auto renderCollection = make_unique_dp<UserMarksRenderCollection>();
|
||||
renderCollection->reserve(provider->GetUserPointCount());
|
||||
for (size_t i = 0, sz = provider->GetUserPointCount(); i < sz; ++i)
|
||||
auto marksRenderCollection = make_unique_dp<UserMarksRenderCollection>();
|
||||
marksRenderCollection->reserve(provider->GetUserPointCount());
|
||||
for (size_t pointIndex = 0, sz = provider->GetUserPointCount(); pointIndex < sz; ++pointIndex)
|
||||
{
|
||||
UserPointMark const * mark = provider->GetUserPointMark(i);
|
||||
UserPointMark const * mark = provider->GetUserPointMark(pointIndex);
|
||||
UserMarkRenderParams renderInfo;
|
||||
renderInfo.m_anchor = mark->GetAnchor();
|
||||
renderInfo.m_depth = mark->GetDepth();
|
||||
|
@ -222,10 +222,29 @@ void DrapeEngine::UpdateUserMarksLayer(size_t layerId, UserMarksProvider * provi
|
|||
renderInfo.m_pixelOffset = mark->GetPixelOffset();
|
||||
renderInfo.m_runCreationAnim = mark->RunCreationAnim();
|
||||
renderInfo.m_symbolName = mark->GetSymbolName();
|
||||
renderCollection->emplace_back(std::move(renderInfo));
|
||||
marksRenderCollection->emplace_back(std::move(renderInfo));
|
||||
}
|
||||
|
||||
auto linesRenderCollection = make_unique_dp<UserLinesRenderCollection>();
|
||||
linesRenderCollection->reserve(provider->GetUserLineCount());
|
||||
for (size_t lineIndex = 0, sz = provider->GetUserLineCount(); lineIndex < sz; ++lineIndex)
|
||||
{
|
||||
UserLineMark const * mark = provider->GetUserLineMark(lineIndex);
|
||||
UserLineRenderParams renderInfo;
|
||||
renderInfo.m_spline = m2::SharedSpline(mark->GetPoints());
|
||||
renderInfo.m_layers.reserve(mark->GetLayerCount());
|
||||
for (size_t layerIndex = 0, sz = mark->GetLayerCount(); layerIndex < sz; ++layerIndex)
|
||||
{
|
||||
renderInfo.m_layers.emplace_back(LineLayer(mark->GetColor(layerIndex),
|
||||
mark->GetWidth(layerIndex),
|
||||
mark->GetLayerDepth(layerIndex)));
|
||||
}
|
||||
linesRenderCollection->emplace_back(std::move(renderInfo));
|
||||
}
|
||||
m_threadCommutator->PostMessage(ThreadsCommutator::ResourceUploadThread,
|
||||
make_unique_dp<UpdateUserMarkLayerMessage>(layerId, std::move(renderCollection)),
|
||||
make_unique_dp<UpdateUserMarkLayerMessage>(layerId,
|
||||
std::move(marksRenderCollection),
|
||||
std::move(linesRenderCollection)),
|
||||
MessagePriority::Normal);
|
||||
}
|
||||
|
||||
|
|
|
@ -1274,11 +1274,7 @@ void FrontendRenderer::RenderUserMarksLayer(ScreenBase const & modelView)
|
|||
{
|
||||
RenderLayer & userMarks = m_layers[RenderLayer::UserMarkID];
|
||||
for (drape_ptr<RenderGroup> & group : userMarks.m_renderGroups)
|
||||
{
|
||||
// TODO: Remove after user lines complete realization.
|
||||
//if (!group->CanBeClipped())
|
||||
RenderSingleGroup(modelView, make_ref(group));
|
||||
}
|
||||
RenderSingleGroup(modelView, make_ref(group));
|
||||
}
|
||||
|
||||
void FrontendRenderer::BuildOverlayTree(ScreenBase const & modelView)
|
||||
|
|
|
@ -237,17 +237,21 @@ private:
|
|||
class UpdateUserMarkLayerMessage : public BaseUserMarkLayerMessage
|
||||
{
|
||||
public:
|
||||
UpdateUserMarkLayerMessage(size_t layerId, drape_ptr<UserMarksRenderCollection> && renderParams)
|
||||
UpdateUserMarkLayerMessage(size_t layerId, drape_ptr<UserMarksRenderCollection> && marksRenderParams,
|
||||
drape_ptr<UserLinesRenderCollection> && linesRenderParams)
|
||||
: BaseUserMarkLayerMessage(layerId)
|
||||
, m_renderParams(std::move(renderParams))
|
||||
, m_marksRenderParams(std::move(marksRenderParams))
|
||||
, m_linesRenderParams(std::move(linesRenderParams))
|
||||
{}
|
||||
|
||||
Type GetType() const override { return Message::UpdateUserMarkLayer; }
|
||||
|
||||
drape_ptr<UserMarksRenderCollection> && AcceptRenderParams() { return std::move(m_renderParams); }
|
||||
drape_ptr<UserMarksRenderCollection> && AcceptMarkRenderParams() { return std::move(m_marksRenderParams); }
|
||||
drape_ptr<UserLinesRenderCollection> && AcceptLineRenderParams() { return std::move(m_linesRenderParams); }
|
||||
|
||||
private:
|
||||
drape_ptr<UserMarksRenderCollection> m_renderParams;
|
||||
drape_ptr<UserMarksRenderCollection> m_marksRenderParams;
|
||||
drape_ptr<UserLinesRenderCollection> m_linesRenderParams;
|
||||
};
|
||||
|
||||
class FlushUserMarksMessage : public BaseUserMarkLayerMessage
|
||||
|
|
|
@ -223,7 +223,7 @@ void UserMarkRenderGroup::UpdateAnimation()
|
|||
m_uniforms.SetFloatValue("u_interpolationT", m_mapping.GetValue(t));
|
||||
}
|
||||
|
||||
bool UserMarkRenderGroup::CanBeClipped() const
|
||||
bool UserMarkRenderGroup::IsUserPoint() const
|
||||
{
|
||||
return m_state.GetProgramIndex() != gpu::LINE_PROGRAM;
|
||||
}
|
||||
|
|
|
@ -101,7 +101,7 @@ public:
|
|||
|
||||
void UpdateAnimation() override;
|
||||
|
||||
bool CanBeClipped() const;
|
||||
bool IsUserPoint() const;
|
||||
|
||||
private:
|
||||
unique_ptr<OpacityAnimation> m_animation;
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include "drape_frontend/user_mark_generator.hpp"
|
||||
#include "drape_frontend/tile_utils.hpp"
|
||||
|
||||
#include "geometry/rect_intersect.hpp"
|
||||
|
||||
#include "indexer/scales.hpp"
|
||||
|
||||
namespace df
|
||||
|
@ -47,9 +49,10 @@ void UserMarkGenerator::UpdateMarksIndex(uint32_t groupId)
|
|||
UserMarksRenderCollection & marks = *m_marks[groupId];
|
||||
for (size_t markIndex = 0; markIndex < marks.size(); ++markIndex)
|
||||
{
|
||||
for (int zoomLevel = 1; zoomLevel <= scales::GetUpperScale(); ++zoomLevel)
|
||||
UserMarkRenderParams const & params = marks[markIndex];
|
||||
for (int zoomLevel = params.m_minZoom; zoomLevel <= scales::GetUpperScale(); ++zoomLevel)
|
||||
{
|
||||
TileKey const tileKey = GetTileKeyByPoint(marks[markIndex].m_pivot, zoomLevel);
|
||||
TileKey const tileKey = GetTileKeyByPoint(params.m_pivot, zoomLevel);
|
||||
ref_ptr<IndexesCollection> groupIndexes = GetIndexesCollection(tileKey, groupId);
|
||||
groupIndexes->m_markIndexes.push_back(static_cast<uint32_t>(markIndex));
|
||||
}
|
||||
|
@ -73,19 +76,19 @@ void UserMarkGenerator::UpdateLinesIndex(uint32_t groupId)
|
|||
UserLinesRenderCollection & lines = *m_lines[groupId];
|
||||
for (size_t lineIndex = 0; lineIndex < lines.size(); ++lineIndex)
|
||||
{
|
||||
for (int zoomLevel = 1; zoomLevel <= scales::GetUpperScale(); ++zoomLevel)
|
||||
UserLineRenderParams const & params = lines[lineIndex];
|
||||
m2::RectD rect;
|
||||
for (m2::PointD const & point : params.m_spline->GetPath())
|
||||
rect.Add(point);
|
||||
|
||||
for (int zoomLevel = params.m_minZoom; zoomLevel <= scales::GetUpperScale(); ++zoomLevel)
|
||||
{
|
||||
// TODO: Calculate tiles for the line properly.
|
||||
std::set<TileKey> tiles;
|
||||
for (size_t i = 0, sz = lines[lineIndex].m_points.size(); i < sz; ++i)
|
||||
{
|
||||
tiles.insert(GetTileKeyByPoint(lines[lineIndex].m_points[i], zoomLevel));
|
||||
}
|
||||
for (auto const & tileKey : tiles)
|
||||
CalcTilesCoverage(rect, zoomLevel, [&](int tileX, int tileY)
|
||||
{
|
||||
TileKey const tileKey(tileX, tileY, zoomLevel);
|
||||
ref_ptr<IndexesCollection> groupIndexes = GetIndexesCollection(tileKey, groupId);
|
||||
groupIndexes->m_lineIndexes.push_back(static_cast<uint32_t>(lineIndex));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -163,15 +166,13 @@ void UserMarkGenerator::GenerateUserMarksGeometry(TileKey const & tileKey, ref_p
|
|||
for (auto & groupPair : indexesGroups)
|
||||
{
|
||||
GroupID groupId = groupPair.first;
|
||||
UserMarksRenderCollection const & renderParams = *m_marks[groupId];
|
||||
MarkIndexesCollection const & indexes = groupPair.second->m_markIndexes;
|
||||
|
||||
if (m_groupsVisibility.find(groupId) == m_groupsVisibility.end())
|
||||
continue;
|
||||
|
||||
TUserMarksRenderData renderData;
|
||||
CacheUserMarks(tileKey, textures, renderParams, indexes, renderData);
|
||||
|
||||
CacheUserMarks(tileKey, textures, *m_marks[groupId], groupPair.second->m_markIndexes, renderData);
|
||||
CacheUserLines(tileKey, textures, *m_lines[groupId], groupPair.second->m_lineIndexes, renderData);
|
||||
m_flushFn(groupId, std::move(renderData));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,8 +8,9 @@
|
|||
|
||||
#include "drape/utils/vertex_decl.hpp"
|
||||
#include "drape/attribute_provider.hpp"
|
||||
#include "drape/batcher.hpp"
|
||||
|
||||
#include "geometry/spline.hpp"
|
||||
#include "geometry/clipping.hpp"
|
||||
|
||||
namespace df
|
||||
{
|
||||
|
@ -146,64 +147,37 @@ void CacheUserLines(TileKey const & tileKey, ref_ptr<dp::TextureManager> texture
|
|||
UserLinesRenderCollection const & renderParams, LineIndexesCollection const & indexes,
|
||||
TUserMarksRenderData & renderData)
|
||||
{
|
||||
// TODO: Refactor old caching to the new scheme.
|
||||
}
|
||||
|
||||
/*
|
||||
void CacheUserLines(UserMarksProvider const * provider, ref_ptr<dp::TextureManager> textures,
|
||||
TUserMarkShapes & outShapes)
|
||||
{
|
||||
int const kZoomLevel = 10;
|
||||
map<TileKey, vector<pair<UserLineMark const *, m2::SharedSpline>>> userLines;
|
||||
for (size_t i = 0; i < provider->GetUserLineCount(); ++i)
|
||||
uint32_t const kBatchSize = 5000;
|
||||
for (auto lineIndex : indexes)
|
||||
{
|
||||
UserLineMark const * line = provider->GetUserLineMark(i);
|
||||
size_t const pointCount = line->GetPointCount();
|
||||
UserLineRenderParams const & renderInfo = renderParams[lineIndex];
|
||||
|
||||
vector<m2::PointD> points;
|
||||
m2::RectD rect;
|
||||
points.reserve(pointCount);
|
||||
for (size_t i = 0; i < pointCount; ++i)
|
||||
{
|
||||
points.push_back(line->GetPoint(i));
|
||||
rect.Add(points.back());
|
||||
}
|
||||
|
||||
TileKey const tileKey = GetTileKeyByPoint(rect.Center(), kZoomLevel);
|
||||
userLines[tileKey].push_back(make_pair(line, m2::SharedSpline(points)));
|
||||
}
|
||||
|
||||
int const kBatchSize = 5000;
|
||||
for (auto it = userLines.begin(); it != userLines.end(); ++it)
|
||||
{
|
||||
TileKey const & key = it->first;
|
||||
dp::Batcher batcher(kBatchSize, kBatchSize);
|
||||
dp::SessionGuard guard(batcher, [&key, &outShapes](dp::GLState const & state,
|
||||
dp::SessionGuard guard(batcher, [&tileKey, &renderData](dp::GLState const & state,
|
||||
drape_ptr<dp::RenderBucket> && b)
|
||||
{
|
||||
outShapes.emplace_back(UserMarksRenderData(state, move(b), key));
|
||||
renderData.emplace_back(UserMarkRenderData(state, move(b), tileKey));
|
||||
});
|
||||
for (auto const & lineData : it->second)
|
||||
|
||||
std::vector<m2::SharedSpline> const splines = m2::ClipSplineByRect(tileKey.GetGlobalRect(), renderInfo.m_spline);
|
||||
for (auto const & spline : splines)
|
||||
{
|
||||
UserLineMark const * line = lineData.first;
|
||||
for (size_t layerIndex = 0; layerIndex < line->GetLayerCount(); ++layerIndex)
|
||||
for (auto const & layer : renderInfo.m_layers)
|
||||
{
|
||||
LineViewParams params;
|
||||
params.m_tileCenter = key.GetGlobalRect().Center();
|
||||
params.m_tileCenter = tileKey.GetGlobalRect().Center();
|
||||
params.m_baseGtoPScale = 1.0f;
|
||||
params.m_cap = dp::RoundCap;
|
||||
params.m_join = dp::RoundJoin;
|
||||
params.m_color = line->GetColor(layerIndex);
|
||||
params.m_depth = line->GetLayerDepth(layerIndex);
|
||||
params.m_width = line->GetWidth(layerIndex);
|
||||
params.m_color = layer.m_color;
|
||||
params.m_depth = layer.m_depth;
|
||||
params.m_width = layer.m_width;
|
||||
params.m_minVisibleScale = 1;
|
||||
params.m_rank = 0;
|
||||
|
||||
LineShape(lineData.second, params).Draw(make_ref(&batcher), textures);
|
||||
LineShape(spline, params).Draw(make_ref(&batcher), textures);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
} // namespace df
|
||||
|
|
|
@ -1,40 +1,49 @@
|
|||
#pragma once
|
||||
|
||||
#include "tile_key.hpp"
|
||||
#include "user_marks_provider.hpp"
|
||||
|
||||
#include "drape/batcher.hpp"
|
||||
#include "drape/glstate.hpp"
|
||||
#include "drape/render_bucket.hpp"
|
||||
#include "drape/texture_manager.hpp"
|
||||
|
||||
#include "geometry/point2d.hpp"
|
||||
#include "geometry/spline.hpp"
|
||||
|
||||
#include "std/function.hpp"
|
||||
#include <memory>
|
||||
|
||||
namespace df
|
||||
{
|
||||
|
||||
struct UserMarkRenderParams
|
||||
{
|
||||
m2::PointD m_pivot;
|
||||
m2::PointD m_pixelOffset;
|
||||
int m_minZoom = 1;
|
||||
m2::PointD m_pivot = m2::PointD(0.0, 0.0);
|
||||
m2::PointD m_pixelOffset = m2::PointD(0.0, 0.0);
|
||||
std::string m_symbolName;
|
||||
dp::Anchor m_anchor;
|
||||
float m_depth;
|
||||
bool m_runCreationAnim;
|
||||
bool m_isVisible;
|
||||
dp::Anchor m_anchor = dp::Center;
|
||||
float m_depth = 0.0;
|
||||
bool m_runCreationAnim = false;
|
||||
bool m_isVisible = true;
|
||||
};
|
||||
|
||||
struct LineLayer
|
||||
{
|
||||
LineLayer() = default;
|
||||
LineLayer(dp::Color color, float width, float depth)
|
||||
: m_color(color)
|
||||
, m_width(width)
|
||||
, m_depth(depth)
|
||||
{}
|
||||
|
||||
dp::Color m_color;
|
||||
float m_width;
|
||||
float m_depth;
|
||||
float m_width = 0.0;
|
||||
float m_depth = 0.0;
|
||||
};
|
||||
|
||||
struct UserLineRenderParams
|
||||
{
|
||||
int m_minZoom = 1;
|
||||
std::vector<LineLayer> m_layers;
|
||||
std::vector<m2::PointD> m_points;
|
||||
m2::SharedSpline m_spline;
|
||||
};
|
||||
|
||||
using UserMarksRenderCollection = std::vector<UserMarkRenderParams>;
|
||||
|
|
|
@ -2,11 +2,12 @@
|
|||
|
||||
#include "drape/drape_global.hpp"
|
||||
|
||||
#include "geometry/point2d.hpp"
|
||||
#include "geometry/polyline2d.hpp"
|
||||
|
||||
#include "base/mutex.hpp"
|
||||
|
||||
#include "std/atomic.hpp"
|
||||
#include <atomic>
|
||||
#include <vector>
|
||||
|
||||
namespace df
|
||||
{
|
||||
|
@ -17,7 +18,7 @@ public:
|
|||
virtual ~UserPointMark() {}
|
||||
virtual m2::PointD const & GetPivot() const = 0;
|
||||
virtual m2::PointD GetPixelOffset() const = 0;
|
||||
virtual string GetSymbolName() const = 0;
|
||||
virtual std::string GetSymbolName() const = 0;
|
||||
virtual dp::Anchor GetAnchor() const = 0;
|
||||
virtual float GetDepth() const = 0;
|
||||
virtual bool RunCreationAnim() const = 0;
|
||||
|
@ -33,10 +34,7 @@ public:
|
|||
virtual dp::Color const & GetColor(size_t layerIndex) const = 0;
|
||||
virtual float GetWidth(size_t layerIndex) const = 0;
|
||||
virtual float GetLayerDepth(size_t layerIndex) const = 0;
|
||||
|
||||
/// Line geometry enumeration
|
||||
virtual size_t GetPointCount() const = 0;
|
||||
virtual m2::PointD const & GetPoint(size_t pointIndex) const = 0;
|
||||
virtual std::vector<m2::PointD> const & GetPoints() const = 0;
|
||||
};
|
||||
|
||||
class UserMarksProvider
|
||||
|
@ -77,8 +75,8 @@ private:
|
|||
|
||||
threads::Mutex m_mutex;
|
||||
bool m_isDirty = false;
|
||||
atomic<bool> m_pendingOnDelete;
|
||||
atomic<int> m_counter;
|
||||
std::atomic<bool> m_pendingOnDelete;
|
||||
std::atomic<int> m_counter;
|
||||
};
|
||||
|
||||
} // namespace df
|
||||
|
|
|
@ -181,7 +181,8 @@ namespace
|
|||
string const kStyleUrl = "styleUrl";
|
||||
string const kPair = "Pair";
|
||||
|
||||
dp::Color const kDefaultTrackColor = dp::Extract(0xFF33CCFF);
|
||||
dp::Color const kDefaultTrackColor = dp::Extract(0xFF1E96F0);
|
||||
float const kDefaultTrackWidth = 15.0f;
|
||||
|
||||
string PointToString(m2::PointD const & org)
|
||||
{
|
||||
|
@ -410,7 +411,7 @@ namespace
|
|||
else if (GEOMETRY_TYPE_LINE == m_geometryType)
|
||||
{
|
||||
Track::Params params;
|
||||
params.m_colors.push_back({ 5.0f, m_trackColor });
|
||||
params.m_colors.push_back({ kDefaultTrackWidth, m_trackColor });
|
||||
params.m_name = m_name;
|
||||
|
||||
/// @todo Add description, style, timestamp
|
||||
|
|
|
@ -62,12 +62,7 @@ float Track::GetLayerDepth(size_t layerIndex) const
|
|||
return 0 + layerIndex * 10;
|
||||
}
|
||||
|
||||
size_t Track::GetPointCount() const
|
||||
std::vector<m2::PointD> const & Track::GetPoints() const
|
||||
{
|
||||
return m_polyline.GetSize();
|
||||
}
|
||||
|
||||
m2::PointD const & Track::GetPoint(size_t pointIndex) const
|
||||
{
|
||||
return m_polyline.GetPoint(pointIndex);
|
||||
return m_polyline.GetPoints();
|
||||
}
|
||||
|
|
|
@ -43,10 +43,7 @@ public:
|
|||
dp::Color const & GetColor(size_t layerIndex) const override;
|
||||
float GetWidth(size_t layerIndex) const override;
|
||||
float GetLayerDepth(size_t layerIndex) const override;
|
||||
|
||||
/// Line geometry enumeration
|
||||
size_t GetPointCount() const override;
|
||||
m2::PointD const & GetPoint(size_t pointIndex) const override;
|
||||
std::vector<m2::PointD> const & GetPoints() const override;
|
||||
|
||||
private:
|
||||
PolylineD m_polyline;
|
||||
|
|
Loading…
Add table
Reference in a new issue