From 6d6e55da68cf142cf1da84138c46f82944746241 Mon Sep 17 00:00:00 2001 From: "r.kuznetsov" Date: Fri, 18 Dec 2015 11:00:35 +0300 Subject: [PATCH] Button shader reorganization --- drape/shaders/button_vertex_shader.vsh | 3 +- drape_frontend/gui/button.cpp | 45 ++++++++++---------------- drape_frontend/gui/button.hpp | 9 ++---- 3 files changed, 21 insertions(+), 36 deletions(-) diff --git a/drape/shaders/button_vertex_shader.vsh b/drape/shaders/button_vertex_shader.vsh index af433ab884..8eab063a26 100644 --- a/drape/shaders/button_vertex_shader.vsh +++ b/drape/shaders/button_vertex_shader.vsh @@ -1,4 +1,3 @@ -attribute vec3 a_position; attribute vec2 a_normal; uniform mat4 modelView; @@ -6,5 +5,5 @@ uniform mat4 projection; void main(void) { - gl_Position = (vec4(a_normal, 0, 0) + vec4(a_position, 1) * modelView) * projection; + gl_Position = vec4(modelView[0][3] + a_normal.x, modelView[1][3] + a_normal.y, modelView[2][3], 1) * projection; } diff --git a/drape_frontend/gui/button.cpp b/drape_frontend/gui/button.cpp index 9c867ff090..4584d118c3 100644 --- a/drape_frontend/gui/button.cpp +++ b/drape_frontend/gui/button.cpp @@ -36,15 +36,13 @@ uint32_t BuildRect(vector & vertices, glsl::vec2 const & v3, glsl::vec2 const & v4) { - glsl::vec3 const position(0.0f, 0.0f, 0.0f); + vertices.push_back(Button::ButtonVertex(v1)); + vertices.push_back(Button::ButtonVertex(v2)); + vertices.push_back(Button::ButtonVertex(v3)); - vertices.push_back(Button::ButtonVertex(position, v1)); - vertices.push_back(Button::ButtonVertex(position, v2)); - vertices.push_back(Button::ButtonVertex(position, v3)); - - vertices.push_back(Button::ButtonVertex(position, v3)); - vertices.push_back(Button::ButtonVertex(position, v2)); - vertices.push_back(Button::ButtonVertex(position, v4)); + vertices.push_back(Button::ButtonVertex(v3)); + vertices.push_back(Button::ButtonVertex(v2)); + vertices.push_back(Button::ButtonVertex(v4)); return dp::Batcher::IndexPerQuad; } @@ -53,23 +51,21 @@ uint32_t BuildCorner(vector & vertices, glsl::vec2 const & pt, double radius, double angleStart, double angleFinish) { - glsl::vec3 const position(0.0f, 0.0f, 0.0f); - - int const trianglesCount = 8; - double const sector = (angleFinish - angleStart) / static_cast(trianglesCount); + int const kTrianglesCount = 8; + double const sector = (angleFinish - angleStart) / kTrianglesCount; m2::PointD startNormal(0.0f, radius); - for (size_t i = 0; i < trianglesCount; ++i) + for (size_t i = 0; i < kTrianglesCount; ++i) { m2::PointD normal = m2::Rotate(startNormal, angleStart + i * sector); m2::PointD nextNormal = m2::Rotate(startNormal, angleStart + (i + 1) * sector); - vertices.push_back(Button::ButtonVertex(position, pt)); - vertices.push_back(Button::ButtonVertex(position, pt - glsl::ToVec2(normal))); - vertices.push_back(Button::ButtonVertex(position, pt - glsl::ToVec2(nextNormal))); + vertices.push_back(Button::ButtonVertex(pt)); + vertices.push_back(Button::ButtonVertex(pt - glsl::ToVec2(normal))); + vertices.push_back(Button::ButtonVertex(pt - glsl::ToVec2(nextNormal))); } - return trianglesCount * dp::Batcher::IndexPerTriangle; + return kTrianglesCount * dp::Batcher::IndexPerTriangle; } } @@ -189,21 +185,14 @@ dp::BindingInfo const & Button::ButtonVertex::GetBindingInfo() if (info == nullptr) { - info.reset(new dp::BindingInfo(2)); + info.reset(new dp::BindingInfo(1)); - dp::BindingDecl & posDecl = info->GetBindingDecl(0); - posDecl.m_attributeName = "a_position"; - posDecl.m_componentCount = 3; - posDecl.m_componentType = gl_const::GLFloatType; - posDecl.m_offset = 0; - posDecl.m_stride = sizeof(ButtonVertex); - - dp::BindingDecl & normalDecl = info->GetBindingDecl(1); + dp::BindingDecl & normalDecl = info->GetBindingDecl(0); normalDecl.m_attributeName = "a_normal"; normalDecl.m_componentCount = 2; normalDecl.m_componentType = gl_const::GLFloatType; - normalDecl.m_offset = sizeof(glsl::vec3); - normalDecl.m_stride = posDecl.m_stride; + normalDecl.m_offset = 0; + normalDecl.m_stride = sizeof(ButtonVertex); } return *info.get(); diff --git a/drape_frontend/gui/button.hpp b/drape_frontend/gui/button.hpp index 193e6db78b..087cc676dd 100644 --- a/drape_frontend/gui/button.hpp +++ b/drape_frontend/gui/button.hpp @@ -33,15 +33,12 @@ public: struct ButtonVertex { ButtonVertex() = default; - ButtonVertex(glsl::vec3 const & position, glsl::vec2 const & normal) - : m_position(position) - , m_normal(normal) - { - } + ButtonVertex(glsl::vec2 const & normal) + : m_normal(normal) + {} static dp::BindingInfo const & GetBindingInfo(); - glsl::vec3 m_position; glsl::vec2 m_normal; };