From 9c1685dc4646f9a095fe0595e5832ae15a5db461 Mon Sep 17 00:00:00 2001 From: exmix Date: Sat, 12 Jul 2014 22:00:58 +0200 Subject: [PATCH] [drape] review fixes --- data/test_scene.json | 8 +- drape/attribute_buffer_mutator.hpp | 8 +- drape/gpu_buffer.cpp | 8 +- drape/overlay_handle.cpp | 8 +- drape/overlay_handle.hpp | 8 +- drape/pointers.hpp | 4 +- drape/vertex_array_buffer.cpp | 56 ++++---- drape/vertex_array_buffer.hpp | 18 +-- drape_frontend/circle_shape.cpp | 6 +- drape_head/testing_engine.cpp | 199 +++++++++++++++-------------- 10 files changed, 168 insertions(+), 155 deletions(-) diff --git a/data/test_scene.json b/data/test_scene.json index 29d43ea5aa..3a0c801cc3 100644 --- a/data/test_scene.json +++ b/data/test_scene.json @@ -40,10 +40,8 @@ "color":[255, 255, 0, 255], "geometry":[300, 300, 200, 300, 200, 200, 300, 300, 200, 200, 300, 200] }, - "circle":{ - "depth" : 10.0, - "color" : [30, 255, 10, 255], - "radius": 55.0, - "geometry" : [500, 200] + "dyn_square":{ + "geometry":[500, 800], + "radius":30.0 } } \ No newline at end of file diff --git a/drape/attribute_buffer_mutator.hpp b/drape/attribute_buffer_mutator.hpp index a661e7e173..bc80b60196 100644 --- a/drape/attribute_buffer_mutator.hpp +++ b/drape/attribute_buffer_mutator.hpp @@ -23,15 +23,15 @@ struct MutateNode class AttributeBufferMutator { - typedef vector mutate_nodes_t; - typedef map mutate_data_t; + typedef vector TMutateNodes; + typedef map TMutateData; public: void AddMutation(BindingInfo const & info, MutateNode const & node); private: friend class VertexArrayBuffer; - mutate_data_t const & GetMutateData() const { return m_data; } + TMutateData const & GetMutateData() const { return m_data; } private: - mutate_data_t m_data; + TMutateData m_data; }; diff --git a/drape/gpu_buffer.cpp b/drape/gpu_buffer.cpp index f7a235cfca..f54db000ab 100644 --- a/drape/gpu_buffer.cpp +++ b/drape/gpu_buffer.cpp @@ -8,7 +8,7 @@ namespace { bool IsMapBufferSupported() { - static bool isSupported = GLExtensionsList::Instance().IsSupported(GLExtensionsList::MapBuffer); + static bool const isSupported = GLExtensionsList::Instance().IsSupported(GLExtensionsList::MapBuffer); return isSupported; } } @@ -69,9 +69,9 @@ void * GPUBuffer::Map() void GPUBuffer::UpdateData(void * gpuPtr, void const * data, uint16_t elementOffset, uint16_t elementCount) { - uint16_t elementSize = GetElementSize(); - uint32_t byteOffset = elementOffset * (uint32_t)elementSize; - uint32_t byteCount = elementCount * (uint32_t)elementSize; + uint16_t const elementSize = GetElementSize(); + uint32_t const byteOffset = elementOffset * (uint32_t)elementSize; + uint32_t const byteCount = elementCount * (uint32_t)elementSize; ASSERT(m_isMapped == true, ()); if (IsMapBufferSupported()) { diff --git a/drape/overlay_handle.cpp b/drape/overlay_handle.cpp index cff854efd3..609d788133 100644 --- a/drape/overlay_handle.cpp +++ b/drape/overlay_handle.cpp @@ -7,7 +7,7 @@ struct OverlayHandle::OffsetNodeFinder public: OffsetNodeFinder(uint8_t bufferID) : m_bufferID(bufferID) {} - bool operator()(OverlayHandle::offset_node_t const & node) + bool operator()(OverlayHandle::TOffsetNode const & node) const { return node.first.GetID() == m_bufferID; } @@ -80,9 +80,9 @@ double const & OverlayHandle::GetPriority() const return m_priority; } -OverlayHandle::offset_node_t const & OverlayHandle::GetOffsetNode(uint8_t bufferID) const +OverlayHandle::TOffsetNode const & OverlayHandle::GetOffsetNode(uint8_t bufferID) const { - set::const_iterator it = find_if(m_offsets.begin(), m_offsets.end(), OffsetNodeFinder(bufferID)); + set::const_iterator it = find_if(m_offsets.begin(), m_offsets.end(), OffsetNodeFinder(bufferID)); ASSERT(it != m_offsets.end(), ()); return *it; } @@ -100,7 +100,7 @@ SquareHandle::SquareHandle(FeatureID const & id, OverlayHandle::Anchor anchor, m2::RectD SquareHandle::GetPixelRect(ScreenBase const & screen) const { - m2::PointD pxPivot = screen.GtoP(m_gbPivot); + m2::PointD const pxPivot = screen.GtoP(m_gbPivot); m2::RectD result(pxPivot - m_pxHalfSize, pxPivot + m_pxHalfSize); m2::PointD offset(0.0, 0.0); diff --git a/drape/overlay_handle.hpp b/drape/overlay_handle.hpp index dbdefa5859..b22bc04ea8 100644 --- a/drape/overlay_handle.hpp +++ b/drape/overlay_handle.hpp @@ -54,8 +54,8 @@ protected: Anchor const m_anchor; double const m_priority; - typedef pair offset_node_t; - offset_node_t const & GetOffsetNode(uint8_t bufferID) const; + typedef pair TOffsetNode; + TOffsetNode const & GetOffsetNode(uint8_t bufferID) const; private: bool m_isVisible; @@ -63,7 +63,7 @@ private: vector m_indexes; struct LessOffsetNode { - bool operator()(offset_node_t const & node1, offset_node_t const & node2) const + bool operator()(TOffsetNode const & node1, TOffsetNode const & node2) const { return node1.first.GetID() < node2.first.GetID(); } @@ -71,7 +71,7 @@ private: struct OffsetNodeFinder; - set m_offsets; + set m_offsets; }; class SquareHandle : public OverlayHandle diff --git a/drape/pointers.hpp b/drape/pointers.hpp index a2d60bf3b9..bf46924b91 100644 --- a/drape/pointers.hpp +++ b/drape/pointers.hpp @@ -39,9 +39,9 @@ private: threads::Mutex m_mutex; }; -#define FAST_DEBUG +#define DISABLE_DEBUG_PRT_TRACKING -#if defined(DEBUG) && !defined(FAST_DEBUG) +#if defined(DEBUG) && !defined(DISABLE_DEBUG_PRT_TRACKING) #define CHECK_POINTERS #endif diff --git a/drape/vertex_array_buffer.cpp b/drape/vertex_array_buffer.cpp index dbe4afc71d..4477fbb0af 100644 --- a/drape/vertex_array_buffer.cpp +++ b/drape/vertex_array_buffer.cpp @@ -75,34 +75,46 @@ void VertexArrayBuffer::UploadData(BindingInfo const & bindingInfo, void const * RefPointer VertexArrayBuffer::GetOrCreateDynamicBuffer(BindingInfo const & bindingInfo) { - return GetOrCreateBuffer(bindingInfo, m_dynamicBuffers); + return GetOrCreateBuffer(bindingInfo, true); } RefPointer VertexArrayBuffer::GetDynamicBuffer(BindingInfo const & bindingInfo) const { - return GetBuffer(bindingInfo, m_dynamicBuffers); + return GetBuffer(bindingInfo, true); } RefPointer VertexArrayBuffer::GetOrCreateStaticBuffer(BindingInfo const & bindingInfo) { - return GetOrCreateBuffer(bindingInfo, m_staticBuffers); + return GetOrCreateBuffer(bindingInfo, false); } -RefPointer VertexArrayBuffer::GetBuffer(BindingInfo const & bindingInfo, const buffers_map_t & buffers) const +RefPointer VertexArrayBuffer::GetBuffer(BindingInfo const & bindingInfo, bool isDynamic) const { - buffers_map_t::const_iterator it = buffers.find(bindingInfo); - if (it == buffers.end()) + TBuffersMap const * buffers = NULL; + if (isDynamic) + buffers = &m_dynamicBuffers; + else + buffers = &m_staticBuffers; + + TBuffersMap::const_iterator it = buffers->find(bindingInfo); + if (it == buffers->end()) return RefPointer(); return it->second.GetRefPointer(); } -RefPointer VertexArrayBuffer::GetOrCreateBuffer(BindingInfo const & bindingInfo, buffers_map_t & buffers) +RefPointer VertexArrayBuffer::GetOrCreateBuffer(BindingInfo const & bindingInfo, bool isDynamic) { - buffers_map_t::iterator it = buffers.find(bindingInfo); - if (it == buffers.end()) + TBuffersMap * buffers = NULL; + if (isDynamic) + buffers = &m_dynamicBuffers; + else + buffers = &m_staticBuffers; + + TBuffersMap::iterator it = buffers->find(bindingInfo); + if (it == buffers->end()) { - MasterPointer & buffer = buffers[bindingInfo]; + MasterPointer & buffer = (*buffers)[bindingInfo]; buffer.Reset(new DataBuffer(bindingInfo.GetElementSize(), m_dataBufferSize)); return buffer.GetRefPointer(); } @@ -121,7 +133,7 @@ uint16_t VertexArrayBuffer::GetAvailableVertexCount() const return m_dataBufferSize; #ifdef DEBUG - buffers_map_t::const_iterator it = m_staticBuffers.begin(); + TBuffersMap::const_iterator it = m_staticBuffers.begin(); uint16_t prev = it->second->GetAvailableSize(); for (; it != m_staticBuffers.end(); ++it) ASSERT(prev == it->second->GetAvailableSize(), ()); @@ -136,7 +148,7 @@ uint16_t VertexArrayBuffer::GetStartIndexValue() const return 0; #ifdef DEBUG - buffers_map_t::const_iterator it = m_staticBuffers.begin(); + TBuffersMap::const_iterator it = m_staticBuffers.begin(); uint16_t prev = it->second->GetCurrentSize(); for (; it != m_staticBuffers.end(); ++it) ASSERT(prev == it->second->GetCurrentSize(), ()); @@ -166,15 +178,15 @@ void VertexArrayBuffer::ApplyMutation(RefPointer indexMutato { m_indexBuffer->UpdateData(indexMutator->GetIndexes(), indexMutator->GetIndexCount()); - typedef AttributeBufferMutator::mutate_data_t mutate_data_t; - typedef AttributeBufferMutator::mutate_nodes_t mutate_nodes_t; - mutate_data_t const & data = attrMutator->GetMutateData(); - for (mutate_data_t::const_iterator it = data.begin(); it != data.end(); ++it) + typedef AttributeBufferMutator::TMutateData TMutateData; + typedef AttributeBufferMutator::TMutateNodes TMutateNodes; + TMutateData const & data = attrMutator->GetMutateData(); + for (TMutateData::const_iterator it = data.begin(); it != data.end(); ++it) { RefPointer buffer = GetDynamicBuffer(it->first); ASSERT(!buffer.IsNull(), ()); GPUBufferMapper mapper(buffer); - mutate_nodes_t const & nodes = it->second; + TMutateNodes const & nodes = it->second; for (size_t i = 0; i < nodes.size(); ++i) { @@ -184,25 +196,25 @@ void VertexArrayBuffer::ApplyMutation(RefPointer indexMutato } } -void VertexArrayBuffer::Bind() +void VertexArrayBuffer::Bind() const { ASSERT(m_VAO != 0, ("You need to call Build method before bind it and render")); GLFunctions::glBindVertexArray(m_VAO); } -void VertexArrayBuffer::BindStaticBuffers() +void VertexArrayBuffer::BindStaticBuffers() const { BindBuffers(m_staticBuffers); } -void VertexArrayBuffer::BindDynamicBuffers() +void VertexArrayBuffer::BindDynamicBuffers() const { BindBuffers(m_dynamicBuffers); } -void VertexArrayBuffer::BindBuffers(buffers_map_t const & buffers) +void VertexArrayBuffer::BindBuffers(TBuffersMap const & buffers) const { - buffers_map_t::const_iterator it = buffers.begin(); + TBuffersMap::const_iterator it = buffers.begin(); for (; it != buffers.end(); ++it) { BindingInfo const & binding = it->first; diff --git a/drape/vertex_array_buffer.hpp b/drape/vertex_array_buffer.hpp index fe6b88fcf3..90f09ebbf7 100644 --- a/drape/vertex_array_buffer.hpp +++ b/drape/vertex_array_buffer.hpp @@ -12,7 +12,7 @@ class VertexArrayBuffer { - typedef map > buffers_map_t; + typedef map > TBuffersMap; public: VertexArrayBuffer(uint32_t indexBufferSize, uint32_t dataBufferSize); ~VertexArrayBuffer(); @@ -42,17 +42,17 @@ private: RefPointer GetOrCreateDynamicBuffer(BindingInfo const & bindingInfo); RefPointer GetDynamicBuffer(BindingInfo const & bindingInfo) const; - RefPointer GetOrCreateBuffer(BindingInfo const & bindingInfo, buffers_map_t & buffers); - RefPointer GetBuffer(BindingInfo const & bindingInfo, buffers_map_t const & buffers) const; - void Bind(); - void BindStaticBuffers(); - void BindDynamicBuffers(); - void BindBuffers(buffers_map_t const & buffers); + RefPointer GetOrCreateBuffer(BindingInfo const & bindingInfo, bool isDynamic); + RefPointer GetBuffer(BindingInfo const & bindingInfo, bool isDynamic) const; + void Bind() const; + void BindStaticBuffers() const; + void BindDynamicBuffers() const; + void BindBuffers(TBuffersMap const & buffers) const; private: int m_VAO; - buffers_map_t m_staticBuffers; - buffers_map_t m_dynamicBuffers; + TBuffersMap m_staticBuffers; + TBuffersMap m_dynamicBuffers; MasterPointer m_indexBuffer; uint32_t m_dataBufferSize; diff --git a/drape_frontend/circle_shape.cpp b/drape_frontend/circle_shape.cpp index 0b62322c2c..3dcc5b6ed3 100644 --- a/drape_frontend/circle_shape.cpp +++ b/drape_frontend/circle_shape.cpp @@ -75,9 +75,9 @@ void CircleShape::Draw(RefPointer batcher, RefPointer normalDecl.m_stride = 5 * sizeof(float); OverlayHandle * overlay = new SquareHandle(m_params.m_id, - OverlayHandle::Center, m_pt, - m2::PointD(m_params.m_radius, m_params.m_radius), - m_params.m_depth); + OverlayHandle::Center, m_pt, + m2::PointD(m_params.m_radius, m_params.m_radius), + m_params.m_depth); provider.InitStream(0, info, MakeStackRefPointer(&stream[0])); batcher->InsertTriangleFan(state, MakeStackRefPointer(&provider), MovePointer(overlay)); diff --git a/drape_head/testing_engine.cpp b/drape_head/testing_engine.cpp index e369c3095c..0f330372f1 100644 --- a/drape_head/testing_engine.cpp +++ b/drape_head/testing_engine.cpp @@ -25,6 +25,95 @@ namespace df { +class SquareHandle : public OverlayHandle +{ +public: + static const uint8_t NormalAttributeID = 1; + SquareHandle(vector const & formingVector) + : OverlayHandle(FeatureID(), OverlayHandle::Center, 0.0f) + , m_vectors(formingVector) + { + SetIsVisible(true); + } + + virtual m2::RectD GetPixelRect(ScreenBase const & screen) const { return m2::RectD(); } + + virtual void GetAttributeMutation(RefPointer mutator) const + { + static const my::Timer timer; + double const angle = timer.ElapsedSeconds(); + + math::Matrix const m = math::Rotate(math::Identity(), angle); + + vector data(4); + for (size_t i = 0; i < m_vectors.size(); ++i) + data[i] = m_vectors[i] * m; + + TOffsetNode const & node = GetOffsetNode(NormalAttributeID); + MutateNode mutateNode; + mutateNode.m_region = node.second; + mutateNode.m_data = MakeStackRefPointer(&data[0]); + mutator->AddMutation(node.first, mutateNode); + } + +private: + vector m_vectors; +}; + +class SquareShape : public MapShape +{ +public: + SquareShape(m2::PointF const & center, float radius) + : m_center(center) + , m_radius(radius) + { + } + + virtual void Draw(RefPointer batcher, RefPointer textures) const + { + vector vertexes(4, m_center); + + vector formingVectors(4); + formingVectors[0] = m2::PointF(-m_radius, m_radius); + formingVectors[1] = m2::PointF(-m_radius, -m_radius); + formingVectors[2] = m2::PointF( m_radius, m_radius); + formingVectors[3] = m2::PointF( m_radius, -m_radius); + + AttributeProvider provider(2, 4); + { + BindingInfo info(1); + BindingDecl & decl = info.GetBindingDecl(0); + decl.m_attributeName = "a_position"; + decl.m_componentCount = 2; + decl.m_componentType = gl_const::GLFloatType; + decl.m_offset = 0; + decl.m_stride = 0; + provider.InitStream(0, info, MakeStackRefPointer(&vertexes[0])); + } + { + BindingInfo info(1, SquareHandle::NormalAttributeID); + BindingDecl & decl = info.GetBindingDecl(0); + decl.m_attributeName = "a_normal"; + decl.m_componentCount = 2; + decl.m_componentType = gl_const::GLFloatType; + decl.m_offset = 0; + decl.m_stride = 0; + provider.InitStream(1, info, MakeStackRefPointer(&formingVectors[0])); + } + + GLState state(gpu::TEST_DYN_ATTR_PROGRAM, GLState::GeometryLayer); + state.SetColor(Color(150, 130, 120, 255)); + + OverlayHandle * handle = new SquareHandle(formingVectors); + + batcher->InsertTriangleStrip(state, MakeStackRefPointer(&provider), MovePointer(handle)); + } + +private: + m2::PointF m_center; + float m_radius; +}; + class MapShapeFactory { typedef function TCreateFn; @@ -132,9 +221,10 @@ private: MapShape * CreateDynSquare(json_t * object) { - /// TODO - ASSERT(false, ()); - return NULL; + float radius = json_real_value(json_object_get(object, "radius")); + vector point; + ParseGeometry(json_object_get(object, "geometry"), point); + return new SquareShape(point[0], radius); } MapShape * CreateCircle(json_t * object) @@ -153,97 +243,6 @@ private: TCreatorsMap m_creators; }; -class SquareHandle : public OverlayHandle -{ -public: - static const uint8_t NormalAttributeID = 1; - SquareHandle(vector const & formingVector) - : OverlayHandle(FeatureID(), OverlayHandle::Center, 0.0f) - , m_vectors(formingVector) - { - SetIsVisible(true); - } - - virtual m2::RectD GetPixelRect(ScreenBase const & screen) const { return m2::RectD(); } - - virtual void GetAttributeMutation(RefPointer mutator) const - { - static my::Timer timer; - double angle = timer.ElapsedSeconds(); - - math::Matrix m = math::Rotate(math::Identity(), angle); - - vector data(4); - for (size_t i = 0; i < m_vectors.size(); ++i) - { - data[i] = m_vectors[i] * m; - } - - offset_node_t const & node = GetOffsetNode(NormalAttributeID); - MutateNode mutateNode; - mutateNode.m_region = node.second; - mutateNode.m_data = MakeStackRefPointer(&data[0]); - mutator->AddMutation(node.first, mutateNode); - } - -private: - vector m_vectors; -}; - -class SquareShape : public MapShape -{ -public: - SquareShape(m2::PointF const & center, float radius) - : m_center(center) - , m_radius(radius) - { - } - - virtual void Draw(RefPointer batcher, RefPointer textures) const - { - vector vertexes(4, m_center); - - vector formingVectors(4); - formingVectors[0] = m2::PointF(-m_radius, m_radius); - formingVectors[1] = m2::PointF(-m_radius, -m_radius); - formingVectors[2] = m2::PointF( m_radius, m_radius); - formingVectors[3] = m2::PointF( m_radius, -m_radius); - - AttributeProvider provider(2, 4); - { - BindingInfo info(1); - BindingDecl & decl = info.GetBindingDecl(0); - decl.m_attributeName = "a_position"; - decl.m_componentCount = 2; - decl.m_componentType = gl_const::GLFloatType; - decl.m_offset = 0; - decl.m_stride = 0; - provider.InitStream(0, info, MakeStackRefPointer(&vertexes[0])); - } - { - BindingInfo info(1, SquareHandle::NormalAttributeID); - BindingDecl & decl = info.GetBindingDecl(0); - decl.m_attributeName = "a_normal"; - decl.m_componentCount = 2; - decl.m_componentType = gl_const::GLFloatType; - decl.m_offset = 0; - decl.m_stride = 0; - provider.InitStream(1, info, MakeStackRefPointer(&formingVectors[0])); - } - - GLState state(gpu::TEST_DYN_ATTR_PROGRAM, GLState::GeometryLayer); - state.SetColor(Color(150, 130, 120, 255)); - - OverlayHandle * handle = new SquareHandle(formingVectors); - - batcher->InsertTriangleStrip(state, MakeStackRefPointer(&provider), MovePointer(handle)); - } - -private: - m2::PointF m_center; - float m_radius; -}; - TestingEngine::TestingEngine(RefPointer oglcontextfactory, double vs, df::Viewport const & viewport) : m_contextFactory(oglcontextfactory) @@ -276,10 +275,14 @@ TestingEngine::~TestingEngine() void TestingEngine::Draw() { - ClearScene(); - m_batcher->StartSession(bind(&df::TestingEngine::OnFlushData, this, _1, _2)); - DrawImpl(); - m_batcher->EndSession(); + static bool isInitialized = false; + if (!isInitialized) + { + m_batcher->StartSession(bind(&df::TestingEngine::OnFlushData, this, _1, _2)); + DrawImpl(); + m_batcher->EndSession(); + isInitialized = true; + } OGLContext * context = m_contextFactory->getDrawContext(); context->setDefaultFramebuffer();