From: David Gow Date: Tue, 12 Aug 2014 14:07:56 +0000 (+0800) Subject: Still-broken quadtree shenanigans! X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=b8c16a61fc9df50a0254aeeb8875421836194981;p=ipdf%2Fcode.git Still-broken quadtree shenanigans! Quadtrees are, therefore, still disabled by default. --- diff --git a/src/document.cpp b/src/document.cpp index 6c281c1..cb52986 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -95,7 +95,6 @@ void Document::GenBaseQuadtree() m_quadtree.nodes.push_back(QuadTreeNode{QUADTREE_EMPTY, QUADTREE_EMPTY, QUADTREE_EMPTY, QUADTREE_EMPTY, QUADTREE_EMPTY, QTC_UNKNOWN, 0, ObjectCount()}); m_quadtree.root_id = 0; GenQuadChild(0, QTC_TOP_LEFT); - GenQuadParent(0, QTC_BOTTOM_RIGHT); } QuadTreeIndex Document::GenQuadChild(QuadTreeIndex parent, QuadTreeNodeChildren type) diff --git a/src/graphicsbuffer.cpp b/src/graphicsbuffer.cpp index d3911db..da522dc 100644 --- a/src/graphicsbuffer.cpp +++ b/src/graphicsbuffer.cpp @@ -263,3 +263,7 @@ void GraphicsBuffer::Bind() const glBindBuffer(BufferTypeToGLType(m_buffer_type), m_buffer_handle); } +void GraphicsBuffer::BindRange(size_t start, size_t size) const +{ + glBindBufferRange(BufferTypeToGLType(m_buffer_type), 0, m_buffer_handle, start, size); +} diff --git a/src/graphicsbuffer.h b/src/graphicsbuffer.h index fd89771..b102c51 100644 --- a/src/graphicsbuffer.h +++ b/src/graphicsbuffer.h @@ -63,6 +63,7 @@ namespace IPDF GLuint GetHandle() const { return m_buffer_handle; } void Bind() const; + void BindRange(size_t start, size_t size) const; private: bool RecreateBuffer(const void *data = NULL); GLuint m_buffer_handle; diff --git a/src/view.cpp b/src/view.cpp index 4bbe5f0..004664b 100644 --- a/src/view.cpp +++ b/src/view.cpp @@ -146,6 +146,22 @@ void View::Render(int width, int height) m_cached_display.Bind(); //NOTE: This is redundant; Clear already calls Bind m_cached_display.Clear(); +#ifndef QUADTREE_DISABLED + if (m_bounds_dirty) + { + if (ContainedInQuadChild(m_bounds, QTC_TOP_LEFT) && m_document.GetQuadTree().nodes[m_current_quadtree_node].top_left != QUADTREE_EMPTY) + { + m_bounds = TransformToQuadChild(m_bounds, QTC_TOP_LEFT); + m_current_quadtree_node = m_document.GetQuadTree().nodes[m_current_quadtree_node].top_left; + } + if ((m_bounds.w > 1 || m_bounds.h > 1) && m_document.GetQuadTree().nodes[m_current_quadtree_node].parent != QUADTREE_EMPTY) + { + m_bounds = TransformFromQuadChild(m_bounds, m_document.GetQuadTree().nodes[m_current_quadtree_node].child_type); + m_current_quadtree_node = m_document.GetQuadTree().nodes[m_current_quadtree_node].parent; + } + } + m_screen.DebugFontPrintF("Current View QuadTree Node: %d\n", m_current_quadtree_node); +#endif if (!m_use_gpu_rendering) { @@ -184,6 +200,7 @@ void View::RenderQuadtreeNode(int width, int height, QuadTreeIndex node, int rem if (node == QUADTREE_EMPTY) return; if (!remaining_depth) return; //Debug("Rendering QT node %d, (objs: %d -- %d)\n", node, m_document.GetQuadTree().nodes[node].object_begin, m_document.GetQuadTree().nodes[node].object_end); + m_bounds_dirty = true; RenderRange(width, height, m_document.GetQuadTree().nodes[node].object_begin, m_document.GetQuadTree().nodes[node].object_end); m_bounds = TransformToQuadChild(old_bounds, QTC_TOP_LEFT); @@ -205,11 +222,10 @@ void View::RenderQuadtreeNode(int width, int height, QuadTreeIndex node, int rem void View::RenderRange(int width, int height, unsigned first_obj, unsigned last_obj) { - if (m_render_dirty) // document has changed PrepareRender(); - if (m_buffer_dirty) // object bounds have changed + if (m_buffer_dirty || m_bounds_dirty) // object bounds have changed UpdateObjBoundsVBO(first_obj, last_obj); if (m_use_gpu_transform) @@ -275,7 +291,7 @@ void View::UpdateObjBoundsVBO(unsigned first_obj, unsigned last_obj) } m_objbounds_vbo.Resize(m_document.ObjectCount()*sizeof(GPUObjBounds)); - BufferBuilder obj_bounds_builder(m_objbounds_vbo.MapRange(first_obj*sizeof(GPUObjBounds), (last_obj-first_obj)*sizeof(GPUObjBounds), false, true, true), m_objbounds_vbo.GetSize()); + BufferBuilder obj_bounds_builder(m_objbounds_vbo.MapRange(first_obj*sizeof(GPUObjBounds), (last_obj-first_obj)*sizeof(GPUObjBounds), false, true, false), m_objbounds_vbo.GetSize()); for (unsigned id = first_obj; id < last_obj; ++id) { diff --git a/src/view.h b/src/view.h index ec5e97f..e4254de 100644 --- a/src/view.h +++ b/src/view.h @@ -48,7 +48,7 @@ namespace IPDF { float x0, y0; float x1, y1; - }; + } __attribute__((packed)); void PrepareRender(); // call when m_render_dirty is true void UpdateObjBoundsVBO(unsigned first_obj, unsigned last_obj); // call when m_buffer_dirty is true