From da463fa328ecabf2cf8a825214390178166607eb Mon Sep 17 00:00:00 2001 From: "r.kuznetsov" Date: Mon, 9 Jan 2017 13:58:34 +0300 Subject: [PATCH] Added outline for my-position arrow in routing --- drape/drape.pro | 1 + .../arrow3d_outline_fragment_shader.fsh | 24 +++++++++++++ drape/shaders/shader_index.txt | 1 + drape_frontend/arrow3d.cpp | 36 ++++++++++++------- drape_frontend/arrow3d.hpp | 9 +++-- drape_frontend/my_position.cpp | 2 +- 6 files changed, 57 insertions(+), 16 deletions(-) create mode 100644 drape/shaders/arrow3d_outline_fragment_shader.fsh diff --git a/drape/drape.pro b/drape/drape.pro index bcdf1d71be..592d58512b 100644 --- a/drape/drape.pro +++ b/drape/drape.pro @@ -16,6 +16,7 @@ OTHER_FILES += \ shaders/area3d_outline_vertex_shader.vsh \ shaders/area_vertex_shader.vsh \ shaders/arrow3d_fragment_shader.fsh \ + shaders/arrow3d_outline_fragment_shader.fsh \ shaders/arrow3d_shadow_fragment_shader.fsh \ shaders/arrow3d_shadow_vertex_shader.vsh \ shaders/arrow3d_vertex_shader.vsh \ diff --git a/drape/shaders/arrow3d_outline_fragment_shader.fsh b/drape/shaders/arrow3d_outline_fragment_shader.fsh new file mode 100644 index 0000000000..809f34a675 --- /dev/null +++ b/drape/shaders/arrow3d_outline_fragment_shader.fsh @@ -0,0 +1,24 @@ +varying float v_intensity; + +#ifdef SAMSUNG_GOOGLE_NEXUS +uniform sampler2D u_colorTex; +#endif + +uniform vec4 u_color; + +void main() +{ +#ifdef SAMSUNG_GOOGLE_NEXUS + // Because of a bug in OpenGL driver on Samsung Google Nexus this workaround is here. + const float kFakeColorScalar = 0.0; + lowp vec4 fakeColor = texture2D(u_colorTex, vec2(0.0, 0.0)) * kFakeColorScalar; +#endif + + vec4 resColor = vec4(u_color.rgb, u_color.a * smoothstep(0.7, 1.0, v_intensity)); + +#ifdef SAMSUNG_GOOGLE_NEXUS + gl_FragColor = resColor + fakeColor; +#else + gl_FragColor = resColor; +#endif +} diff --git a/drape/shaders/shader_index.txt b/drape/shaders/shader_index.txt index 5fbb2ccab3..c2033f7e0b 100644 --- a/drape/shaders/shader_index.txt +++ b/drape/shaders/shader_index.txt @@ -25,6 +25,7 @@ DEBUG_RECT_PROGRAM debug_rect_vertex_shader.vsh debug_rect_fragment_shader.fsh TRANSPARENT_LAYER_PROGRAM transparent_layer_vertex_shader.vsh transparent_layer_fragment_shader.fsh ARROW_3D_PROGRAM arrow3d_vertex_shader.vsh arrow3d_fragment_shader.fsh ARROW_3D_SHADOW_PROGRAM arrow3d_shadow_vertex_shader.vsh arrow3d_shadow_fragment_shader.fsh +ARROW_3D_OUTLINE_PROGRAM arrow3d_shadow_vertex_shader.vsh arrow3d_outline_fragment_shader.fsh TEXTURING_BILLBOARD_PROGRAM texturing_billboard_vertex_shader.vsh texturing_fragment_shader.fsh MASKED_TEXTURING_BILLBOARD_PROGRAM masked_texturing_billboard_vertex_shader.vsh masked_texturing_fragment_shader.fsh TEXT_OUTLINED_BILLBOARD_PROGRAM text_outlined_billboard_vertex_shader.vsh text_fragment_shader.fsh diff --git a/drape_frontend/arrow3d.cpp b/drape_frontend/arrow3d.cpp index d49148cf3e..a89a4fea25 100644 --- a/drape_frontend/arrow3d.cpp +++ b/drape_frontend/arrow3d.cpp @@ -27,7 +27,9 @@ double const kArrow3dScaleMin = 1.0; double const kArrow3dScaleMax = 2.2; double const kArrow3dMinZoom = 16; -uint32_t constexpr kComponentsInVertex = 4; +float const kOutlineScale = 1.2f; + +int constexpr kComponentsInVertex = 4; Arrow3d::Arrow3d() : m_state(gpu::ARROW_3D_PROGRAM, dp::GLState::OverlayLayer) @@ -118,7 +120,7 @@ void Arrow3d::SetPositionObsolete(bool obsolete) m_obsoletePosition = obsolete; } -void Arrow3d::Render(ScreenBase const & screen, int zoomLevel, ref_ptr mng) +void Arrow3d::Render(ScreenBase const & screen, ref_ptr mng, bool routingMode) { // Unbind current VAO, because glVertexAttributePointer and glEnableVertexAttribute can affect it. if (dp::GLExtensionsList::Instance().IsSupported(dp::GLExtensionsList::VertexArrayObject)) @@ -134,26 +136,36 @@ void Arrow3d::Render(ScreenBase const & screen, int zoomLevel, ref_ptr shadowProgram = mng->GetProgram(gpu::ARROW_3D_SHADOW_PROGRAM); - RenderArrow(screen, shadowProgram, dp::Color(60, 60, 60, 60), 0.05f, false /* hasNormals */); + RenderArrow(screen, shadowProgram, dp::Color(60, 60, 60, 60), 0.05f /* dz */, + routingMode ? kOutlineScale : 1.0f /* scaleFactor */, false /* hasNormals */); + } + + dp::Color const color = df::GetColorConstant(GetStyleReader().GetCurrentStyle(), + m_obsoletePosition ? df::Arrow3DObsolete : df::Arrow3D); + + // Render outline. + if (routingMode) + { + ref_ptr outlineProgram = mng->GetProgram(gpu::ARROW_3D_OUTLINE_PROGRAM); + RenderArrow(screen, outlineProgram, dp::Color(255, 255, 255, color.GetAlfa()), 0.0f /* dz */, + kOutlineScale /* scaleFactor */, false /* hasNormals */); } // Render arrow. ref_ptr arrowProgram = mng->GetProgram(gpu::ARROW_3D_PROGRAM); - dp::Color const color = df::GetColorConstant(GetStyleReader().GetCurrentStyle(), - m_obsoletePosition ? df::Arrow3DObsolete : df::Arrow3D); - RenderArrow(screen, arrowProgram, color, 0.0f, true /* hasNormals */); + RenderArrow(screen, arrowProgram, color, 0.0f /* dz */, 1.0f /* scaleFactor */, true /* hasNormals */); arrowProgram->Unbind(); GLFunctions::glBindBuffer(0, gl_const::GLArrayBuffer); } void Arrow3d::RenderArrow(ScreenBase const & screen, ref_ptr program, - dp::Color const & color, float dz, bool hasNormals) + dp::Color const & color, float dz, float scaleFactor, bool hasNormals) { program->Bind(); GLFunctions::glBindBuffer(m_bufferId, gl_const::GLArrayBuffer); - uint32_t const attributePosition = program->GetAttributeLocation("a_pos"); + int8_t const attributePosition = program->GetAttributeLocation("a_pos"); ASSERT_NOT_EQUAL(attributePosition, -1, ()); GLFunctions::glEnableVertexAttribute(attributePosition); GLFunctions::glVertexAttributePointer(attributePosition, kComponentsInVertex, @@ -162,14 +174,14 @@ void Arrow3d::RenderArrow(ScreenBase const & screen, ref_ptr pro if (hasNormals) { GLFunctions::glBindBuffer(m_bufferNormalsId, gl_const::GLArrayBuffer); - uint32_t const attributeNormal = program->GetAttributeLocation("a_normal"); + int8_t const attributeNormal = program->GetAttributeLocation("a_normal"); ASSERT_NOT_EQUAL(attributeNormal, -1, ()); GLFunctions::glEnableVertexAttribute(attributeNormal); GLFunctions::glVertexAttributePointer(attributeNormal, 3, gl_const::GLFloatType, false, 0, 0); } dp::UniformValuesStorage uniforms; - math::Matrix const modelTransform = CalculateTransform(screen, dz); + math::Matrix const modelTransform = CalculateTransform(screen, dz, scaleFactor); uniforms.SetMatrix4x4Value("u_transform", modelTransform.m_data); glsl::vec4 const c = glsl::ToVec4(color); uniforms.SetFloatValue("u_color", c.r, c.g, c.b, c.a); @@ -178,9 +190,9 @@ void Arrow3d::RenderArrow(ScreenBase const & screen, ref_ptr pro GLFunctions::glDrawArrays(gl_const::GLTriangles, 0, static_cast(m_vertices.size()) / kComponentsInVertex); } -math::Matrix Arrow3d::CalculateTransform(ScreenBase const & screen, float dz) const +math::Matrix Arrow3d::CalculateTransform(ScreenBase const & screen, float dz, float scaleFactor) const { - double arrowScale = VisualParams::Instance().GetVisualScale() * kArrowSize; + double arrowScale = VisualParams::Instance().GetVisualScale() * kArrowSize * scaleFactor; if (screen.isPerspective()) { double const t = GetNormalizedZoomLevel(screen.GetScale(), kArrow3dMinZoom); diff --git a/drape_frontend/arrow3d.hpp b/drape_frontend/arrow3d.hpp index 7dcaeec3e2..37db7a7ed4 100644 --- a/drape_frontend/arrow3d.hpp +++ b/drape_frontend/arrow3d.hpp @@ -30,13 +30,16 @@ public: void SetTexture(ref_ptr texMng); void SetPositionObsolete(bool obsolete); - void Render(ScreenBase const & screen, int zoomLevel, ref_ptr mng); + void Render(ScreenBase const & screen, ref_ptr mng, + bool routingMode); private: void Build(); - math::Matrix CalculateTransform(ScreenBase const & screen, float dz) const; + math::Matrix CalculateTransform(ScreenBase const & screen, + float dz, float scaleFactor) const; void RenderArrow(ScreenBase const & screen, ref_ptr program, - dp::Color const & color, float dz, bool hasNormals); + dp::Color const & color, float dz, + float scaleFactor, bool hasNormals); m2::PointD m_position; double m_azimuth = 0.0; diff --git a/drape_frontend/my_position.cpp b/drape_frontend/my_position.cpp index d699c2ba54..d7d480bcd1 100644 --- a/drape_frontend/my_position.cpp +++ b/drape_frontend/my_position.cpp @@ -125,7 +125,7 @@ void MyPosition::RenderMyPosition(ScreenBase const & screen, int zoomLevel, { m_arrow3d.SetPosition(m_position); m_arrow3d.SetAzimuth(m_azimuth); - m_arrow3d.Render(screen, zoomLevel, mng); + m_arrow3d.Render(screen, mng, m_isRoutingMode); } else {