diff options
author | r.kuznetsov <r.kuznetsov@corp.mail.ru> | 2016-09-14 17:25:56 +0300 |
---|---|---|
committer | r.kuznetsov <r.kuznetsov@corp.mail.ru> | 2016-09-26 16:19:29 +0300 |
commit | 1a1ebbcbe99a80210049bea08045da3ea7835d91 (patch) | |
tree | 8f2b80d91e72652b24e395f6a0a56652cfc77976 /drape | |
parent | a115d10958f8617196d7c286ca04487ebfaee0ef (diff) |
Added outline for houses
Diffstat (limited to 'drape')
-rw-r--r-- | drape/batcher.cpp | 46 | ||||
-rw-r--r-- | drape/batcher.hpp | 18 | ||||
-rw-r--r-- | drape/batcher_helpers.cpp | 198 | ||||
-rw-r--r-- | drape/batcher_helpers.hpp | 53 | ||||
-rw-r--r-- | drape/color.hpp | 7 | ||||
-rw-r--r-- | drape/drape.pro | 1 | ||||
-rw-r--r-- | drape/drape_tests/glfunctions.cpp | 3 | ||||
-rw-r--r-- | drape/glconstants.cpp | 1 | ||||
-rw-r--r-- | drape/glconstants.hpp | 1 | ||||
-rw-r--r-- | drape/glfunctions.cpp | 4 | ||||
-rw-r--r-- | drape/glfunctions.hpp | 2 | ||||
-rw-r--r-- | drape/glstate.cpp | 22 | ||||
-rw-r--r-- | drape/glstate.hpp | 5 | ||||
-rw-r--r-- | drape/render_bucket.cpp | 4 | ||||
-rw-r--r-- | drape/render_bucket.hpp | 2 | ||||
-rw-r--r-- | drape/shaders/area3d_outline_vertex_shader.vsh | 28 | ||||
-rw-r--r-- | drape/shaders/shader_index.txt | 2 | ||||
-rw-r--r-- | drape/vertex_array_buffer.cpp | 12 | ||||
-rw-r--r-- | drape/vertex_array_buffer.hpp | 4 |
19 files changed, 330 insertions, 83 deletions
diff --git a/drape/batcher.cpp b/drape/batcher.cpp index ea72fe4f88..c8bc1b548a 100644 --- a/drape/batcher.cpp +++ b/drape/batcher.cpp @@ -53,10 +53,12 @@ public: return m_indexStorage.GetRaw(); } else + { return m_overlay->IndexStorage(size); + } } - void SubmitIndeces() override + void SubmitIndices() override { if (m_overlay == nullptr || !m_overlay->IndexesRequired()) m_buffer->UploadIndexes(m_indexStorage.GetRawConst(), m_indexStorage.Size()); @@ -123,7 +125,7 @@ void Batcher::InsertTriangleList(GLState const & state, ref_ptr<AttributeProvide IndicesRange Batcher::InsertTriangleList(GLState const & state, ref_ptr<AttributeProvider> params, drape_ptr<OverlayHandle> && handle) { - return InsertTriangles<TriangleListBatch>(state, params, move(handle)); + return InsertPrimitives<TriangleListBatch>(state, params, move(handle), 0 /* vertexStride */); } void Batcher::InsertTriangleStrip(GLState const & state, ref_ptr<AttributeProvider> params) @@ -134,7 +136,7 @@ void Batcher::InsertTriangleStrip(GLState const & state, ref_ptr<AttributeProvid IndicesRange Batcher::InsertTriangleStrip(GLState const & state, ref_ptr<AttributeProvider> params, drape_ptr<OverlayHandle> && handle) { - return InsertTriangles<TriangleStripBatch>(state, params, move(handle)); + return InsertPrimitives<TriangleStripBatch>(state, params, move(handle), 0 /* vertexStride */); } void Batcher::InsertTriangleFan(GLState const & state, ref_ptr<AttributeProvider> params) @@ -145,7 +147,7 @@ void Batcher::InsertTriangleFan(GLState const & state, ref_ptr<AttributeProvider IndicesRange Batcher::InsertTriangleFan(GLState const & state, ref_ptr<AttributeProvider> params, drape_ptr<OverlayHandle> && handle) { - return InsertTriangles<TriangleFanBatch>(state, params, move(handle)); + return InsertPrimitives<TriangleFanBatch>(state, params, move(handle), 0 /* vertexStride */); } void Batcher::InsertListOfStrip(GLState const & state, ref_ptr<AttributeProvider> params, @@ -157,7 +159,30 @@ void Batcher::InsertListOfStrip(GLState const & state, ref_ptr<AttributeProvider IndicesRange Batcher::InsertListOfStrip(GLState const & state, ref_ptr<AttributeProvider> params, drape_ptr<OverlayHandle> && handle, uint8_t vertexStride) { - return InsertTriangles<TriangleListOfStripBatch>(state, params, move(handle), vertexStride); + return InsertPrimitives<TriangleListOfStripBatch>(state, params, move(handle), vertexStride); +} + +void Batcher::InsertLineStrip(GLState const & state, ref_ptr<AttributeProvider> params) +{ + InsertLineStrip(state, params, nullptr); +} + +IndicesRange Batcher::InsertLineStrip(GLState const & state, ref_ptr<AttributeProvider> params, + drape_ptr<OverlayHandle> && handle) +{ + return InsertPrimitives<LineStripBatch>(state, params, move(handle), 0 /* vertexStride */); +} + +void Batcher::InsertLineRaw(GLState const & state, ref_ptr<AttributeProvider> params, + vector<int> const & indices) +{ + InsertLineRaw(state, params, indices, nullptr); +} + +IndicesRange Batcher::InsertLineRaw(GLState const & state, ref_ptr<AttributeProvider> params, + vector<int> const & indices, drape_ptr<OverlayHandle> && handle) +{ + return InsertPrimitives<LineRawBatch>(state, params, move(handle), 0 /* vertexStride */, indices); } void Batcher::StartSession(TFlushFn const & flusher) @@ -228,9 +253,10 @@ void Batcher::Flush() m_buckets.clear(); } -template <typename TBatcher> -IndicesRange Batcher::InsertTriangles(GLState const & state, ref_ptr<AttributeProvider> params, - drape_ptr<OverlayHandle> && transferHandle, uint8_t vertexStride) +template <typename TBatcher, typename ... TArgs> +IndicesRange Batcher::InsertPrimitives(GLState const & state, ref_ptr<AttributeProvider> params, + drape_ptr<OverlayHandle> && transferHandle, uint8_t vertexStride, + TArgs ... batcherArgs) { ref_ptr<VertexArrayBuffer> vao = GetBucket(state)->GetBuffer(); IndicesRange range; @@ -241,8 +267,8 @@ IndicesRange Batcher::InsertTriangles(GLState const & state, ref_ptr<AttributePr Batcher::CallbacksWrapper wrapper(state, make_ref(handle), make_ref(this)); wrapper.SetVAO(vao); - TBatcher batch(wrapper); - batch.SetIsCanDevideStreams(handle == nullptr); + TBatcher batch(wrapper, batcherArgs ...); + batch.SetCanDevideStreams(handle == nullptr); batch.SetVertexStride(vertexStride); batch.BatchData(params); diff --git a/drape/batcher.hpp b/drape/batcher.hpp index 1326de0372..ca5f30f6a0 100644 --- a/drape/batcher.hpp +++ b/drape/batcher.hpp @@ -45,6 +45,15 @@ public: IndicesRange InsertListOfStrip(GLState const & state, ref_ptr<AttributeProvider> params, drape_ptr<OverlayHandle> && handle, uint8_t vertexStride); + void InsertLineStrip(GLState const & state, ref_ptr<AttributeProvider> params); + IndicesRange InsertLineStrip(GLState const & state, ref_ptr<AttributeProvider> params, + drape_ptr<OverlayHandle> && handle); + + void InsertLineRaw(GLState const & state, ref_ptr<AttributeProvider> params, + vector<int> const & indices); + IndicesRange InsertLineRaw(GLState const & state, ref_ptr<AttributeProvider> params, + vector<int> const & indices, drape_ptr<OverlayHandle> && handle); + typedef function<void (GLState const &, drape_ptr<RenderBucket> &&)> TFlushFn; void StartSession(TFlushFn const & flusher); void EndSession(); @@ -52,9 +61,10 @@ public: void SetFeatureMinZoom(int minZoom); private: - template<typename TBacher> - IndicesRange InsertTriangles(GLState const & state, ref_ptr<AttributeProvider> params, - drape_ptr<OverlayHandle> && handle, uint8_t vertexStride = 0); + template<typename TBatcher, typename ... TArgs> + IndicesRange InsertPrimitives(GLState const & state, ref_ptr<AttributeProvider> params, + drape_ptr<OverlayHandle> && transferHandle, uint8_t vertexStride, + TArgs ... batcherArgs); class CallbacksWrapper; void ChangeBuffer(ref_ptr<CallbacksWrapper> wrapper); @@ -63,10 +73,8 @@ private: void FinalizeBucket(GLState const & state); void Flush(); -private: TFlushFn m_flushInterface; -private: using TBuckets = map<GLState, drape_ptr<RenderBucket>>; TBuckets m_buckets; diff --git a/drape/batcher_helpers.cpp b/drape/batcher_helpers.cpp index 7fea0d6f82..c35586d064 100644 --- a/drape/batcher_helpers.cpp +++ b/drape/batcher_helpers.cpp @@ -45,22 +45,23 @@ public: IndexGenerator(uint32_t startIndex) : m_startIndex(startIndex) , m_counter(0) - , m_minStriptCounter(0) {} + , m_minStripCounter(0) {} protected: uint32_t GetCounter() { return m_counter++; } + void ResetCounter() { m_counter = 0; - m_minStriptCounter = 0; + m_minStripCounter = 0; } uint32_t const m_startIndex; int16_t GetCWNormalizer() { - int16_t tmp = m_minStriptCounter; - m_minStriptCounter = my::cyclicClamp(m_minStriptCounter + 1, 0, 5); + int16_t tmp = m_minStripCounter; + m_minStripCounter = my::cyclicClamp(m_minStripCounter + 1, 0, 5); switch (tmp) { case 4: return 1; @@ -71,7 +72,7 @@ protected: private: uint32_t m_counter; - uint8_t m_minStriptCounter; + uint8_t m_minStripCounter; }; class ListIndexGenerator : public IndexGenerator @@ -86,21 +87,60 @@ class StripIndexGenerator : public IndexGenerator public: StripIndexGenerator(uint32_t startIndex) : IndexGenerator(startIndex) - , m_minStriptCounter(0) {} + {} + uint32_t operator()() { uint32_t const counter = GetCounter(); return m_startIndex + counter - 2 * (counter / 3) + GetCWNormalizer(); } +}; + +class LineStripIndexGenerator : public IndexGenerator +{ +public: + LineStripIndexGenerator(uint32_t startIndex) + : IndexGenerator(startIndex) + {} + + uint32_t operator()() + { + uint32_t const counter = GetCounter(); + uint32_t const result = m_startIndex + m_counter; + if (counter % 2 == 0) + m_counter++; + + return result; + } private: - uint32_t m_minStriptCounter; + uint32_t m_counter = 0; +}; + +class LineRawIndexGenerator : public IndexGenerator +{ +public: + LineRawIndexGenerator(uint32_t startIndex, vector<int> const & indices) + : IndexGenerator(startIndex) + , m_indices(indices) + {} + + uint32_t operator()() + { + uint32_t const counter = GetCounter(); + ASSERT_LESS(counter, m_indices.size(), ()); + return static_cast<uint32_t>(m_startIndex + m_indices[counter]); + } + +private: + vector<int> const & m_indices; }; class FanIndexGenerator : public IndexGenerator { public: FanIndexGenerator(uint32_t startIndex) : IndexGenerator(startIndex) {} + uint32_t operator()() { uint32_t const counter = GetCounter(); @@ -110,14 +150,15 @@ public: } }; -class ListOfStriptGenerator : public IndexGenerator +class ListOfStripGenerator : public IndexGenerator { public: - ListOfStriptGenerator(uint32_t startIndex, uint32_t vertexStride, uint32_t indexPerStrip) + ListOfStripGenerator(uint32_t startIndex, uint32_t vertexStride, uint32_t indexPerStrip) : IndexGenerator(startIndex) , m_vertexStride(vertexStride) , m_indexPerStrip(indexPerStrip) - , m_base(0) {} + , m_base(0) + {} uint32_t operator()() { @@ -140,74 +181,83 @@ private: } // namespace -TriangleBatch::TriangleBatch(BatchCallbacks & callbacks) +UniversalBatch::UniversalBatch(BatchCallbacks & callbacks, uint8_t minVerticesCount, + uint8_t minIndicesCount) : m_callbacks(callbacks) , m_canDevideStreams(true) -{ -} + , m_minVerticesCount(minVerticesCount) + , m_minIndicesCount(minIndicesCount) +{} -void TriangleBatch::SetIsCanDevideStreams(bool canDevide) +void UniversalBatch::SetCanDevideStreams(bool canDevide) { m_canDevideStreams = canDevide; } -bool TriangleBatch::IsCanDevideStreams() const +bool UniversalBatch::CanDevideStreams() const { return m_canDevideStreams; } -void TriangleBatch::SetVertexStride(uint8_t vertexStride) +void UniversalBatch::SetVertexStride(uint8_t vertexStride) { m_vertexStride = vertexStride; } -void TriangleBatch::FlushData(ref_ptr<AttributeProvider> streams, uint32_t vertexCount) const +void UniversalBatch::FlushData(ref_ptr<AttributeProvider> streams, + uint32_t vertexCount) const { for (uint8_t i = 0; i < streams->GetStreamCount(); ++i) FlushData(streams->GetBindingInfo(i), streams->GetRawPointer(i), vertexCount); } -void TriangleBatch::FlushData(BindingInfo const & info, void const * data, uint32_t elementCount) const +void UniversalBatch::FlushData(BindingInfo const & info, void const * data, + uint32_t elementCount) const { m_callbacks.FlushData(info, data, elementCount); } -void * TriangleBatch::GetIndexStorage(uint32_t indexCount, uint32_t & startIndex) +void * UniversalBatch::GetIndexStorage(uint32_t indexCount, uint32_t & startIndex) { return m_callbacks.GetIndexStorage(indexCount, startIndex); } -void TriangleBatch::SubmitIndex() +void UniversalBatch::SubmitIndex() { - m_callbacks.SubmitIndeces(); + m_callbacks.SubmitIndices(); } -uint32_t TriangleBatch::GetAvailableVertexCount() const +uint32_t UniversalBatch::GetAvailableVertexCount() const { return m_callbacks.GetAvailableVertexCount(); } -uint32_t TriangleBatch::GetAvailableIndexCount() const +uint32_t UniversalBatch::GetAvailableIndexCount() const { return m_callbacks.GetAvailableIndexCount(); } -void TriangleBatch::ChangeBuffer() const +void UniversalBatch::ChangeBuffer() const { return m_callbacks.ChangeBuffer(); } -uint8_t TriangleBatch::GetVertexStride() const +uint8_t UniversalBatch::GetVertexStride() const { return m_vertexStride; } -bool TriangleBatch::IsBufferFilled(uint32_t availableVerticesCount, uint32_t availableIndicesCount) const +bool UniversalBatch::IsBufferFilled(uint32_t availableVerticesCount, + uint32_t availableIndicesCount) const { - return availableVerticesCount < 3 || availableIndicesCount < 3; + return availableVerticesCount < m_minVerticesCount || + availableIndicesCount < m_minIndicesCount; } -TriangleListBatch::TriangleListBatch(BatchCallbacks & callbacks) : TBase(callbacks) {} + +TriangleListBatch::TriangleListBatch(BatchCallbacks & callbacks) + : TBase(callbacks, 3 /* minVerticesCount */, 3 /* minIndicesCount */) +{} void TriangleListBatch::BatchData(ref_ptr<AttributeProvider> streams) { @@ -220,7 +270,7 @@ void TriangleListBatch::BatchData(ref_ptr<AttributeProvider> streams) uint32_t avIndex = GetAvailableIndexCount(); uint32_t vertexCount = streams->GetVertexCount(); - if (IsCanDevideStreams()) + if (CanDevideStreams()) { vertexCount = min(vertexCount, avVertex); vertexCount = min(vertexCount, avIndex); @@ -246,12 +296,86 @@ void TriangleListBatch::BatchData(ref_ptr<AttributeProvider> streams) } } -FanStripHelper::FanStripHelper(BatchCallbacks & callbacks) - : TBase(callbacks) - , m_isFullUploaded(false) + +LineStripBatch::LineStripBatch(BatchCallbacks & callbacks) + : TBase(callbacks, 2 /* minVerticesCount */, 2 /* minIndicesCount */) +{} + +void LineStripBatch::BatchData(ref_ptr<AttributeProvider> streams) { + while (streams->IsDataExists()) + { + if (IsBufferFilled(GetAvailableVertexCount(), GetAvailableIndexCount())) + ChangeBuffer(); + + uint32_t avVertex = GetAvailableVertexCount(); + uint32_t avIndex = GetAvailableIndexCount(); + uint32_t vertexCount = streams->GetVertexCount(); + ASSERT_GREATER_OR_EQUAL(vertexCount, 2, ()); + uint32_t indexCount = (vertexCount - 1) * 2; + + if (!IsEnoughMemory(avVertex, vertexCount, avIndex, indexCount)) + { + ChangeBuffer(); + avVertex = GetAvailableVertexCount(); + avIndex = GetAvailableIndexCount(); + ASSERT(IsEnoughMemory(avVertex, vertexCount, avIndex, indexCount), ()); + } + + uint32_t startIndex = 0; + void * indicesStorage = GetIndexStorage(indexCount, startIndex); + GenerateIndices<LineStripIndexGenerator>(indicesStorage, indexCount, startIndex); + SubmitIndex(); + + FlushData(streams, vertexCount); + streams->Advance(vertexCount); + } +} + + +LineRawBatch::LineRawBatch(BatchCallbacks & callbacks, vector<int> const & indices) + : TBase(callbacks, 2 /* minVerticesCount */, 2 /* minIndicesCount */) + , m_indices(indices) +{} + +void LineRawBatch::BatchData(ref_ptr<AttributeProvider> streams) +{ + while (streams->IsDataExists()) + { + if (IsBufferFilled(GetAvailableVertexCount(), GetAvailableIndexCount())) + ChangeBuffer(); + + uint32_t avVertex = GetAvailableVertexCount(); + 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()); + + if (!IsEnoughMemory(avVertex, vertexCount, avIndex, indexCount)) + { + ChangeBuffer(); + avVertex = GetAvailableVertexCount(); + avIndex = GetAvailableIndexCount(); + ASSERT(IsEnoughMemory(avVertex, vertexCount, avIndex, indexCount), ()); + } + + uint32_t startIndex = 0; + void * indicesStorage = GetIndexStorage(indexCount, startIndex); + LineRawIndexGenerator generator(startIndex, m_indices); + GenerateIndices(indicesStorage, indexCount, generator); + SubmitIndex(); + + FlushData(streams, vertexCount); + streams->Advance(vertexCount); + } } + +FanStripHelper::FanStripHelper(BatchCallbacks & callbacks) + : TBase(callbacks, 3 /* minVerticesCount */, 3 /* minIndicesCount */) + , m_isFullUploaded(false) +{} + uint32_t FanStripHelper::BatchIndexes(uint32_t vertexCount) { uint32_t avVertex = GetAvailableVertexCount(); @@ -261,7 +385,7 @@ uint32_t FanStripHelper::BatchIndexes(uint32_t vertexCount) uint32_t batchIndexCount = 0; CalcBatchPortion(vertexCount, avVertex, avIndex, batchVertexCount, batchIndexCount); - if (!IsFullUploaded() && !IsCanDevideStreams()) + if (!IsFullUploaded() && !CanDevideStreams()) { ChangeBuffer(); avVertex = GetAvailableVertexCount(); @@ -332,8 +456,7 @@ uint32_t FanStripHelper::AlignICount(uint32_t iCount) const TriangleStripBatch::TriangleStripBatch(BatchCallbacks & callbacks) : TBase(callbacks) -{ -} +{} void TriangleStripBatch::BatchData(ref_ptr<AttributeProvider> streams) { @@ -465,8 +588,7 @@ void TriangleFanBatch::GenerateIndexes(void * indexStorage, uint32_t count, uint TriangleListOfStripBatch::TriangleListOfStripBatch(BatchCallbacks & callbacks) : TBase(callbacks) -{ -} +{} void TriangleListOfStripBatch::BatchData(ref_ptr<AttributeProvider> streams) { @@ -526,7 +648,7 @@ uint32_t TriangleListOfStripBatch::AlignICount(uint32_t iCount) const void TriangleListOfStripBatch::GenerateIndexes(void * indexStorage, uint32_t count, uint32_t startIndex) const { uint8_t const vertexStride = GetVertexStride(); - GenerateIndices(indexStorage, count, ListOfStriptGenerator(startIndex, vertexStride, VtoICount(vertexStride))); + GenerateIndices(indexStorage, count, ListOfStripGenerator(startIndex, vertexStride, VtoICount(vertexStride))); } } // namespace dp diff --git a/drape/batcher_helpers.hpp b/drape/batcher_helpers.hpp index b099c2314d..8ccc53d286 100644 --- a/drape/batcher_helpers.hpp +++ b/drape/batcher_helpers.hpp @@ -15,21 +15,21 @@ class BatchCallbacks public: virtual void FlushData(BindingInfo const & binding, void const * data, uint32_t count) = 0; virtual void * GetIndexStorage(uint32_t indexCount, uint32_t & startIndex) = 0; - virtual void SubmitIndeces() = 0; + virtual void SubmitIndices() = 0; virtual uint32_t GetAvailableVertexCount() const = 0; virtual uint32_t GetAvailableIndexCount() const = 0; virtual void ChangeBuffer() = 0; }; -class TriangleBatch +class UniversalBatch { public: - TriangleBatch(BatchCallbacks & callbacks); - virtual ~TriangleBatch(){} + UniversalBatch(BatchCallbacks & callbacks, uint8_t minVerticesCount, uint8_t minIndicesCount); + virtual ~UniversalBatch(){} virtual void BatchData(ref_ptr<AttributeProvider> streams) = 0; - void SetIsCanDevideStreams(bool canDevide); - bool IsCanDevideStreams() const; + void SetCanDevideStreams(bool canDevide); + bool CanDevideStreams() const; void SetVertexStride(uint8_t vertexStride); protected: @@ -48,21 +48,46 @@ private: BatchCallbacks & m_callbacks; bool m_canDevideStreams; uint8_t m_vertexStride; + uint8_t const m_minVerticesCount; + uint8_t const m_minIndicesCount; }; -class TriangleListBatch : public TriangleBatch +class TriangleListBatch : public UniversalBatch { - typedef TriangleBatch TBase; + using TBase = UniversalBatch; public: TriangleListBatch(BatchCallbacks & callbacks); - virtual void BatchData(ref_ptr<AttributeProvider> streams); + void BatchData(ref_ptr<AttributeProvider> streams) override; +}; + +class LineStripBatch : public UniversalBatch +{ + using TBase = UniversalBatch; + +public: + LineStripBatch(BatchCallbacks & callbacks); + + void BatchData(ref_ptr<AttributeProvider> streams) override; +}; + +class LineRawBatch : public UniversalBatch +{ + using TBase = UniversalBatch; + +public: + LineRawBatch(BatchCallbacks & callbacks, vector<int> const & indices); + + void BatchData(ref_ptr<AttributeProvider> streams) override; + +private: + vector<int> const & m_indices; }; -class FanStripHelper : public TriangleBatch +class FanStripHelper : public UniversalBatch { - typedef TriangleBatch TBase; + using TBase = UniversalBatch; public: FanStripHelper(BatchCallbacks & callbacks); @@ -85,7 +110,7 @@ private: class TriangleStripBatch : public FanStripHelper { - typedef FanStripHelper TBase; + using TBase = FanStripHelper; public: TriangleStripBatch(BatchCallbacks & callbacks); @@ -97,7 +122,7 @@ protected: class TriangleFanBatch : public FanStripHelper { - typedef FanStripHelper TBase; + using TBase = FanStripHelper; public: TriangleFanBatch(BatchCallbacks & callbacks); @@ -109,7 +134,7 @@ protected: class TriangleListOfStripBatch : public FanStripHelper { - typedef FanStripHelper TBase; + using TBase = FanStripHelper; public: TriangleListOfStripBatch(BatchCallbacks & callbacks); diff --git a/drape/color.hpp b/drape/color.hpp index 3bdd95a911..6726812266 100644 --- a/drape/color.hpp +++ b/drape/color.hpp @@ -24,6 +24,13 @@ struct Color bool operator==(Color const & other) const { return m_rgba == other.m_rgba; } 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), + GetAlfa()); + } static Color Black() { return Color(0, 0, 0, 255); } static Color White() { return Color(255, 255, 255, 255); } diff --git a/drape/drape.pro b/drape/drape.pro index 323eacc8f2..0253766c1f 100644 --- a/drape/drape.pro +++ b/drape/drape.pro @@ -13,6 +13,7 @@ SOURCES += glfunctions.cpp OTHER_FILES += \ shaders/area3d_vertex_shader.vsh \ + shaders/area3d_outline_vertex_shader.vsh \ shaders/area_vertex_shader.vsh \ shaders/arrow3d_fragment_shader.fsh \ shaders/arrow3d_shadow_fragment_shader.fsh \ diff --git a/drape/drape_tests/glfunctions.cpp b/drape/drape_tests/glfunctions.cpp index 46cbeb24ae..d92fb43f6e 100644 --- a/drape/drape_tests/glfunctions.cpp +++ b/drape/drape_tests/glfunctions.cpp @@ -264,7 +264,8 @@ void * GLFunctions::glMapBuffer(glConst, glConst) { return 0; } void GLFunctions::glUnmapBuffer(glConst target) {} -void GLFunctions::glDrawElements(uint32_t sizeOfIndex, uint32_t indexCount, uint32_t startIndex) {} +void GLFunctions::glDrawElements(glConst primitive, uint32_t sizeOfIndex, + uint32_t indexCount, uint32_t startIndex) {} void GLFunctions::glDrawArrays(glConst mode, int32_t first, uint32_t count) {} diff --git a/drape/glconstants.cpp b/drape/glconstants.cpp index 56823129f6..e934c7be71 100644 --- a/drape/glconstants.cpp +++ b/drape/glconstants.cpp @@ -201,6 +201,7 @@ const glConst GLAlways = GL_ALWAYS; const glConst GLActiveUniforms = GL_ACTIVE_UNIFORMS; +const glConst GLLines = GL_LINES; const glConst GLLineStrip = GL_LINE_STRIP; const glConst GLTriangles = GL_TRIANGLES; const glConst GLTriangleStrip = GL_TRIANGLE_STRIP; diff --git a/drape/glconstants.hpp b/drape/glconstants.hpp index aee0b8c37f..1dccc60bb8 100644 --- a/drape/glconstants.hpp +++ b/drape/glconstants.hpp @@ -153,6 +153,7 @@ extern const glConst GLAlways; extern const glConst GLActiveUniforms; /// Draw primitives +extern const glConst GLLines; extern const glConst GLLineStrip; extern const glConst GLTriangles; extern const glConst GLTriangleStrip; diff --git a/drape/glfunctions.cpp b/drape/glfunctions.cpp index 93f4e39f34..68ed7f15a5 100644 --- a/drape/glfunctions.cpp +++ b/drape/glfunctions.cpp @@ -994,9 +994,9 @@ void GLFunctions::glTexParameter(glConst param, glConst value) GLCHECK(::glTexParameteri(GL_TEXTURE_2D, param, value)); } -void GLFunctions::glDrawElements(uint32_t sizeOfIndex, uint32_t indexCount, uint32_t startIndex) +void GLFunctions::glDrawElements(glConst primitive, uint32_t sizeOfIndex, uint32_t indexCount, uint32_t startIndex) { - GLCHECK(::glDrawElements(GL_TRIANGLES, indexCount, sizeOfIndex == sizeof(uint32_t) ? GL_UNSIGNED_INT : GL_UNSIGNED_SHORT, + GLCHECK(::glDrawElements(primitive, indexCount, sizeOfIndex == sizeof(uint32_t) ? GL_UNSIGNED_INT : GL_UNSIGNED_SHORT, reinterpret_cast<GLvoid *>(startIndex * sizeOfIndex))); } diff --git a/drape/glfunctions.hpp b/drape/glfunctions.hpp index aaf38e80bb..b775f41ab9 100644 --- a/drape/glfunctions.hpp +++ b/drape/glfunctions.hpp @@ -133,7 +133,7 @@ public: static void glTexParameter(glConst param, glConst value); // Draw support - static void glDrawElements(uint32_t sizeOfIndex, uint32_t indexCount, uint32_t startIndex = 0); + static void glDrawElements(glConst primitive, uint32_t sizeOfIndex, uint32_t indexCount, uint32_t startIndex = 0); static void glDrawArrays(glConst mode, int32_t first, uint32_t count); // FBO support diff --git a/drape/glstate.cpp b/drape/glstate.cpp index 091ba984c3..cdcfff2538 100644 --- a/drape/glstate.cpp +++ b/drape/glstate.cpp @@ -52,6 +52,7 @@ GLState::GLState(uint32_t gpuProgramIndex, DepthLayer depthLayer) , m_textureFilter(gl_const::GLLinear) , m_colorTexture(nullptr) , m_maskTexture(nullptr) + , m_drawAsLine(false) { } @@ -75,6 +76,16 @@ void GLState::SetTextureFilter(glConst filter) m_textureFilter = filter; } +bool GLState::GetDrawAsLine() const +{ + return m_drawAsLine; +} + +void GLState::SetDrawAsLine(bool drawAsLine) +{ + m_drawAsLine = drawAsLine; +} + bool GLState::operator<(GLState const & other) const { if (m_depthLayer != other.m_depthLayer) @@ -89,8 +100,12 @@ bool GLState::operator<(GLState const & other) const return m_depthFunction < other.m_depthFunction; if (m_colorTexture != other.m_colorTexture) return m_colorTexture < other.m_colorTexture; + if (m_maskTexture != other.m_maskTexture) + return m_maskTexture < other.m_maskTexture; + if (m_textureFilter != other.m_textureFilter) + return m_textureFilter < other.m_textureFilter; - return m_maskTexture < other.m_maskTexture; + return m_drawAsLine < other.m_drawAsLine; } bool GLState::operator==(GLState const & other) const @@ -100,7 +115,10 @@ bool GLState::operator==(GLState const & other) const m_gpuProgram3dIndex == other.m_gpuProgram3dIndex && m_blending == other.m_blending && m_colorTexture == other.m_colorTexture && - m_maskTexture == other.m_maskTexture; + m_maskTexture == other.m_maskTexture && + m_textureFilter == other.m_textureFilter && + m_depthFunction == other.m_depthFunction && + m_drawAsLine == other.m_drawAsLine; } bool GLState::operator!=(GLState const & other) const diff --git a/drape/glstate.hpp b/drape/glstate.hpp index 5946d6f493..661461ebf4 100644 --- a/drape/glstate.hpp +++ b/drape/glstate.hpp @@ -67,6 +67,9 @@ public: glConst GetTextureFilter() const; void SetTextureFilter(glConst filter); + bool GetDrawAsLine() const; + void SetDrawAsLine(bool drawAsLine); + bool operator<(GLState const & other) const; bool operator==(GLState const & other) const; bool operator!=(GLState const & other) const; @@ -81,6 +84,8 @@ private: ref_ptr<Texture> m_colorTexture; ref_ptr<Texture> m_maskTexture; + + bool m_drawAsLine; }; void ApplyUniforms(UniformValuesStorage const & uniforms, ref_ptr<GpuProgram> program); diff --git a/drape/render_bucket.cpp b/drape/render_bucket.cpp index 7684ad5484..b0b732e37c 100644 --- a/drape/render_bucket.cpp +++ b/drape/render_bucket.cpp @@ -77,7 +77,7 @@ void RenderBucket::RemoveOverlayHandles(ref_ptr<OverlayTree> tree) tree->Remove(make_ref(overlayHandle)); } -void RenderBucket::Render() +void RenderBucket::Render(bool drawAsLine) { ASSERT(m_buffer != nullptr, ()); @@ -105,7 +105,7 @@ void RenderBucket::Render() m_buffer->ApplyMutation(hasIndexMutation ? rfpIndex : nullptr, rfpAttrib); } - m_buffer->Render(); + m_buffer->Render(drawAsLine); } void RenderBucket::SetFeatureMinZoom(int minZoom) diff --git a/drape/render_bucket.hpp b/drape/render_bucket.hpp index 5669603a1d..7c3d9a0e73 100644 --- a/drape/render_bucket.hpp +++ b/drape/render_bucket.hpp @@ -37,7 +37,7 @@ public: void Update(ScreenBase const & modelView); void CollectOverlayHandles(ref_ptr<OverlayTree> tree); void RemoveOverlayHandles(ref_ptr<OverlayTree> tree); - void Render(); + void Render(bool drawAsLine); // Only for testing! Don't use this function in production code! void RenderDebug(ScreenBase const & screen) const; diff --git a/drape/shaders/area3d_outline_vertex_shader.vsh b/drape/shaders/area3d_outline_vertex_shader.vsh new file mode 100644 index 0000000000..7c1fa01717 --- /dev/null +++ b/drape/shaders/area3d_outline_vertex_shader.vsh @@ -0,0 +1,28 @@ +attribute vec3 a_position; +attribute vec2 a_colorTexCoords; + +uniform mat4 modelView; +uniform mat4 projection; +uniform mat4 pivotTransform; +uniform float zScale; + +#ifdef ENABLE_VTF +uniform sampler2D u_colorTex; +varying lowp vec4 v_color; +#else +varying vec2 v_colorTexCoords; +#endif + +void main(void) +{ + vec4 pos = vec4(a_position, 1.0) * modelView; + pos.xyw = (pos * projection).xyw; + pos.z = a_position.z * zScale; + gl_Position = pivotTransform * pos; + +#ifdef ENABLE_VTF + v_color = texture2D(u_colorTex, a_colorTexCoords); +#else + v_colorTexCoords = a_colorTexCoords; +#endif +} diff --git a/drape/shaders/shader_index.txt b/drape/shaders/shader_index.txt index 2b191117d5..62b1ad476e 100644 --- a/drape/shaders/shader_index.txt +++ b/drape/shaders/shader_index.txt @@ -2,7 +2,9 @@ TEXT_OUTLINED_PROGRAM text_outlined_vertex_shader.vsh text_fragment_shader.fsh TEXT_PROGRAM text_vertex_shader.vsh text_fragment_shader.fsh TEXT_OUTLINED_GUI_PROGRAM text_outlined_gui_vertex_shader.vsh text_fragment_shader.fsh AREA_PROGRAM area_vertex_shader.vsh solid_color_fragment_shader.fsh +AREA_OUTLINE_PROGRAM area_vertex_shader.vsh solid_color_fragment_shader.fsh AREA_3D_PROGRAM area3d_vertex_shader.vsh texturing3d_fragment_shader.fsh +AREA_3D_OUTLINE_PROGRAM area3d_outline_vertex_shader.vsh solid_color_fragment_shader.fsh TEXTURING_PROGRAM texturing_vertex_shader.vsh texturing_fragment_shader.fsh MASKED_TEXTURING_PROGRAM masked_texturing_vertex_shader.vsh masked_texturing_fragment_shader.fsh LINE_PROGRAM line_vertex_shader.vsh line_fragment_shader.fsh diff --git a/drape/vertex_array_buffer.cpp b/drape/vertex_array_buffer.cpp index e4dab7b1af..b812881732 100644 --- a/drape/vertex_array_buffer.cpp +++ b/drape/vertex_array_buffer.cpp @@ -67,12 +67,12 @@ void VertexArrayBuffer::PreflushImpl() m_isPreflushed = true; } -void VertexArrayBuffer::Render() +void VertexArrayBuffer::Render(bool drawAsLine) { - RenderRange(IndicesRange(0, GetIndexBuffer()->GetCurrentSize())); + RenderRange(drawAsLine, IndicesRange(0, GetIndexBuffer()->GetCurrentSize())); } -void VertexArrayBuffer::RenderRange(IndicesRange const & range) +void VertexArrayBuffer::RenderRange(bool drawAsLine, IndicesRange const & range) { if (!(m_staticBuffers.empty() && m_dynamicBuffers.empty()) && GetIndexCount() > 0) { @@ -84,7 +84,9 @@ void VertexArrayBuffer::RenderRange(IndicesRange const & range) BindDynamicBuffers(); GetIndexBuffer()->Bind(); - GLFunctions::glDrawElements(dp::IndexStorage::SizeOfIndex(), range.m_idxCount, range.m_idxStart); + GLFunctions::glDrawElements(drawAsLine ? gl_const::GLLines : gl_const::GLTriangles, + dp::IndexStorage::SizeOfIndex(), + range.m_idxCount, range.m_idxStart); Unbind(); } @@ -224,7 +226,7 @@ uint32_t VertexArrayBuffer::GetIndexCount() const void VertexArrayBuffer::UploadIndexes(void const * data, uint32_t count) { - ASSERT(count <= GetIndexBuffer()->GetAvailableSize(), ()); + ASSERT_LESS_OR_EQUAL(count, GetIndexBuffer()->GetAvailableSize(), ()); GetIndexBuffer()->UploadData(data, count); } diff --git a/drape/vertex_array_buffer.hpp b/drape/vertex_array_buffer.hpp index 8ba2db50f2..baab293954 100644 --- a/drape/vertex_array_buffer.hpp +++ b/drape/vertex_array_buffer.hpp @@ -49,8 +49,8 @@ public: /// On devices where implemented OES_vertex_array_object extensions we use it for build VertexArrayBuffer /// OES_vertex_array_object create OpenGL resource that belong only one GL context (which was created by) /// by this reason Build/Bind and Render must be called only on Frontendrendere thread - void Render(); - void RenderRange(IndicesRange const & range); + void Render(bool drawAsLine); + void RenderRange(bool drawAsLine, IndicesRange const & range); void Build(ref_ptr<GpuProgram> program); ///@} |