forked from organicmaps/organicmaps
User marks optimization. Calculation of a user mark depth in the shader.
This commit is contained in:
parent
55b61e842f
commit
d83bd7c462
13 changed files with 54 additions and 60 deletions
|
@ -32,7 +32,7 @@ BackendRenderer::BackendRenderer(Params && params)
|
|||
, m_readManager(make_unique_dp<ReadManager>(params.m_commutator, m_model,
|
||||
params.m_allow3dBuildings, params.m_trafficEnabled))
|
||||
, m_trafficGenerator(make_unique_dp<TrafficGenerator>(bind(&BackendRenderer::FlushTrafficRenderData, this, _1)))
|
||||
, m_userMarkGenerator(make_unique_dp<UserMarkGenerator>(bind(&BackendRenderer::FlushUserMarksRenderData, this, _1, _2)))
|
||||
, m_userMarkGenerator(make_unique_dp<UserMarkGenerator>(bind(&BackendRenderer::FlushUserMarksRenderData, this, _1)))
|
||||
, m_requestedTiles(params.m_requestedTiles)
|
||||
, m_updateCurrentCountryFn(params.m_updateCurrentCountryFn)
|
||||
, m_metalineManager(make_unique_dp<MetalineManager>(params.m_commutator, m_model))
|
||||
|
@ -593,10 +593,10 @@ void BackendRenderer::FlushTrafficRenderData(TrafficRenderData && renderData)
|
|||
MessagePriority::Normal);
|
||||
}
|
||||
|
||||
void BackendRenderer::FlushUserMarksRenderData(GroupID groupId, TUserMarksRenderData && renderData)
|
||||
void BackendRenderer::FlushUserMarksRenderData(TUserMarksRenderData && renderData)
|
||||
{
|
||||
m_commutator->PostMessage(ThreadsCommutator::RenderThread,
|
||||
make_unique_dp<FlushUserMarksMessage>(groupId, std::move(renderData)),
|
||||
make_unique_dp<FlushUserMarksMessage>(std::move(renderData)),
|
||||
MessagePriority::Normal);
|
||||
}
|
||||
|
||||
|
|
|
@ -96,7 +96,7 @@ private:
|
|||
void FlushGeometry(TileKey const & key, dp::GLState const & state, drape_ptr<dp::RenderBucket> && buffer);
|
||||
|
||||
void FlushTrafficRenderData(TrafficRenderData && renderData);
|
||||
void FlushUserMarksRenderData(GroupID groupId, TUserMarksRenderData && renderData);
|
||||
void FlushUserMarksRenderData(TUserMarksRenderData && renderData);
|
||||
|
||||
void CleanupOverlays(TileKey const & tileKey);
|
||||
|
||||
|
|
|
@ -235,9 +235,9 @@ void DrapeEngine::UpdateUserMarksLayer(size_t layerId, UserMarksProvider * provi
|
|||
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)));
|
||||
renderInfo.m_layers.emplace_back(mark->GetColor(layerIndex),
|
||||
mark->GetWidth(layerIndex),
|
||||
mark->GetLayerDepth(layerIndex));
|
||||
}
|
||||
linesRenderCollection->emplace_back(std::move(renderInfo));
|
||||
}
|
||||
|
|
|
@ -1147,7 +1147,6 @@ void FrontendRenderer::RenderScene(ScreenBase const & modelView)
|
|||
RenderTrafficAndRouteLayer(modelView);
|
||||
}
|
||||
|
||||
// After this line we do not use (almost) depth buffer.
|
||||
GLFunctions::glDisable(gl_const::GLDepthTest);
|
||||
GLFunctions::glClear(gl_const::GLDepthBit);
|
||||
|
||||
|
@ -1272,9 +1271,12 @@ void FrontendRenderer::RenderTrafficAndRouteLayer(ScreenBase const & modelView)
|
|||
|
||||
void FrontendRenderer::RenderUserMarksLayer(ScreenBase const & modelView)
|
||||
{
|
||||
GLFunctions::glEnable(gl_const::GLDepthTest);
|
||||
GLFunctions::glClear(gl_const::GLDepthBit);
|
||||
RenderLayer & userMarks = m_layers[RenderLayer::UserMarkID];
|
||||
for (drape_ptr<RenderGroup> & group : userMarks.m_renderGroups)
|
||||
RenderSingleGroup(modelView, make_ref(group));
|
||||
GLFunctions::glDisable(gl_const::GLDepthTest);
|
||||
}
|
||||
|
||||
void FrontendRenderer::BuildOverlayTree(ScreenBase const & modelView)
|
||||
|
|
|
@ -254,12 +254,11 @@ private:
|
|||
drape_ptr<UserLinesRenderCollection> m_linesRenderParams;
|
||||
};
|
||||
|
||||
class FlushUserMarksMessage : public BaseUserMarkLayerMessage
|
||||
class FlushUserMarksMessage : public Message
|
||||
{
|
||||
public:
|
||||
FlushUserMarksMessage(size_t layerId, TUserMarksRenderData && renderData)
|
||||
: BaseUserMarkLayerMessage(layerId)
|
||||
, m_renderData(std::move(renderData))
|
||||
FlushUserMarksMessage(TUserMarksRenderData && renderData)
|
||||
: m_renderData(std::move(renderData))
|
||||
{}
|
||||
|
||||
Type GetType() const override { return Message::FlushUserMarks; }
|
||||
|
|
|
@ -18,7 +18,7 @@ TEXTURING_GUI_PROGRAM texturing_gui.vsh.glsl texturing.fsh.glsl
|
|||
RULER_PROGRAM ruler.vsh.glsl texturing.fsh.glsl
|
||||
ACCURACY_PROGRAM position_accuracy3d.vsh.glsl texturing.fsh.glsl
|
||||
MY_POSITION_PROGRAM my_position.vsh.glsl texturing.fsh.glsl
|
||||
BOOKMARK_PROGRAM user_mark.vsh.glsl texturing.fsh.glsl
|
||||
BOOKMARK_PROGRAM user_mark.vsh.glsl discarded_texturing.fsh.glsl
|
||||
ROUTE_PROGRAM route.vsh.glsl route.fsh.glsl
|
||||
ROUTE_DASH_PROGRAM route.vsh.glsl route_dash.fsh.glsl
|
||||
ROUTE_ARROW_PROGRAM route_arrow.vsh.glsl discarded_texturing.fsh.glsl
|
||||
|
@ -34,7 +34,7 @@ MASKED_TEXTURING_BILLBOARD_PROGRAM masked_texturing_billboard.vsh.glsl masked_te
|
|||
TEXT_OUTLINED_BILLBOARD_PROGRAM text_outlined_billboard.vsh.glsl text.fsh.glsl
|
||||
TEXT_BILLBOARD_PROGRAM text_billboard.vsh.glsl text.fsh.glsl
|
||||
TEXT_FIXED_BILLBOARD_PROGRAM text_billboard.vsh.glsl text_fixed.fsh.glsl
|
||||
BOOKMARK_BILLBOARD_PROGRAM user_mark_billboard.vsh.glsl texturing.fsh.glsl
|
||||
BOOKMARK_BILLBOARD_PROGRAM user_mark_billboard.vsh.glsl discarded_texturing.fsh.glsl
|
||||
TRAFFIC_PROGRAM traffic.vsh.glsl traffic.fsh.glsl
|
||||
TRAFFIC_LINE_PROGRAM traffic_line.vsh.glsl traffic_line.fsh.glsl
|
||||
SMAA_EDGES_PROGRAM smaa_edges.vsh.glsl smaa_edges.fsh.glsl
|
||||
|
|
|
@ -18,6 +18,8 @@ void main()
|
|||
|
||||
vec4 p = vec4(a_position, 1) * modelView;
|
||||
vec4 pos = vec4(normal, 0, 0) + p;
|
||||
vec4 projectedPivot = p * projection;
|
||||
gl_Position = applyPivotTransform(pos * projection, pivotTransform, 0.0);
|
||||
gl_Position.z = smoothstep(0.1, 0.9, projectedPivot.y / projectedPivot.w * 0.5 + 0.5);
|
||||
v_colorTexCoords = a_colorTexCoords;
|
||||
}
|
||||
|
|
|
@ -18,7 +18,8 @@ void main()
|
|||
|
||||
vec4 pivot = vec4(a_position.xyz, 1.0) * modelView;
|
||||
vec4 offset = vec4(normal, 0.0, 0.0) * projection;
|
||||
gl_Position = applyBillboardPivotTransform(pivot * projection, pivotTransform, 0.0, offset.xy);
|
||||
|
||||
vec4 projectedPivot = pivot * projection;
|
||||
gl_Position = applyBillboardPivotTransform(projectedPivot, pivotTransform, 0.0, offset.xy);
|
||||
gl_Position.z = smoothstep(0.1, 0.9, projectedPivot.y / projectedPivot.w * 0.5 + 0.5);
|
||||
v_colorTexCoords = a_colorTexCoords;
|
||||
}
|
||||
|
|
|
@ -1,10 +1,14 @@
|
|||
#include "drape_frontend/user_mark_generator.hpp"
|
||||
#include "drape_frontend/tile_utils.hpp"
|
||||
|
||||
#include "drape/batcher.hpp"
|
||||
|
||||
#include "geometry/rect_intersect.hpp"
|
||||
|
||||
#include "indexer/scales.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace df
|
||||
{
|
||||
UserMarkGenerator::UserMarkGenerator(TFlushFn const & flushFn)
|
||||
|
@ -158,22 +162,34 @@ void UserMarkGenerator::SetGroupVisibility(GroupID groupId, bool isVisible)
|
|||
|
||||
void UserMarkGenerator::GenerateUserMarksGeometry(TileKey const & tileKey, ref_ptr<dp::TextureManager> textures)
|
||||
{
|
||||
MarksIndex::const_iterator itTile = m_marksIndex.find(tileKey);
|
||||
MarksIndex::const_iterator itTile = m_marksIndex.find(TileKey(tileKey.m_x,
|
||||
tileKey.m_y,
|
||||
min(tileKey.m_zoomLevel, scales::GetUpperScale())));
|
||||
if (itTile == m_marksIndex.end())
|
||||
return;
|
||||
|
||||
MarkIndexesGroups & indexesGroups = *itTile->second;
|
||||
for (auto & groupPair : indexesGroups)
|
||||
TUserMarksRenderData renderData;
|
||||
{
|
||||
GroupID groupId = groupPair.first;
|
||||
uint32_t const kMaxSize = 65000;
|
||||
dp::Batcher batcher(kMaxSize, kMaxSize);
|
||||
dp::SessionGuard guard(batcher, [&tileKey, &renderData](dp::GLState const & state,
|
||||
drape_ptr<dp::RenderBucket> && b)
|
||||
{
|
||||
renderData.emplace_back(state, std::move(b), tileKey);
|
||||
});
|
||||
|
||||
if (m_groupsVisibility.find(groupId) == m_groupsVisibility.end())
|
||||
continue;
|
||||
MarkIndexesGroups & indexesGroups = *itTile->second;
|
||||
for (auto & groupPair : indexesGroups)
|
||||
{
|
||||
GroupID groupId = groupPair.first;
|
||||
|
||||
TUserMarksRenderData 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));
|
||||
if (m_groupsVisibility.find(groupId) == m_groupsVisibility.end())
|
||||
continue;
|
||||
|
||||
CacheUserMarks(tileKey, textures, *m_marks[groupId], groupPair.second->m_markIndexes, batcher);
|
||||
CacheUserLines(tileKey, textures, *m_lines[groupId], groupPair.second->m_lineIndexes, batcher);
|
||||
}
|
||||
}
|
||||
m_flushFn(std::move(renderData));
|
||||
}
|
||||
} // namespace df
|
||||
|
|
|
@ -28,7 +28,7 @@ using MarksIndex = std::map<TileKey, drape_ptr<MarkIndexesGroups>>;
|
|||
class UserMarkGenerator
|
||||
{
|
||||
public:
|
||||
using TFlushFn = function<void(GroupID, TUserMarksRenderData && renderData)>;
|
||||
using TFlushFn = function<void(TUserMarksRenderData && renderData)>;
|
||||
|
||||
UserMarkGenerator(TFlushFn const & flushFn);
|
||||
|
||||
|
|
|
@ -81,24 +81,15 @@ struct UserPointVertex : gpu::BaseVertex
|
|||
|
||||
void CacheUserMarks(TileKey const & tileKey, ref_ptr<dp::TextureManager> textures,
|
||||
UserMarksRenderCollection const & renderParams, MarkIndexesCollection const & indexes,
|
||||
TUserMarksRenderData & renderData)
|
||||
dp::Batcher & batcher)
|
||||
{
|
||||
using UPV = UserPointVertex;
|
||||
|
||||
uint32_t const vertexCount = static_cast<uint32_t>(indexes.size()) * dp::Batcher::VertexPerQuad;
|
||||
uint32_t const indicesCount = static_cast<uint32_t>(indexes.size()) * dp::Batcher::IndexPerQuad;
|
||||
buffer_vector<UPV, 128> buffer;
|
||||
buffer.reserve(vertexCount);
|
||||
|
||||
// TODO: Sort once on render params receiving.
|
||||
MarkIndexesCollection sortedIndexes = indexes;
|
||||
sort(sortedIndexes.begin(), sortedIndexes.end(), [&renderParams](uint32_t ind1, uint32_t ind2)
|
||||
{
|
||||
return renderParams[ind1].m_pivot.y > renderParams[ind2].m_pivot.y;
|
||||
});
|
||||
|
||||
dp::TextureManager::SymbolRegion region;
|
||||
for (auto const markIndex : sortedIndexes)
|
||||
for (auto const markIndex : indexes)
|
||||
{
|
||||
UserMarkRenderParams const & renderInfo = renderParams[markIndex];
|
||||
if (!renderInfo.m_isVisible)
|
||||
|
@ -129,14 +120,6 @@ void CacheUserMarks(TileKey const & tileKey, ref_ptr<dp::TextureManager> texture
|
|||
state.SetColorTexture(region.GetTexture());
|
||||
state.SetTextureFilter(gl_const::GLNearest);
|
||||
|
||||
uint32_t const kMaxSize = 65000;
|
||||
dp::Batcher batcher(min(indicesCount, kMaxSize), min(vertexCount, kMaxSize));
|
||||
dp::SessionGuard guard(batcher, [&tileKey, &renderData](dp::GLState const & state,
|
||||
drape_ptr<dp::RenderBucket> && b)
|
||||
{
|
||||
renderData.emplace_back(UserMarkRenderData(state, move(b), tileKey));
|
||||
});
|
||||
|
||||
dp::AttributeProvider attribProvider(1, static_cast<uint32_t>(buffer.size()));
|
||||
attribProvider.InitStream(0, UPV::GetBinding(), make_ref(buffer.data()));
|
||||
|
||||
|
@ -145,20 +128,12 @@ void CacheUserMarks(TileKey const & tileKey, ref_ptr<dp::TextureManager> texture
|
|||
|
||||
void CacheUserLines(TileKey const & tileKey, ref_ptr<dp::TextureManager> textures,
|
||||
UserLinesRenderCollection const & renderParams, LineIndexesCollection const & indexes,
|
||||
TUserMarksRenderData & renderData)
|
||||
dp::Batcher & batcher)
|
||||
{
|
||||
uint32_t const kBatchSize = 5000;
|
||||
for (auto lineIndex : indexes)
|
||||
{
|
||||
UserLineRenderParams const & renderInfo = renderParams[lineIndex];
|
||||
|
||||
dp::Batcher batcher(kBatchSize, kBatchSize);
|
||||
dp::SessionGuard guard(batcher, [&tileKey, &renderData](dp::GLState const & state,
|
||||
drape_ptr<dp::RenderBucket> && b)
|
||||
{
|
||||
renderData.emplace_back(UserMarkRenderData(state, move(b), tileKey));
|
||||
});
|
||||
|
||||
std::vector<m2::SharedSpline> const splines = m2::ClipSplineByRect(tileKey.GetGlobalRect(), renderInfo.m_spline);
|
||||
for (auto const & spline : splines)
|
||||
{
|
||||
|
|
|
@ -2,8 +2,7 @@
|
|||
|
||||
#include "tile_key.hpp"
|
||||
|
||||
#include "drape/glstate.hpp"
|
||||
#include "drape/render_bucket.hpp"
|
||||
#include "drape/batcher.hpp"
|
||||
#include "drape/texture_manager.hpp"
|
||||
|
||||
#include "geometry/spline.hpp"
|
||||
|
@ -69,10 +68,10 @@ using TUserMarksRenderData = std::vector<UserMarkRenderData>;
|
|||
|
||||
void CacheUserMarks(TileKey const & tileKey, ref_ptr<dp::TextureManager> textures,
|
||||
UserMarksRenderCollection const & renderParams, MarkIndexesCollection const & indexes,
|
||||
TUserMarksRenderData & renderData);
|
||||
dp::Batcher & batcher);
|
||||
|
||||
void CacheUserLines(TileKey const & tileKey, ref_ptr<dp::TextureManager> textures,
|
||||
UserLinesRenderCollection const & renderParams, LineIndexesCollection const & indexes,
|
||||
TUserMarksRenderData & renderData);
|
||||
dp::Batcher & batcher);
|
||||
|
||||
} // namespace df
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
BookmarkManager::BookmarkManager(Framework & f)
|
||||
: m_framework(f)
|
||||
{
|
||||
m_userMarkLayers.reserve(3);
|
||||
m_userMarkLayers.reserve(4);
|
||||
m_userMarkLayers.push_back(new SearchUserMarkContainer(0.0 /* activePinDepth */, m_framework));
|
||||
m_userMarkLayers.push_back(new ApiUserMarkContainer(0.0 /* activePinDepth */, m_framework));
|
||||
m_userMarkLayers.push_back(new DebugUserMarkContainer(0.0 /* debugDepth */, m_framework));
|
||||
|
|
Loading…
Add table
Reference in a new issue