Fixed transit scheme regeneration on Android.

New lines caps.
This commit is contained in:
Daria Volvenkova 2018-07-03 13:11:02 +03:00 committed by Roman Kuznetsov
parent 5f81e61459
commit a77d984bde
9 changed files with 111 additions and 135 deletions

View file

@ -32,10 +32,7 @@ BackendRenderer::BackendRenderer(Params && params)
, m_readManager(make_unique_dp<ReadManager>(params.m_commutator, m_model,
params.m_allow3dBuildings, params.m_trafficEnabled,
std::move(params.m_isUGCFn)))
, m_transitBuilder(make_unique_dp<TransitSchemeBuilder>(bind(&BackendRenderer::FlushTransitRenderData, this, _1),
bind(&BackendRenderer::FlushTransitMarkersRenderData, this, _1),
bind(&BackendRenderer::FlushTransitTextRenderData, this, _1),
bind(&BackendRenderer::FlushTransitStubsRenderData, this, _1)))
, m_transitBuilder(make_unique_dp<TransitSchemeBuilder>(bind(&BackendRenderer::FlushTransitRenderData, this, _1)))
, m_trafficGenerator(make_unique_dp<TrafficGenerator>(bind(&BackendRenderer::FlushTrafficRenderData, this, _1)))
, m_userMarkGenerator(make_unique_dp<UserMarkGenerator>(bind(&BackendRenderer::FlushUserMarksRenderData, this, _1)))
, m_requestedTiles(params.m_requestedTiles)
@ -339,7 +336,7 @@ void BackendRenderer::AcceptMessage(ref_ptr<Message> message)
m_texMng->OnSwitchMapStyle();
RecacheMapShapes();
m_trafficGenerator->InvalidateTexturesCache();
m_transitBuilder->BuildScheme(m_texMng);
m_transitBuilder->RebuildSchemes(m_texMng);
break;
}
@ -440,14 +437,13 @@ void BackendRenderer::AcceptMessage(ref_ptr<Message> message)
{
ref_ptr<UpdateTransitSchemeMessage> msg = message;
m_transitBuilder->SetVisibleMwms(msg->GetVisibleMwms());
m_transitBuilder->UpdateScheme(msg->GetTransitDisplayInfos());
m_transitBuilder->BuildScheme(m_texMng);
m_transitBuilder->UpdateSchemes(msg->GetTransitDisplayInfos(), m_texMng);
break;
}
case Message::RegenerateTransitScheme:
{
m_transitBuilder->BuildScheme(m_texMng);
m_transitBuilder->RebuildSchemes(m_texMng);
break;
}
@ -672,27 +668,6 @@ void BackendRenderer::FlushTransitRenderData(TransitRenderData && renderData)
MessagePriority::Normal);
}
void BackendRenderer::FlushTransitMarkersRenderData(TransitRenderData && renderData)
{
m_commutator->PostMessage(ThreadsCommutator::RenderThread,
make_unique_dp<FlushTransitMarkersMessage>(std::move(renderData)),
MessagePriority::Normal);
}
void BackendRenderer::FlushTransitTextRenderData(TransitRenderData && renderData)
{
m_commutator->PostMessage(ThreadsCommutator::RenderThread,
make_unique_dp<FlushTransitTextMessage>(std::move(renderData)),
MessagePriority::Normal);
}
void BackendRenderer::FlushTransitStubsRenderData(TransitRenderData && renderData)
{
m_commutator->PostMessage(ThreadsCommutator::RenderThread,
make_unique_dp<FlushTransitStubsMessage>(std::move(renderData)),
MessagePriority::Normal);
}
void BackendRenderer::FlushTrafficRenderData(TrafficRenderData && renderData)
{
m_commutator->PostMessage(ThreadsCommutator::RenderThread,

View file

@ -101,10 +101,6 @@ private:
void FlushGeometry(TileKey const & key, dp::GLState const & state, drape_ptr<dp::RenderBucket> && buffer);
void FlushTransitRenderData(TransitRenderData && renderData);
void FlushTransitMarkersRenderData(TransitRenderData && renderData);
void FlushTransitTextRenderData(TransitRenderData && renderData);
void FlushTransitStubsRenderData(TransitRenderData && renderData);
void FlushTrafficRenderData(TrafficRenderData && renderData);
void FlushUserMarksRenderData(TUserMarksRenderData && renderData);

View file

@ -471,33 +471,6 @@ void FrontendRenderer::AcceptMessage(ref_ptr<Message> message)
break;
}
case Message::FlushTransitMarkers:
{
ref_ptr<FlushTransitMarkersMessage > msg = message;
auto renderData = msg->AcceptRenderData();
m_transitSchemeRenderer->AddMarkersRenderData(make_ref(m_gpuProgramManager), make_ref(m_overlayTree),
std::move(renderData));
break;
}
case Message::FlushTransitText:
{
ref_ptr<FlushTransitTextMessage > msg = message;
auto renderData = msg->AcceptRenderData();
m_transitSchemeRenderer->AddTextRenderData(make_ref(m_gpuProgramManager), make_ref(m_overlayTree),
std::move(renderData));
break;
}
case Message::FlushTransitStubs:
{
ref_ptr<FlushTransitTextMessage > msg = message;
auto renderData = msg->AcceptRenderData();
m_transitSchemeRenderer->AddStubsRenderData(make_ref(m_gpuProgramManager), make_ref(m_overlayTree),
std::move(renderData));
break;
}
case Message::FlushSubrouteArrows:
{
ref_ptr<FlushSubrouteArrowsMessage> msg = message;

View file

@ -1077,15 +1077,6 @@ public:
using FlushTransitSchemeMessage = FlushRenderDataMessage<TransitRenderData,
Message::FlushTransitScheme>;
using FlushTransitMarkersMessage = FlushRenderDataMessage<TransitRenderData,
Message::FlushTransitMarkers>;
using FlushTransitTextMessage = FlushRenderDataMessage<TransitRenderData,
Message::FlushTransitText>;
using FlushTransitStubsMessage = FlushRenderDataMessage<TransitRenderData,
Message::FlushTransitStubs>;
class DrapeApiAddLinesMessage : public Message
{
public:

View file

@ -50,7 +50,7 @@ std::string const kTransitTransferOuterColor = "TransitTransferOuterMarker";
std::string const kTransitTransferInnerColor = "TransitTransferInnerMarker";
std::string const kTransitStopInnerColor = "TransitStopInnerMarker";
float const kTransitMarkTextSize = 12.0f;
float const kTransitMarkTextSize = 11.0f;
struct TransitStaticVertex
{
@ -279,7 +279,8 @@ void TransitSchemeBuilder::SetVisibleMwms(std::vector<MwmSet::MwmId> const & vis
m_visibleMwms = visibleMwms;
}
void TransitSchemeBuilder::UpdateScheme(TransitDisplayInfos const & transitDisplayInfos)
void TransitSchemeBuilder::UpdateSchemes(TransitDisplayInfos const & transitDisplayInfos,
ref_ptr<dp::TextureManager> textures)
{
for (auto const & mwmInfo : transitDisplayInfos)
{
@ -296,6 +297,7 @@ void TransitSchemeBuilder::UpdateScheme(TransitDisplayInfos const & transitDispl
CollectShapes(transitDisplayInfo, scheme);
PrepareScheme(scheme);
BuildScheme(mwmId, textures);
}
}
@ -309,16 +311,19 @@ void TransitSchemeBuilder::Clear(MwmSet::MwmId const & mwmId)
m_schemes.erase(mwmId);
}
void TransitSchemeBuilder::BuildScheme(ref_ptr<dp::TextureManager> textures)
void TransitSchemeBuilder::RebuildSchemes(ref_ptr<dp::TextureManager> textures)
{
for (auto const & mwmScheme : m_schemes)
BuildScheme(mwmScheme.first, textures);
}
void TransitSchemeBuilder::BuildScheme(MwmSet::MwmId const & mwmId, ref_ptr<dp::TextureManager> textures)
{
if (m_schemes.find(mwmId) == m_schemes.end())
return;
++m_recacheId;
for (auto const & mwmId : m_visibleMwms)
{
if (m_schemes.find(mwmId) == m_schemes.end())
continue;
GenerateShapes(mwmId);
GenerateStops(mwmId, textures);
}
GenerateShapes(mwmId);
GenerateStops(mwmId, textures);
}
void TransitSchemeBuilder::CollectStops(TransitDisplayInfo const & transitDisplayInfo,
@ -537,7 +542,10 @@ void TransitSchemeBuilder::GenerateShapes(MwmSet::MwmId const & mwmId)
{
dp::SessionGuard guard(batcher, [this, &mwmId, &scheme](dp::GLState const & state, drape_ptr<dp::RenderBucket> && b)
{
TransitRenderData renderData(state, m_recacheId, mwmId, scheme.m_pivot, std::move(b));
TransitRenderData::Type type = TransitRenderData::Type::Lines;
if (state.GetProgram<gpu::Program>() == gpu::Program::TransitCircle)
type = TransitRenderData::Type::LinesCaps;
TransitRenderData renderData(type, state, m_recacheId, mwmId, scheme.m_pivot, std::move(b));
m_flushRenderDataFn(std::move(renderData));
});
@ -581,13 +589,14 @@ void TransitSchemeBuilder::GenerateStops(MwmSet::MwmId const & mwmId, ref_ptr<dp
auto const flusher = [this, &mwmId, &scheme](dp::GLState const & state, drape_ptr<dp::RenderBucket> && b)
{
TransitRenderData renderData(state, m_recacheId, mwmId, scheme.m_pivot, std::move(b));
TransitRenderData::Type type = TransitRenderData::Type::Stubs;
if (state.GetProgram<gpu::Program>() == gpu::Program::TransitMarker)
m_flushMarkersRenderDataFn(std::move(renderData));
type = TransitRenderData::Type::Markers;
else if (state.GetProgram<gpu::Program>() == gpu::Program::TextOutlined)
m_flushTextRenderDataFn(std::move(renderData));
else
m_flushStubsRenderDataFn(std::move(renderData));
type = TransitRenderData::Type::Text;
TransitRenderData renderData(type, state, m_recacheId, mwmId, scheme.m_pivot, std::move(b));
m_flushRenderDataFn(std::move(renderData));
};
uint32_t const kBatchSize = 5000;

View file

@ -21,15 +21,26 @@ extern std::vector<float> const kTransitLinesWidthInPixel;
struct TransitRenderData
{
enum class Type
{
LinesCaps,
Lines,
Markers,
Text,
Stubs
};
Type m_type;
dp::GLState m_state;
uint32_t m_recacheId;
MwmSet::MwmId m_mwmId;
m2::PointD m_pivot;
drape_ptr<dp::RenderBucket> m_bucket;
TransitRenderData(dp::GLState const & state, uint32_t recacheId, MwmSet::MwmId const & mwmId, m2::PointD const pivot,
drape_ptr<dp::RenderBucket> && bucket)
: m_state(state)
TransitRenderData(Type type, dp::GLState const & state, uint32_t recacheId, MwmSet::MwmId const & mwmId,
m2::PointD const pivot, drape_ptr<dp::RenderBucket> && bucket)
: m_type(type)
, m_state(state)
, m_recacheId(recacheId)
, m_mwmId(mwmId)
, m_pivot(pivot)
@ -96,20 +107,14 @@ public:
using TFlushRenderDataFn = function<void (TransitRenderData && renderData)>;
TransitSchemeBuilder(TFlushRenderDataFn const & flushFn,
TFlushRenderDataFn const & flushMarkersFn,
TFlushRenderDataFn const & flushTextFn,
TFlushRenderDataFn const & flushStubsFn)
TransitSchemeBuilder(TFlushRenderDataFn const & flushFn)
: m_flushRenderDataFn(flushFn)
, m_flushMarkersRenderDataFn(flushMarkersFn)
, m_flushTextRenderDataFn(flushTextFn)
, m_flushStubsRenderDataFn(flushStubsFn)
{}
void SetVisibleMwms(std::vector<MwmSet::MwmId> const & visibleMwms);
void UpdateScheme(TransitDisplayInfos const & transitDisplayInfos);
void BuildScheme(ref_ptr<dp::TextureManager> textures);
void UpdateSchemes(TransitDisplayInfos const & transitDisplayInfos, ref_ptr<dp::TextureManager> textures);
void RebuildSchemes(ref_ptr<dp::TextureManager> textures);
void Clear();
void Clear(MwmSet::MwmId const & mwmId);
@ -125,6 +130,8 @@ private:
std::map<routing::transit::TransferId, StopNodeParams> m_transfers;
};
void BuildScheme(MwmSet::MwmId const & mwmId, ref_ptr<dp::TextureManager> textures);
void CollectStops(TransitDisplayInfo const & transitDisplayInfo,
MwmSet::MwmId const & mwmId, MwmSchemeData & scheme);
@ -162,9 +169,6 @@ private:
std::vector<MwmSet::MwmId> m_visibleMwms;
TFlushRenderDataFn m_flushRenderDataFn;
TFlushRenderDataFn m_flushMarkersRenderDataFn;
TFlushRenderDataFn m_flushTextRenderDataFn;
TFlushRenderDataFn m_flushStubsRenderDataFn;
uint32_t m_recacheId = 0;
};

View file

@ -29,7 +29,7 @@ float CalculateHalfWidth(ScreenBase const & screen)
bool TransitSchemeRenderer::HasRenderData(int zoomLevel) const
{
return !m_renderData.empty() && zoomLevel >= kTransitSchemeMinZoomLevel;
return !m_linesRenderData.empty() && zoomLevel >= kTransitSchemeMinZoomLevel;
}
void TransitSchemeRenderer::ClearGLDependentResources(ref_ptr<dp::OverlayTree> tree)
@ -40,7 +40,8 @@ void TransitSchemeRenderer::ClearGLDependentResources(ref_ptr<dp::OverlayTree> t
RemoveOverlays(tree, m_colorSymbolRenderData);
}
m_renderData.clear();
m_linesRenderData.clear();
m_linesCapsRenderData.clear();
m_markersRenderData.clear();
m_textRenderData.clear();
m_colorSymbolRenderData.clear();
@ -48,7 +49,8 @@ void TransitSchemeRenderer::ClearGLDependentResources(ref_ptr<dp::OverlayTree> t
void TransitSchemeRenderer::Clear(MwmSet::MwmId const & mwmId, ref_ptr<dp::OverlayTree> tree)
{
ClearRenderData(mwmId, nullptr /* tree */, m_renderData);
ClearRenderData(mwmId, nullptr /* tree */, m_linesRenderData);
ClearRenderData(mwmId, nullptr /* tree */, m_linesCapsRenderData);
ClearRenderData(mwmId, nullptr /* tree */, m_markersRenderData);
ClearRenderData(mwmId, tree, m_textRenderData);
ClearRenderData(mwmId, tree, m_colorSymbolRenderData);
@ -80,25 +82,24 @@ void TransitSchemeRenderer::ClearRenderData(TRemovePredicate const & predicate,
void TransitSchemeRenderer::AddRenderData(ref_ptr<gpu::ProgramManager> mng, ref_ptr<dp::OverlayTree> tree,
TransitRenderData && renderData)
{
PrepareRenderData(mng, tree, m_renderData, std::move(renderData));
}
void TransitSchemeRenderer::AddMarkersRenderData(ref_ptr<gpu::ProgramManager> mng, ref_ptr<dp::OverlayTree> tree,
TransitRenderData && renderData)
{
PrepareRenderData(mng, tree, m_markersRenderData, std::move(renderData));
}
void TransitSchemeRenderer::AddTextRenderData(ref_ptr<gpu::ProgramManager> mng, ref_ptr<dp::OverlayTree> tree,
TransitRenderData && renderData)
{
PrepareRenderData(mng, tree, m_textRenderData, std::move(renderData));
}
void TransitSchemeRenderer::AddStubsRenderData(ref_ptr<gpu::ProgramManager> mng, ref_ptr<dp::OverlayTree> tree,
TransitRenderData && renderData)
{
PrepareRenderData(mng, tree, m_colorSymbolRenderData, std::move(renderData));
switch (renderData.m_type)
{
case TransitRenderData::Type::LinesCaps:
PrepareRenderData(mng, tree, m_linesCapsRenderData, std::move(renderData));
break;
case TransitRenderData::Type::Lines:
PrepareRenderData(mng, tree, m_linesRenderData, std::move(renderData));
break;
case TransitRenderData::Type::Markers:
PrepareRenderData(mng, tree, m_markersRenderData, std::move(renderData));
break;
case TransitRenderData::Type::Text:
PrepareRenderData(mng, tree, m_textRenderData, std::move(renderData));
break;
case TransitRenderData::Type::Stubs:
PrepareRenderData(mng, tree, m_colorSymbolRenderData, std::move(renderData));
break;
}
}
void TransitSchemeRenderer::PrepareRenderData(ref_ptr<gpu::ProgramManager> mng, ref_ptr<dp::OverlayTree> tree,
@ -132,6 +133,7 @@ void TransitSchemeRenderer::RenderTransit(ScreenBase const & screen, int zoomLev
float const pixelHalfWidth = CalculateHalfWidth(screen);
RenderLinesCaps(screen, mng, commonUniforms, pixelHalfWidth);
RenderLines(screen, mng, commonUniforms, pixelHalfWidth);
RenderMarkers(screen, mng, commonUniforms, pixelHalfWidth);
{
@ -165,11 +167,12 @@ void TransitSchemeRenderer::RemoveOverlays(ref_ptr<dp::OverlayTree> tree, std::v
data.m_bucket->RemoveOverlayHandles(tree);
}
void TransitSchemeRenderer::RenderLines(ScreenBase const & screen, ref_ptr<gpu::ProgramManager> mng,
dp::UniformValuesStorage const & commonUniforms, float pixelHalfWidth)
void TransitSchemeRenderer::RenderLinesCaps(ScreenBase const & screen, ref_ptr<gpu::ProgramManager> mng,
dp::UniformValuesStorage const & commonUniforms, float pixelHalfWidth)
{
GLFunctions::glDisable(gl_const::GLDepthTest);
for (auto & renderData : m_renderData)
GLFunctions::glEnable(gl_const::GLDepthTest);
GLFunctions::glClear(gl_const::GLDepthBit);
for (auto & renderData : m_linesCapsRenderData)
{
ref_ptr<dp::GpuProgram> program = mng->GetProgram(renderData.m_state.GetProgram<gpu::Program>());
program->Bind();
@ -187,10 +190,32 @@ void TransitSchemeRenderer::RenderLines(ScreenBase const & screen, ref_ptr<gpu::
}
}
void TransitSchemeRenderer::RenderLines(ScreenBase const & screen, ref_ptr<gpu::ProgramManager> mng,
dp::UniformValuesStorage const & commonUniforms, float pixelHalfWidth)
{
GLFunctions::glEnable(gl_const::GLDepthTest);
for (auto & renderData : m_linesRenderData)
{
ref_ptr<dp::GpuProgram> program = mng->GetProgram(renderData.m_state.GetProgram<gpu::Program>());
program->Bind();
dp::ApplyState(renderData.m_state, program);
dp::UniformValuesStorage uniforms = commonUniforms;
math::Matrix<float, 4, 4> mv = screen.GetModelView(renderData.m_pivot, kShapeCoordScalar);
uniforms.SetMatrix4x4Value("u_modelView", mv.m_data);
uniforms.SetFloatValue("u_lineHalfWidth", pixelHalfWidth);
dp::ApplyUniforms(uniforms, program);
renderData.m_bucket->Render(false /* draw as line */);
}
}
void TransitSchemeRenderer::RenderMarkers(ScreenBase const & screen, ref_ptr<gpu::ProgramManager> mng,
dp::UniformValuesStorage const & commonUniforms, float pixelHalfWidth)
{
GLFunctions::glEnable(gl_const::GLDepthTest);
GLFunctions::glClear(gl_const::GLDepthBit);
for (auto & renderData : m_markersRenderData)
{
auto program = mng->GetProgram(renderData.m_state.GetProgram<gpu::Program>());
@ -213,6 +238,7 @@ void TransitSchemeRenderer::RenderMarkers(ScreenBase const & screen, ref_ptr<gpu
void TransitSchemeRenderer::RenderText(ScreenBase const & screen, ref_ptr<gpu::ProgramManager> mng,
dp::UniformValuesStorage const & commonUniforms)
{
GLFunctions::glDisable(gl_const::GLDepthTest);
auto const & params = df::VisualParams::Instance().GetGlyphVisualParams();
for (auto & renderData : m_textRenderData)
{

View file

@ -19,14 +19,7 @@ class OverlayTree;
class TransitSchemeRenderer
{
public:
void AddRenderData(ref_ptr<gpu::ProgramManager> mng, ref_ptr<dp::OverlayTree> tree,
TransitRenderData && renderData);
void AddMarkersRenderData(ref_ptr<gpu::ProgramManager> mng, ref_ptr<dp::OverlayTree> tree,
TransitRenderData && renderData);
void AddTextRenderData(ref_ptr<gpu::ProgramManager> mng, ref_ptr<dp::OverlayTree> tree,
TransitRenderData && renderData);
void AddStubsRenderData(ref_ptr<gpu::ProgramManager> mng, ref_ptr<dp::OverlayTree> tree,
TransitRenderData && renderData);
void AddRenderData(ref_ptr<gpu::ProgramManager> mng, ref_ptr<dp::OverlayTree> tree, TransitRenderData && renderData);
bool HasRenderData(int zoomLevel) const;
@ -59,6 +52,8 @@ private:
void RenderLines(ScreenBase const & screen, ref_ptr<gpu::ProgramManager> mng,
dp::UniformValuesStorage const & commonUniforms, float pixelHalfWidth);
void RenderLinesCaps(ScreenBase const & screen, ref_ptr<gpu::ProgramManager> mng,
dp::UniformValuesStorage const & commonUniforms, float pixelHalfWidth);
void RenderMarkers(ScreenBase const & screen, ref_ptr<gpu::ProgramManager> mng,
dp::UniformValuesStorage const & commonUniforms, float pixelHalfWidth);
void RenderText(ScreenBase const & screen, ref_ptr<gpu::ProgramManager> mng,
@ -67,7 +62,8 @@ private:
dp::UniformValuesStorage const & commonUniforms);
uint32_t m_lastRecacheId = 0;
std::vector<TransitRenderData> m_renderData;
std::vector<TransitRenderData> m_linesRenderData;
std::vector<TransitRenderData> m_linesCapsRenderData;
std::vector<TransitRenderData> m_markersRenderData;
std::vector<TransitRenderData> m_textRenderData;
std::vector<TransitRenderData> m_colorSymbolRenderData;

View file

@ -1,3 +1,7 @@
// Warning! Beware to use this shader. "discard" command may significally reduce performance.
// Unfortunately some CG algorithms cannot be implemented on OpenGL ES 2.0 without discarding
// fragments from depth buffer.
varying vec3 v_radius;
varying vec4 v_color;
@ -15,5 +19,7 @@ void main()
float stepValue = smoothstep(smallRadius * smallRadius, v_radius.z * v_radius.z,
dot(v_radius.xy, v_radius.xy));
finalColor.a = finalColor.a * (1.0 - stepValue);
if (finalColor.a < 0.01)
discard;
gl_FragColor = samsungGoogleNexusWorkaround(finalColor);
}