diff options
author | r.kuznetsov <r.kuznetsov@corp.mail.ru> | 2016-09-15 13:04:36 +0300 |
---|---|---|
committer | r.kuznetsov <r.kuznetsov@corp.mail.ru> | 2016-09-27 11:53:44 +0300 |
commit | 06cf7a28debe3d2c922e8d7114f06c154356e360 (patch) | |
tree | 6a7846556ff2579d12325efdc1f99bfd2b364bad /drape | |
parent | 1a1ebbcbe99a80210049bea08045da3ea7835d91 (diff) |
Added line simplification
Diffstat (limited to 'drape')
-rw-r--r-- | drape/batcher_helpers.cpp | 2 | ||||
-rw-r--r-- | drape/color.hpp | 8 | ||||
-rw-r--r-- | drape/drape_tests/glfunctions.cpp | 12 | ||||
-rw-r--r-- | drape/drape_tests/glmock_functions.hpp | 3 | ||||
-rw-r--r-- | drape/glfunctions.cpp | 22 | ||||
-rw-r--r-- | drape/glfunctions.hpp | 4 | ||||
-rw-r--r-- | drape/glstate.cpp | 22 | ||||
-rw-r--r-- | drape/glstate.hpp | 3 | ||||
-rw-r--r-- | drape/support_manager.cpp | 10 | ||||
-rw-r--r-- | drape/support_manager.hpp | 4 |
10 files changed, 80 insertions, 10 deletions
diff --git a/drape/batcher_helpers.cpp b/drape/batcher_helpers.cpp index c35586d064..e15a3840a0 100644 --- a/drape/batcher_helpers.cpp +++ b/drape/batcher_helpers.cpp @@ -349,7 +349,7 @@ void LineRawBatch::BatchData(ref_ptr<AttributeProvider> streams) uint32_t avIndex = GetAvailableIndexCount(); uint32_t vertexCount = streams->GetVertexCount(); ASSERT_GREATER_OR_EQUAL(vertexCount, 2, ()); - uint32_t indexCount = static_cast<uint32_t>(m_indices.size()); + uint32_t const indexCount = static_cast<uint32_t>(m_indices.size()); if (!IsEnoughMemory(avVertex, vertexCount, avIndex, indexCount)) { diff --git a/drape/color.hpp b/drape/color.hpp index 6726812266..bd51571259 100644 --- a/drape/color.hpp +++ b/drape/color.hpp @@ -1,5 +1,7 @@ #pragma once +#include "base/math.hpp" + #include "std/cstdint.hpp" #include "std/sstream.hpp" #include "std/string.hpp" @@ -26,9 +28,9 @@ struct Color bool operator< (Color const & other) const { return m_rgba < other.m_rgba; } Color operator*(float s) const { - return Color(static_cast<uint8_t>(GetRed() * s), - static_cast<uint8_t>(GetGreen() * s), - static_cast<uint8_t>(GetBlue() * s), + return Color(my::clamp(static_cast<uint8_t>(GetRed() * s), 0, 255), + my::clamp(static_cast<uint8_t>(GetGreen() * s), 0, 255), + my::clamp(static_cast<uint8_t>(GetBlue() * s), 0, 255), GetAlfa()); } diff --git a/drape/drape_tests/glfunctions.cpp b/drape/drape_tests/glfunctions.cpp index d92fb43f6e..ad78bd869b 100644 --- a/drape/drape_tests/glfunctions.cpp +++ b/drape/drape_tests/glfunctions.cpp @@ -11,7 +11,6 @@ using namespace emul; void GLFunctions::glFlush() { - } uint32_t GLFunctions::glGenVertexArray() @@ -111,7 +110,6 @@ int8_t GLFunctions::glGetAttribLocation(uint32_t programID, string const & name) void GLFunctions::glBindAttribLocation(uint32_t programID, uint8_t index, string const & name) { - } /// enable vertex attribute binding. To get attributeLocation need to call glGetAttributeLocation @@ -246,6 +244,16 @@ string GLFunctions::glGetString(glConst pname) return MOCK_CALL(glGetString(pname)); } +int32_t GLFunctions::glGetMaxLineWidth() +{ + return MOCK_CALL(glGetMaxLineWidth()); +} + +void GLFunctions::glLineWidth(uint32_t value) +{ + return MOCK_CALL(glLineWidth(value)); +} + void CheckGLError(my::SrcPoint const & /*srcPt*/) {} void GLFunctions::glEnable(glConst mode) {} diff --git a/drape/drape_tests/glmock_functions.hpp b/drape/drape_tests/glmock_functions.hpp index 7c80ac36b5..399dabe8d0 100644 --- a/drape/drape_tests/glmock_functions.hpp +++ b/drape/drape_tests/glmock_functions.hpp @@ -82,6 +82,9 @@ public: MOCK_METHOD1(glGetInteger, int32_t(glConst)); MOCK_METHOD1(glGetString, string(glConst)); + MOCK_METHOD0(glGetMaxLineWidth, int32_t()); + + MOCK_METHOD1(glLineWidth, void(uint32_t value)); private: static GLMockFunctions * m_mock; diff --git a/drape/glfunctions.cpp b/drape/glfunctions.cpp index 68ed7f15a5..41ec7c1632 100644 --- a/drape/glfunctions.cpp +++ b/drape/glfunctions.cpp @@ -190,6 +190,7 @@ public: m_glBindTextureCache = CachedParam<uint32_t>(); m_glActiveTextureCache = CachedParam<glConst>(); m_glUseProgramCache = CachedParam<uint32_t>(); + m_glLineWidthCache = CachedParam<uint32_t>(); m_glStateCache.clear(); m_uniformsCache.clear(); } @@ -250,6 +251,14 @@ public: } } + void glLineWidth(uint32_t value) + { + if (!IsCachedThread() || m_glLineWidthCache.Assign(value)) + { + GLCHECK(::glLineWidth(static_cast<float>(value))); + } + } + private: template<typename TValue> @@ -326,6 +335,7 @@ private: CachedParam<glConst> m_glActiveTextureCache; CachedParam<uint32_t> m_glUseProgramCache; StateParams m_glStateCache; + CachedParam<uint32_t> m_glLineWidthCache; map<uint32_t, UniformsCache> m_uniformsCache; @@ -573,6 +583,13 @@ string GLFunctions::glGetString(glConst pname) return string(str); } +int32_t GLFunctions::glGetMaxLineWidth() +{ + GLint range[2]; + GLCHECK(::glGetIntegerv(GL_ALIASED_LINE_WIDTH_RANGE, range)); + return max(range[0], range[1]); +} + int32_t GLFunctions::glGetBufferParameter(glConst target, glConst name) { GLint result; @@ -1037,6 +1054,11 @@ uint32_t GLFunctions::glCheckFramebufferStatus() return result; } +void GLFunctions::glLineWidth(uint32_t value) +{ + s_cache.glLineWidth(value); +} + namespace { diff --git a/drape/glfunctions.hpp b/drape/glfunctions.hpp index b775f41ab9..dab34efe89 100644 --- a/drape/glfunctions.hpp +++ b/drape/glfunctions.hpp @@ -40,6 +40,8 @@ public: static string glGetString(glConst pname); + static int32_t glGetMaxLineWidth(); + static void glEnable(glConst mode); static void glDisable(glConst mode); static void glClearDepthValue(double depth); @@ -48,6 +50,8 @@ public: static void glBlendEquation(glConst function); static void glBlendFunc(glConst srcFactor, glConst dstFactor); + static void glLineWidth(uint32_t value); + /// VAO support static uint32_t glGenVertexArray(); static void glBindVertexArray(uint32_t vao); diff --git a/drape/glstate.cpp b/drape/glstate.cpp index cdcfff2538..a13b8fea7f 100644 --- a/drape/glstate.cpp +++ b/drape/glstate.cpp @@ -53,8 +53,8 @@ GLState::GLState(uint32_t gpuProgramIndex, DepthLayer depthLayer) , m_colorTexture(nullptr) , m_maskTexture(nullptr) , m_drawAsLine(false) -{ -} + , m_lineWidth(1) +{} glConst GLState::GetDepthFunction() const { @@ -86,6 +86,16 @@ void GLState::SetDrawAsLine(bool drawAsLine) m_drawAsLine = drawAsLine; } +int GLState::GetLineWidth() const +{ + return m_lineWidth; +} + +void GLState::SetLineWidth(int width) +{ + m_lineWidth = width; +} + bool GLState::operator<(GLState const & other) const { if (m_depthLayer != other.m_depthLayer) @@ -104,8 +114,10 @@ bool GLState::operator<(GLState const & other) const return m_maskTexture < other.m_maskTexture; if (m_textureFilter != other.m_textureFilter) return m_textureFilter < other.m_textureFilter; + if (m_drawAsLine != other.m_drawAsLine) + return m_drawAsLine < other.m_drawAsLine; - return m_drawAsLine < other.m_drawAsLine; + return m_lineWidth < other.m_lineWidth; } bool GLState::operator==(GLState const & other) const @@ -118,7 +130,8 @@ bool GLState::operator==(GLState const & other) const m_maskTexture == other.m_maskTexture && m_textureFilter == other.m_textureFilter && m_depthFunction == other.m_depthFunction && - m_drawAsLine == other.m_drawAsLine; + m_drawAsLine == other.m_drawAsLine && + m_lineWidth == other.m_lineWidth; } bool GLState::operator!=(GLState const & other) const @@ -205,6 +218,7 @@ void ApplyState(GLState state, ref_ptr<GpuProgram> program) ApplyTextures(state, program); ApplyBlending(state, program); GLFunctions::glDepthFunc(state.GetDepthFunction()); + GLFunctions::glLineWidth(state.GetLineWidth()); } } diff --git a/drape/glstate.hpp b/drape/glstate.hpp index 661461ebf4..cf42cec1e4 100644 --- a/drape/glstate.hpp +++ b/drape/glstate.hpp @@ -69,6 +69,8 @@ public: bool GetDrawAsLine() const; void SetDrawAsLine(bool drawAsLine); + int GetLineWidth() const; + void SetLineWidth(int width); bool operator<(GLState const & other) const; bool operator==(GLState const & other) const; @@ -86,6 +88,7 @@ private: ref_ptr<Texture> m_maskTexture; bool m_drawAsLine; + int m_lineWidth; }; void ApplyUniforms(UniformValuesStorage const & uniforms, ref_ptr<GpuProgram> program); diff --git a/drape/support_manager.cpp b/drape/support_manager.cpp index 812bbe693e..516f5fa41b 100644 --- a/drape/support_manager.cpp +++ b/drape/support_manager.cpp @@ -3,6 +3,8 @@ #include "base/logging.hpp" +#include "std/algorithm.hpp" + #include "3party/Alohalytics/src/alohalytics.h" namespace dp @@ -43,6 +45,9 @@ void SupportManager::Init() m_isTegra = (renderer.find("Tegra") != string::npos); if (m_isTegra) LOG(LINFO, ("NVidia Tegra device detected.")); + + m_maxLineWidth = max(1, GLFunctions::glGetMaxLineWidth()); + LOG(LINFO, ("Max line width =", m_maxLineWidth)); } bool SupportManager::IsSamsungGoogleNexus() const @@ -60,6 +65,11 @@ bool SupportManager::IsTegraDevice() const return m_isTegra; } +int SupportManager::GetMaxLineWidth() const +{ + return m_maxLineWidth; +} + SupportManager & SupportManager::Instance() { static SupportManager manager; diff --git a/drape/support_manager.hpp b/drape/support_manager.hpp index ec45097d84..bac71bd2e1 100644 --- a/drape/support_manager.hpp +++ b/drape/support_manager.hpp @@ -17,6 +17,8 @@ public: bool IsAdreno200Device() const; bool IsTegraDevice() const; + int GetMaxLineWidth() const; + private: SupportManager() = default; ~SupportManager() = default; @@ -24,6 +26,8 @@ private: bool m_isSamsungGoogleNexus = false; bool m_isAdreno200 = false; bool m_isTegra = false; + + int m_maxLineWidth = 1; }; } // namespace dp |