X-Git-Url: https://git.ucc.asn.au/?p=ipdf%2Fcode.git;a=blobdiff_plain;f=src%2Fview.cpp;h=02859c5abbd09642b1bdd634ca2003f4c095ada0;hp=4dbe5df91a5a99032d42f02c6dc6a5c6f8b4b61f;hb=2db1211c9a24a0cd22da1d3ddcddf564f814fc0a;hpb=47c305b00cc92169d826b0ca5268c92b1d019e28 diff --git a/src/view.cpp b/src/view.cpp index 4dbe5df..02859c5 100644 --- a/src/view.cpp +++ b/src/view.cpp @@ -32,6 +32,12 @@ View::View(Document & document, Screen & screen, const Rect & bounds, const Colo // 2. Implement class inheriting from ObjectRenderer using that type in objectrenderer.h and objectrenderer.cpp // 3. Add it here // 4. Profit + + +#ifndef QUADTREE_DISABLED + m_quadtree_max_depth = 1; + m_current_quadtree_node = document.GetQuadTree().root_id; +#endif } /** @@ -118,6 +124,28 @@ Rect View::TransformToViewCoords(const Rect& inp) const * @param height - Height of View to render */ void View::Render(int width, int height) +{ +#ifdef QUADTREE_DISABLED + RenderRange(width, height, 0, m_document.ObjectCount()); +#else + RenderQuadtreeNode(width, height, m_current_quadtree_node, m_quadtree_max_depth); +#endif +} + +#ifndef QUADTREE_DISABLED +void View::RenderQuadtreeNode(int width, int height, QuadTreeIndex node, int remaining_depth) +{ + if (node == QUADTREE_EMPTY) return; + if (!remaining_depth) return; + RenderRange(width, height, m_document.GetQuadTree().nodes[node].object_begin, m_document.GetQuadTree().nodes[node].object_end); + RenderQuadtreeNode(width, height, m_document.GetQuadTree().nodes[node].top_left, remaining_depth-1); + RenderQuadtreeNode(width, height, m_document.GetQuadTree().nodes[node].top_right, remaining_depth-1); + RenderQuadtreeNode(width, height, m_document.GetQuadTree().nodes[node].bottom_left, remaining_depth-1); + RenderQuadtreeNode(width, height, m_document.GetQuadTree().nodes[node].bottom_right, remaining_depth-1); +} +#endif + +void View::RenderRange(int width, int height, unsigned first_obj, unsigned last_obj) { // View dimensions have changed (ie: Window was resized) int prev_width = m_cached_display.GetWidth(); @@ -162,10 +190,6 @@ void View::Render(int width, int height) m_cached_display.Bind(); //NOTE: This is redundant; Clear already calls Bind m_cached_display.Clear(); - // When we QuadTree, this will be magic. - int first_obj = 0; - int last_obj = m_document.ObjectCount(); - // Render using GPU if (m_use_gpu_rendering) { @@ -206,7 +230,7 @@ void View::Render(int width, int height) for (unsigned i = 0; i < m_object_renderers.size(); ++i) { - m_object_renderers[i]->RenderUsingCPU(m_document.m_objects, *this, {m_cpu_rendering_pixels, width, height}); + m_object_renderers[i]->RenderUsingCPU(m_document.m_objects, *this, {m_cpu_rendering_pixels, width, height}, first_obj, last_obj); } m_screen.RenderPixels(0,0,width, height, m_cpu_rendering_pixels); //TODO: Make this work :( // Debug for great victory (do something similar for GPU and compare?)