diff options
-rw-r--r-- | drape/glstate.cpp | 16 | ||||
-rw-r--r-- | drape/shaders/route_arrow_fragment_shader.fsh | 10 | ||||
-rw-r--r-- | drape/shaders/route_fragment_shader.fsh | 5 | ||||
-rw-r--r-- | drape/shaders/route_vertex_shader.vsh | 14 | ||||
-rwxr-xr-x | drape_frontend/frontend_renderer.cpp | 29 | ||||
-rw-r--r-- | drape_frontend/navigator.cpp | 10 | ||||
-rw-r--r-- | drape_frontend/render_node.cpp | 2 | ||||
-rw-r--r-- | drape_frontend/route_renderer.cpp | 27 | ||||
-rw-r--r-- | drape_frontend/route_renderer.hpp | 7 | ||||
-rw-r--r-- | drape_frontend/user_event_stream.cpp | 7 | ||||
-rw-r--r-- | drape_frontend/user_event_stream.hpp | 2 | ||||
-rw-r--r-- | drape_frontend/visual_params.cpp | 12 | ||||
-rw-r--r-- | drape_frontend/visual_params.hpp | 4 | ||||
-rw-r--r-- | drape_head/testing_engine.cpp | 4 |
14 files changed, 101 insertions, 48 deletions
diff --git a/drape/glstate.cpp b/drape/glstate.cpp index 0b0986da94..b1478dcb07 100644 --- a/drape/glstate.cpp +++ b/drape/glstate.cpp @@ -109,6 +109,14 @@ void ApplyTextures(GLState state, ref_ptr<GpuProgram> program) tex->Bind(); GLFunctions::glUniformValuei(colorTexLoc, 0); } + else + { + // Some Android devices (Galaxy Nexus) require to reset texture state explicitly. +#ifdef OMIM_OS_ANDROID + GLFunctions::glActiveTexture(gl_const::GLTexture0); + GLFunctions::glBindTexture(0); +#endif + } tex = state.GetMaskTexture(); if (tex != nullptr) @@ -118,6 +126,14 @@ void ApplyTextures(GLState state, ref_ptr<GpuProgram> program) tex->Bind(); GLFunctions::glUniformValuei(maskTexLoc, 1); } + else + { + // Some Android devices (Galaxy Nexus) require to reset texture state explicitly. +#ifdef OMIM_OS_ANDROID + GLFunctions::glActiveTexture(gl_const::GLTexture0 + 1); + GLFunctions::glBindTexture(0); +#endif + } } void ApplyBlending(GLState state, ref_ptr<GpuProgram> program) diff --git a/drape/shaders/route_arrow_fragment_shader.fsh b/drape/shaders/route_arrow_fragment_shader.fsh index 7c72a36cee..e08c95dabe 100644 --- a/drape/shaders/route_arrow_fragment_shader.fsh +++ b/drape/shaders/route_arrow_fragment_shader.fsh @@ -1,4 +1,4 @@ -varying vec2 v_length; +varying vec3 v_length; uniform sampler2D u_colorTex; uniform vec4 u_textureRect; @@ -21,10 +21,10 @@ vec2 calculateUv(vec2 len, vec4 arrowBorder) void main(void) { vec4 arrowBorder = u_arrowBorders[0]; - vec2 uv = calculateUv(v_length, u_arrowBorders[0]) + - calculateUv(v_length, u_arrowBorders[1]) + - calculateUv(v_length, u_arrowBorders[2]) + - calculateUv(v_length, u_arrowBorders[3]); + vec2 uv = calculateUv(v_length.xy, u_arrowBorders[0]) + + calculateUv(v_length.xy, u_arrowBorders[1]) + + calculateUv(v_length.xy, u_arrowBorders[2]) + + calculateUv(v_length.xy, u_arrowBorders[3]); vec4 color = texture2D(u_colorTex, uv); gl_FragColor = color; diff --git a/drape/shaders/route_fragment_shader.fsh b/drape/shaders/route_fragment_shader.fsh index 3d32091413..55f7232ff7 100644 --- a/drape/shaders/route_fragment_shader.fsh +++ b/drape/shaders/route_fragment_shader.fsh @@ -1,12 +1,11 @@ -varying vec2 v_length; +varying vec3 v_length; uniform vec4 u_color; -uniform float u_clipLength; void main(void) { vec4 color = u_color; - if (v_length.x < u_clipLength) + if (v_length.x < v_length.z) color.a = 0.0; gl_FragColor = color; diff --git a/drape/shaders/route_vertex_shader.vsh b/drape/shaders/route_vertex_shader.vsh index edd261bf47..0097ab1974 100644 --- a/drape/shaders/route_vertex_shader.vsh +++ b/drape/shaders/route_vertex_shader.vsh @@ -5,28 +5,28 @@ attribute vec3 a_length; uniform mat4 modelView; uniform mat4 projection; -uniform vec2 u_halfWidth; +uniform vec3 u_routeParams; -varying vec2 v_length; +varying vec3 v_length; void main(void) { float normalLen = length(a_normal); vec2 transformedAxisPos = (vec4(a_position.xy, 0.0, 1.0) * modelView).xy; vec2 len = vec2(a_length.x, a_length.z); - if (u_halfWidth.x != 0.0 && normalLen != 0.0) + if (u_routeParams.x != 0.0 && normalLen != 0.0) { - vec2 norm = a_normal * u_halfWidth.x; + vec2 norm = a_normal * u_routeParams.x; float actualHalfWidth = length(norm); vec4 glbShiftPos = vec4(a_position.xy + norm, 0.0, 1.0); vec2 shiftPos = (glbShiftPos * modelView).xy; transformedAxisPos = transformedAxisPos + normalize(shiftPos - transformedAxisPos) * actualHalfWidth; - if (u_halfWidth.y != 0.0) - len = vec2(a_length.x + a_length.y * u_halfWidth.y, a_length.z); + if (u_routeParams.y != 0.0) + len = vec2(a_length.x + a_length.y * u_routeParams.y, a_length.z); } - v_length = len; + v_length = vec3(len, u_routeParams.z); gl_Position = vec4(transformedAxisPos, a_position.z, 1.0) * projection; } diff --git a/drape_frontend/frontend_renderer.cpp b/drape_frontend/frontend_renderer.cpp index 13efe7e6cd..039048cbca 100755 --- a/drape_frontend/frontend_renderer.cpp +++ b/drape_frontend/frontend_renderer.cpp @@ -467,7 +467,7 @@ FeatureID FrontendRenderer::GetVisiblePOI(m2::RectD const & pixelRect) const ScreenBase const & screen = m_userEventStream.GetCurrentScreen(); for (ref_ptr<dp::OverlayHandle> handle : selectResult) { - double const curDist = pt.SquareLength(handle->GetPivot(screen)); + double const curDist = pt.SquareLength(handle->GetPivot(screen)); if (curDist < dist) { dist = curDist; @@ -586,15 +586,17 @@ void FrontendRenderer::RenderScene(ScreenBase const & modelView) GLFunctions::glDisable(gl_const::GLDepthTest); + m_routeRenderer->RenderRoute(modelView, make_ref(m_gpuProgramManager), m_generalUniforms); + for (drape_ptr<UserMarkRenderGroup> const & group : m_userMarkRenderGroups) { ASSERT(group.get() != nullptr, ()); - group->UpdateAnimation(); if (m_userMarkVisibility.find(group->GetTileKey()) != m_userMarkVisibility.end()) RenderSingleGroup(modelView, make_ref(group)); } - m_routeRenderer->Render(modelView, make_ref(m_gpuProgramManager), m_generalUniforms); + m_routeRenderer->RenderRouteSigns(modelView, make_ref(m_gpuProgramManager), m_generalUniforms); + m_myPositionController->Render(MyPositionController::RenderMyPosition, modelView, make_ref(m_gpuProgramManager), m_generalUniforms); @@ -611,13 +613,14 @@ void FrontendRenderer::RenderScene(ScreenBase const & modelView) void FrontendRenderer::RenderSingleGroup(ScreenBase const & modelView, ref_ptr<BaseRenderGroup> group) { group->UpdateAnimation(); - dp::GLState const & state = group->GetState(); + dp::GLState const & state = group->GetState(); ref_ptr<dp::GpuProgram> program = m_gpuProgramManager->GetProgram(state.GetProgramIndex()); program->Bind(); + + ApplyState(state, program); ApplyUniforms(m_generalUniforms, program); ApplyUniforms(group->GetUniforms(), program); - ApplyState(state, program); group->Render(modelView); } @@ -813,6 +816,8 @@ void FrontendRenderer::Routine::Do() dp::BlendingParams blendingParams; blendingParams.Apply(); + int const kMaxInactiveFrames = 60; + my::HighResTimer timer; timer.Reset(); double frameTime = 0.0; @@ -823,19 +828,27 @@ void FrontendRenderer::Routine::Do() while (!IsCancelled()) { context->setDefaultFramebuffer(); + bool const hasAsyncRoutines = m_renderer.m_texMng->UpdateDynamicTextures(); m_renderer.RenderScene(modelView); + bool const animActive = InterpolationHolder::Instance().Advance(frameTime); modelView = m_renderer.UpdateScene(viewChanged); - if (!viewChanged && m_renderer.IsQueueEmpty() && !animActive && !hasAsyncRoutines) + bool const waitCompletion = m_renderer.m_userEventStream.IsWaitingForActionCompletion(); + + // Check for a frame is inactive. + bool const isInactiveFrame = !viewChanged && m_renderer.IsQueueEmpty() && + !animActive && !hasAsyncRoutines && + !waitCompletion; + if (isInactiveFrame) ++inactiveFrameCount; else inactiveFrameCount = 0; - if (inactiveFrameCount > 60) + if (inactiveFrameCount > kMaxInactiveFrames) { - // process a message or wait for a message + // Process a message or wait for a message. m_renderer.ProcessSingleMessage(); inactiveFrameCount = 0; } diff --git a/drape_frontend/navigator.cpp b/drape_frontend/navigator.cpp index 59cf0c9da8..d4ee02f7b9 100644 --- a/drape_frontend/navigator.cpp +++ b/drape_frontend/navigator.cpp @@ -449,7 +449,11 @@ bool Navigator::ScaleImpl(m2::PointD const & newPt1, m2::PointD const & newPt2, void Navigator::DoScale(m2::PointD const & pt1, m2::PointD const & pt2) { - if (m_LastPt1 == pt1 && m_LastPt2 == pt2) + double const threshold = df::VisualParams::Instance().GetScaleThreshold(); + double const deltaPt1 = (pt1 - m_LastPt1).Length(); + double const deltaPt2 = (pt2 - m_LastPt2).Length(); + + if (deltaPt1 < threshold && deltaPt2 < threshold) return; if (pt1 == pt2) return; @@ -500,10 +504,6 @@ void Navigator::DoScale(m2::PointD const & pt1, m2::PointD const & pt2) void Navigator::StopScale(m2::PointD const & pt1, m2::PointD const & pt2) { DoScale(pt1, pt2); - - ASSERT_EQUAL(m_LastPt1, pt1, ()); - ASSERT_EQUAL(m_LastPt2, pt2, ()); - m_InAction = false; } diff --git a/drape_frontend/render_node.cpp b/drape_frontend/render_node.cpp index f94c14509f..ffc907d963 100644 --- a/drape_frontend/render_node.cpp +++ b/drape_frontend/render_node.cpp @@ -36,8 +36,8 @@ void RenderNode::Apply(ref_ptr<dp::GpuProgramManager> mng, dp::UniformValuesStor m_isBuilded = true; } - dp::ApplyUniforms(uniforms, prg); dp::ApplyState(m_state, prg); + dp::ApplyUniforms(uniforms, prg); } } diff --git a/drape_frontend/route_renderer.cpp b/drape_frontend/route_renderer.cpp index b2b0f4602e..480ec2f2ec 100644 --- a/drape_frontend/route_renderer.cpp +++ b/drape_frontend/route_renderer.cpp @@ -161,8 +161,8 @@ void RouteRenderer::InterpolateByZoom(ScreenBase const & screen, float & halfWid } } -void RouteRenderer::Render(ScreenBase const & screen, ref_ptr<dp::GpuProgramManager> mng, - dp::UniformValuesStorage const & commonUniforms) +void RouteRenderer::RenderRoute(ScreenBase const & screen, ref_ptr<dp::GpuProgramManager> mng, + dp::UniformValuesStorage const & commonUniforms) { if (!m_routeData) return; @@ -178,18 +178,16 @@ void RouteRenderer::Render(ScreenBase const & screen, ref_ptr<dp::GpuProgramMana dp::GLState const & state = m_routeData->m_route.m_state; // set up uniforms - dp::UniformValuesStorage uniformStorage; + dp::UniformValuesStorage uniforms = commonUniforms; glsl::vec4 color = glsl::ToVec4(m_routeData->m_color); - uniformStorage.SetFloatValue("u_color", color.r, color.g, color.b, alpha); - uniformStorage.SetFloatValue("u_halfWidth", halfWidth, halfWidth * screen.GetScale()); - uniformStorage.SetFloatValue("u_clipLength", m_distanceFromBegin); + uniforms.SetFloatValue("u_color", color.r, color.g, color.b, alpha); + uniforms.SetFloatValue("u_routeParams", halfWidth, halfWidth * screen.GetScale(), m_distanceFromBegin); // set up shaders and apply uniforms - ref_ptr<dp::GpuProgram> prg = mng->GetProgram(state.GetProgramIndex()); + ref_ptr<dp::GpuProgram> prg = mng->GetProgram(gpu::ROUTE_PROGRAM); prg->Bind(); dp::ApplyBlending(state, prg); - dp::ApplyUniforms(commonUniforms, prg); - dp::ApplyUniforms(uniformStorage, prg); + dp::ApplyUniforms(uniforms, prg); // render routes for (drape_ptr<dp::RenderBucket> const & bucket : m_routeData->m_route.m_buckets) @@ -216,6 +214,13 @@ void RouteRenderer::Render(ScreenBase const & screen, ref_ptr<dp::GpuProgramMana for (drape_ptr<ArrowRenderProperty> & property : m_routeData->m_arrows) RenderArrow(prg, property, halfWidth, screen); } +} + +void RouteRenderer::RenderRouteSigns(ScreenBase const & screen, ref_ptr<dp::GpuProgramManager> mng, + dp::UniformValuesStorage const & commonUniforms) +{ + if (!m_routeData) + return; // render end of route { @@ -223,10 +228,12 @@ void RouteRenderer::Render(ScreenBase const & screen, ref_ptr<dp::GpuProgramMana dp::UniformValuesStorage uniforms = commonUniforms; uniforms.SetFloatValue("u_opacity", 1.0); + ref_ptr<dp::GpuProgram> program = mng->GetProgram(state.GetProgramIndex()); program->Bind(); dp::ApplyState(m_routeData->m_endOfRouteSign.m_state, program); dp::ApplyUniforms(uniforms, program); + for (drape_ptr<dp::RenderBucket> const & bucket : m_routeData->m_endOfRouteSign.m_buckets) bucket->Render(screen); } @@ -240,7 +247,7 @@ void RouteRenderer::RenderArrow(ref_ptr<dp::GpuProgram> prg, drape_ptr<ArrowRend double const textureWidth = 2.0 * arrowHalfWidth * kArrowAspect; dp::UniformValuesStorage uniformStorage; - uniformStorage.SetFloatValue("u_halfWidth", arrowHalfWidth, glbArrowHalfWidth); + uniformStorage.SetFloatValue("u_routeParams", arrowHalfWidth, glbArrowHalfWidth, m_distanceFromBegin); // calculate arrows CalculateArrowBorders(property, kArrowSize, screen.GetScale(), textureWidth, glbArrowHalfWidth); diff --git a/drape_frontend/route_renderer.hpp b/drape_frontend/route_renderer.hpp index dbbbb9ef11..b19de637c2 100644 --- a/drape_frontend/route_renderer.hpp +++ b/drape_frontend/route_renderer.hpp @@ -37,8 +37,11 @@ class RouteRenderer final public: RouteRenderer(); - void Render(ScreenBase const & screen, ref_ptr<dp::GpuProgramManager> mng, - dp::UniformValuesStorage const & commonUniforms); + void RenderRoute(ScreenBase const & screen, ref_ptr<dp::GpuProgramManager> mng, + dp::UniformValuesStorage const & commonUniforms); + + void RenderRouteSigns(ScreenBase const & screen, ref_ptr<dp::GpuProgramManager> mng, + dp::UniformValuesStorage const & commonUniforms); void SetRouteData(drape_ptr<RouteData> && routeData, ref_ptr<dp::GpuProgramManager> mng); diff --git a/drape_frontend/user_event_stream.cpp b/drape_frontend/user_event_stream.cpp index 7875a0c993..a45212a0ba 100644 --- a/drape_frontend/user_event_stream.cpp +++ b/drape_frontend/user_event_stream.cpp @@ -472,7 +472,7 @@ bool UserEventStream::TouchMove(array<Touch, 2> const & touches, double timestam case STATE_TAP_DETECTION: case STATE_WAIT_DOUBLE_TAP: ASSERT_EQUAL(touchCount, 1, ()); - if (m_startDragOrg.SquareLength(touches[0].m_location) > VisualParams::Instance().GetDragThreshold()) + if (m_startDragOrg.Length(touches[0].m_location) > VisualParams::Instance().GetDragThreshold()) CancelTapDetector(); break; case STATE_DRAG: @@ -774,4 +774,9 @@ bool UserEventStream::IsInUserAction() const return m_state == STATE_DRAG || m_state == STATE_SCALE; } +bool UserEventStream::IsWaitingForActionCompletion() const +{ + return m_state == STATE_TAP_DETECTION || m_state == STATE_WAIT_DOUBLE_TAP; +} + } diff --git a/drape_frontend/user_event_stream.hpp b/drape_frontend/user_event_stream.hpp index d31d63e70e..b374bd91b1 100644 --- a/drape_frontend/user_event_stream.hpp +++ b/drape_frontend/user_event_stream.hpp @@ -225,6 +225,8 @@ public: m2::AnyRectD GetTargetRect() const; bool IsInUserAction() const; + bool IsWaitingForActionCompletion() const; + void SetListener(ref_ptr<Listener> listener) { m_listener = listener; } #ifdef DEBUG diff --git a/drape_frontend/visual_params.cpp b/drape_frontend/visual_params.cpp index c6f33d32c3..ff0f540d5c 100644 --- a/drape_frontend/visual_params.cpp +++ b/drape_frontend/visual_params.cpp @@ -114,12 +114,20 @@ uint32_t VisualParams::GetTileSize() const uint32_t VisualParams::GetTouchRectRadius() const { - return 20 * GetVisualScale(); + float const kRadiusInPixels = 20.0f; + return kRadiusInPixels * GetVisualScale(); } double VisualParams::GetDragThreshold() const { - return 10.0 * GetVisualScale(); + double const kDragThresholdInPixels = 10.0; + return kDragThresholdInPixels * GetVisualScale(); +} + +double VisualParams::GetScaleThreshold() const +{ + double const kScaleThresholdInPixels = 2.0; + return kScaleThresholdInPixels * GetVisualScale(); } VisualParams::GlyphVisualParams const & VisualParams::GetGlyphVisualParams() const diff --git a/drape_frontend/visual_params.hpp b/drape_frontend/visual_params.hpp index a7a981ba35..d8059de3a9 100644 --- a/drape_frontend/visual_params.hpp +++ b/drape_frontend/visual_params.hpp @@ -26,9 +26,11 @@ public: double GetVisualScale() const; uint32_t GetTileSize() const; - /// How many pixels around touch point are used to get bookmark or POI in consideration of visual scale + /// How many pixels around touch point are used to get bookmark or POI in consideration of visual scale. uint32_t GetTouchRectRadius() const; + double GetDragThreshold() const; + double GetScaleThreshold() const; struct GlyphVisualParams { diff --git a/drape_head/testing_engine.cpp b/drape_head/testing_engine.cpp index 727f52f41f..3871fa3d00 100644 --- a/drape_head/testing_engine.cpp +++ b/drape_head/testing_engine.cpp @@ -416,9 +416,7 @@ void TestingEngine::DrawImpl() { m_generalUniforms.SetFloatValue("u_opacity", 1.0f); m_generalUniforms.SetFloatValue("u_color", 0.0f, 0.0f, 1.0f, 0.7f); - m_generalUniforms.SetFloatValue("u_halfWidth", 15.0f, 15.0f * m_modelView.GetScale()); - - m_generalUniforms.SetFloatValue("u_clipLength", 8.0f); + m_generalUniforms.SetFloatValue("u_routeParams", 15.0f, 15.0f * m_modelView.GetScale(), 8.0f); dp::Batcher::TFlushFn flushFn = bind(&df::TestingEngine::OnFlushData, this, _1, _2); m_batcher->StartSession(flushFn); |