diff --git a/drape/drape.pro b/drape/drape.pro index 9004186513..c921c3d415 100644 --- a/drape/drape.pro +++ b/drape/drape.pro @@ -24,4 +24,5 @@ OTHER_FILES += \ shaders/solid_area_fragment_shader.fsh \ shaders/texturing_vertex_shader.vsh \ shaders/shader_index.txt \ - shaders/texturing_fragment_shader.fsh + shaders/texturing_fragment_shader.fsh \ + shaders/line_vertex_shader.vsh diff --git a/drape/shaders/line_vertex_shader.vsh b/drape/shaders/line_vertex_shader.vsh index d869cabdca..7080fccc93 100644 --- a/drape/shaders/line_vertex_shader.vsh +++ b/drape/shaders/line_vertex_shader.vsh @@ -1,10 +1,13 @@ attribute highp vec4 position; -attribute highp vec4 normal; +attribute highp vec4 direction; uniform highp mat4 modelView; uniform highp mat4 projection; void main(void) { - gl_Position = (position + normal) * modelView * projection; + float width = direction.z; + vec4 n = vec4(-direction.y, direction.x, 0, 0); + vec4 pn = normalize(n * modelView) * width; + gl_Position = (pn + position * modelView) * projection; } diff --git a/drape_frontend/line_shape.cpp b/drape_frontend/line_shape.cpp index b156ad401e..f80e7f8518 100644 --- a/drape_frontend/line_shape.cpp +++ b/drape_frontend/line_shape.cpp @@ -7,9 +7,9 @@ #include "../base/math.hpp" #include "../base/logging.hpp" +#include "../base/stl_add.hpp" #include "../std/algorithm.hpp" -#include "../base/stl_add.hpp" namespace df { @@ -57,7 +57,7 @@ namespace df void LineShape::Draw(RefPointer batcher) const { vector renderPoints; - vector renderNormals; + vector renderNormals; const float hw = GetWidth() / 2.0f; typedef m2::PointF vec2; @@ -88,18 +88,12 @@ namespace df continue; } - vec2 normal(-segment.y, segment.x); - ASSERT(my::AlmostEqual(m2::DotProduct(normal, segment), 0.f), ()); - - normal = normal.Normalize()*hw; - ASSERT(!normal.IsAlmostZero(), (i, normal, start, end, segment)); - - ToPoint3DFunctor convertTo3d(m_depth); const Point3D start3d = convertTo3d(start); const Point3D end3d = convertTo3d(end); - const m2::PointF normalPos = normal; - const m2::PointF normalNeg = -normal; + convertTo3d.SetThirdComponent(hw); + const Point3D normalPos = convertTo3d(segment); + const Point3D normalNeg = convertTo3d(-segment); renderPoints.push_back(start3d); renderPoints.push_back(start3d); @@ -137,8 +131,8 @@ namespace df { BindingInfo normalInfo(1); BindingDecl & decl = normalInfo.GetBindingDecl(0); - decl.m_attributeName = "normal"; - decl.m_componentCount = 2; + decl.m_attributeName = "direction"; + decl.m_componentCount = 3; decl.m_componentType = GLConst::GLFloatType; decl.m_offset = 0; decl.m_stride = 0; diff --git a/drape_frontend/map_shape.hpp b/drape_frontend/map_shape.hpp index dfdc70aecc..021e178ff3 100644 --- a/drape_frontend/map_shape.hpp +++ b/drape_frontend/map_shape.hpp @@ -25,17 +25,22 @@ namespace df struct ToPoint3DFunctor { - ToPoint3DFunctor(float depth) - : m_depth(depth) + ToPoint3DFunctor(float thirdComponent) + : m_thirdComponent(thirdComponent) {} Point3D operator ()(m2::PointF const & p) { - return Point3D(p.x, p.y, m_depth); + return Point3D(p.x, p.y, m_thirdComponent); + } + + void SetThirdComponent(float c) + { + m_thirdComponent = c; } private: - float m_depth; + float m_thirdComponent; }; ///