Add #define to transform Object bounds on the fly
[ipdf/code.git] / src / view.cpp
1 #include "view.h"
2 #include "bufferbuilder.h"
3 #include "screen.h"
4 #include "gl_core44.h"
5
6 #ifndef CONTROLPANEL_DISABLED
7         #include "controlpanel.h"
8 #endif //CONTROLPANEL_DISABLED
9
10 using namespace IPDF;
11 using namespace std;
12
13 /**
14  * Constructs a view
15  * Allocates memory for ObjectRenderers
16  * @param document - The document to associate the View with
17  * @param bounds - Initial bounds of the View
18  * @param colour - Colour to use for rendering this view. TODO: Make sure this actually works, or just remove it
19  */
20 View::View(Document & document, Screen & screen, const Rect & bounds, const Colour & colour)
21         : m_use_gpu_transform(USE_GPU_TRANSFORM), m_use_gpu_rendering(USE_GPU_RENDERING), m_bounds_dirty(true), m_buffer_dirty(true), 
22                 m_render_dirty(true), m_document(document), m_screen(screen), m_cached_display(), m_bounds(bounds), m_colour(colour), m_bounds_ubo(), 
23                 m_objbounds_vbo(), m_object_renderers(NUMBER_OF_OBJECT_TYPES), m_cpu_rendering_pixels(NULL),
24                 m_perform_shading(USE_SHADING), m_show_bezier_bounds(false), m_show_bezier_type(false),
25                 m_show_fill_points(false), m_show_fill_bounds(false), m_lazy_rendering(true)
26 {
27         Debug("View Created - Bounds => {%s}", m_bounds.Str().c_str());
28
29         screen.SetView(this); // oh dear...
30
31         
32
33         // Create ObjectRenderers - new's match delete's in View::~View
34         //TODO: Don't forget to put new renderers here or things will be segfaultastic
35         if (screen.Valid())
36         {
37                 m_object_renderers[RECT_FILLED] = new RectFilledRenderer();
38                 m_object_renderers[RECT_OUTLINE] = new RectOutlineRenderer();
39                 m_object_renderers[CIRCLE_FILLED] = new CircleFilledRenderer();
40                 m_object_renderers[BEZIER] = new BezierRenderer();
41                 m_object_renderers[PATH] = new PathRenderer();
42         }
43         else
44         {
45                 for (int i = RECT_FILLED; i <= PATH; ++i)
46                         m_object_renderers[i] = new FakeRenderer();
47         }
48
49         // To add rendering for a new type of object;
50         // 1. Add enum to ObjectType in ipdf.h
51         // 2. Implement class inheriting from ObjectRenderer using that type in objectrenderer.h and objectrenderer.cpp
52         // 3. Add it here
53         // 4. Profit
54
55
56 #ifndef QUADTREE_DISABLED
57         m_quadtree_max_depth = 2;
58         m_current_quadtree_node = document.GetQuadTree().root_id;
59 #endif
60 }
61
62 /**
63  * Destroy a view
64  * Frees memory used by ObjectRenderers
65  */
66 View::~View()
67 {
68         for (unsigned i = 0; i < m_object_renderers.size(); ++i)
69         {
70                 delete m_object_renderers[i]; // delete's match new's in constructor
71         }
72         m_object_renderers.clear();
73         delete [] m_cpu_rendering_pixels;
74 }
75
76 /**
77  * Translate the view
78  * @param x, y - Amount to translate
79  */
80 void View::Translate(Real x, Real y)
81 {
82         if (!m_use_gpu_transform)
83                 m_buffer_dirty = true;
84         m_bounds_dirty = true;
85         #ifdef TRANSFORM_OBJECTS_NOT_VIEW
86         m_document.TranslateObjects(-x, -y);
87         #endif
88         x *= m_bounds.w;
89         y *= m_bounds.h;
90         m_bounds.x += x;
91         m_bounds.y += y;
92         //Debug("View Bounds => %s", m_bounds.Str().c_str());
93
94         
95 }
96
97 /**
98  * Set View bounds
99  * @param bounds - New bounds
100  */
101 void View::SetBounds(const Rect & bounds)
102 {
103         m_bounds.x = bounds.x;
104         m_bounds.y = bounds.y;
105         m_bounds.w = bounds.w;
106         m_bounds.h = bounds.h;
107         if (!m_use_gpu_transform)
108                 m_buffer_dirty = true;
109         m_bounds_dirty = true;
110 }
111
112 /**
113  * Scale the View at a point
114  * @param x, y - Coordinates to scale at (eg: Mouse cursor position)
115  * @param scale_amount - Amount to scale by
116  */
117 void View::ScaleAroundPoint(Real x, Real y, Real scale_amount)
118 {
119         
120         // (x0, y0, w, h) -> (x*w - (x*w - x0)*s, y*h - (y*h - y0)*s, w*s, h*s)
121         // x and y are coordinates in the window
122         // Convert to local coords.
123         if (!m_use_gpu_transform)
124                 m_buffer_dirty = true;
125         m_bounds_dirty = true;
126         
127         
128         #ifdef TRANSFORM_OBJECTS_NOT_VIEW
129         m_document.ScaleObjectsAboutPoint(x, y, scale_amount);
130         #endif
131         x *= m_bounds.w;
132         y *= m_bounds.h;
133         x += m_bounds.x;
134         y += m_bounds.y;
135         
136         Real top = y - m_bounds.y;
137         Real left = x - m_bounds.x;
138         
139         top *= scale_amount;
140         left *= scale_amount;
141         
142         m_bounds.x = x - left;
143         m_bounds.y = y - top;
144         m_bounds.w *= scale_amount;
145         m_bounds.h *= scale_amount;
146         //Debug("Scale at {%s, %s} by %s View Bounds => %s", x.Str().c_str(), y.Str().c_str(), scale_amount.Str().c_str(), m_bounds.Str().c_str());
147         
148         
149 }
150
151 /**
152  * Transform a point in the document to a point relative to the top left corner of the view
153  * This is the CPU coordinate transform code; used only if the CPU is doing coordinate transforms
154  * @param inp - Input Rect {x,y,w,h} in the document
155  * @returns output Rect {x,y,w,h} in the View
156  */
157 Rect View::TransformToViewCoords(const Rect& inp) const
158 {
159         #ifdef TRANSFORM_OBJECTS_NOT_VIEW
160                 return inp;
161         #endif
162         Rect out;
163         out.x = (inp.x - m_bounds.x) / m_bounds.w;
164         out.y = (inp.y - m_bounds.y) / m_bounds.h;
165         out.w = inp.w / m_bounds.w;
166         out.h = inp.h / m_bounds.h;
167         return out;
168 }
169
170 /**
171  * Render the view
172  * Updates FrameBuffer if the document, object bounds, or view bounds have changed, then Blits it
173  * Otherwise just Blits the cached FrameBuffer
174  * @param width - Width of View to render
175  * @param height - Height of View to render
176  */
177 void View::Render(int width, int height)
178 {
179         if (!m_screen.Valid()) return;
180         glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION,42,-1, "Beginning View::Render()");
181         // View dimensions have changed (ie: Window was resized)
182         int prev_width = m_cached_display.GetWidth();
183         int prev_height = m_cached_display.GetHeight();
184         if (width != prev_width || height != prev_height)
185         {
186                 m_cached_display.Create(width, height);
187                 m_bounds_dirty = true;
188         }
189
190         // View bounds have not changed; blit the FrameBuffer as it is
191         if (!m_bounds_dirty && m_lazy_rendering)
192         {
193                 m_cached_display.UnBind();
194                 m_cached_display.Blit();
195                 glPopDebugGroup();
196                 return;
197         }
198         m_cached_display.Bind(); //NOTE: This is redundant; Clear already calls Bind
199         m_cached_display.Clear();
200
201 #ifndef QUADTREE_DISABLED
202         if (m_bounds_dirty || !m_lazy_rendering)
203         {
204                 if ( false &&  (m_bounds.x > 1.0 || m_bounds.x < 0.0 || m_bounds.y > 1.0 || m_bounds.y < 0.0 || m_bounds.w > 1.0 || m_bounds.h > 1.0))
205                 {
206                         //TODO: Generate a new parent node.
207                         if (m_document.GetQuadTree().nodes[m_current_quadtree_node].parent != QUADTREE_EMPTY)
208                         {
209                                 m_bounds = TransformFromQuadChild(m_bounds, m_document.GetQuadTree().nodes[m_current_quadtree_node].child_type);
210                                 m_current_quadtree_node = m_document.GetQuadTree().nodes[m_current_quadtree_node].parent;
211                         }
212                 }
213                 if (ContainedInQuadChild(m_bounds, QTC_TOP_LEFT))
214                 {
215                         if (m_document.GetQuadTree().nodes[m_current_quadtree_node].top_left == QUADTREE_EMPTY)
216                         {
217                                 // We want to reparent into a child node, but none exist. Get the document to create one.
218                                 m_document.GenQuadChild(m_current_quadtree_node, QTC_TOP_LEFT);
219                                 m_render_dirty = true;
220                         }
221                         m_bounds = TransformToQuadChild(m_bounds, QTC_TOP_LEFT);
222                         m_current_quadtree_node = m_document.GetQuadTree().nodes[m_current_quadtree_node].top_left;
223                 }
224                 if (ContainedInQuadChild(m_bounds, QTC_TOP_RIGHT))
225                 {
226                         if (m_document.GetQuadTree().nodes[m_current_quadtree_node].top_right == QUADTREE_EMPTY)
227                         {
228                                 // We want to reparent into a child node, but none exist. Get the document to create one.
229                                 m_document.GenQuadChild(m_current_quadtree_node, QTC_TOP_RIGHT);
230                                 m_render_dirty = true;
231                         }
232                         m_bounds = TransformToQuadChild(m_bounds, QTC_TOP_RIGHT);
233                         m_current_quadtree_node = m_document.GetQuadTree().nodes[m_current_quadtree_node].top_right;
234                 }
235                 if (ContainedInQuadChild(m_bounds, QTC_BOTTOM_LEFT))
236                 {
237                         if (m_document.GetQuadTree().nodes[m_current_quadtree_node].bottom_left == QUADTREE_EMPTY)
238                         {
239                                 // We want to reparent into a child node, but none exist. Get the document to create one.
240                                 m_document.GenQuadChild(m_current_quadtree_node, QTC_BOTTOM_LEFT);
241                                 m_render_dirty = true;
242                         }
243                         m_bounds = TransformToQuadChild(m_bounds, QTC_BOTTOM_LEFT);
244                         m_current_quadtree_node = m_document.GetQuadTree().nodes[m_current_quadtree_node].bottom_left;
245                 }
246                 if (ContainedInQuadChild(m_bounds, QTC_BOTTOM_RIGHT))
247                 {
248                         if (m_document.GetQuadTree().nodes[m_current_quadtree_node].bottom_right == QUADTREE_EMPTY)
249                         {
250                                 // We want to reparent into a child node, but none exist. Get the document to create one.
251                                 m_document.GenQuadChild(m_current_quadtree_node, QTC_BOTTOM_RIGHT);
252                                 m_render_dirty = true;
253                         }
254                         m_bounds = TransformToQuadChild(m_bounds, QTC_BOTTOM_RIGHT);
255                         m_current_quadtree_node = m_document.GetQuadTree().nodes[m_current_quadtree_node].bottom_right;
256                 }
257         }
258         m_screen.DebugFontPrintF("Current View QuadTree Node: %d (objs: %d -> %d)\n", m_current_quadtree_node, m_document.GetQuadTree().nodes[m_current_quadtree_node].object_begin,
259                                 m_document.GetQuadTree().nodes[m_current_quadtree_node].object_end);
260
261         Rect view_top_bounds = m_bounds;
262         QuadTreeIndex tmp = m_current_quadtree_node;
263         while (tmp != -1)
264         {
265                 view_top_bounds = TransformFromQuadChild(view_top_bounds, m_document.GetQuadTree().nodes[tmp].child_type);
266                 tmp = m_document.GetQuadTree().nodes[tmp].parent;
267         }
268         m_screen.DebugFontPrintF("Equivalent View Bounds: %s\n", view_top_bounds.Str().c_str());
269 #endif
270
271         if (!m_use_gpu_rendering)
272         {
273                 // Dynamically resize CPU rendering target pixels if needed
274                 if (m_cpu_rendering_pixels == NULL || width*height > prev_width*prev_height)
275                 {
276                         delete [] m_cpu_rendering_pixels;
277                         m_cpu_rendering_pixels = new uint8_t[width*height*4];
278                         if (m_cpu_rendering_pixels == NULL)
279                                 Fatal("Could not allocate %d*%d*4 = %d bytes for cpu rendered pixels", width, height, width*height*4);
280                 }
281                 // Clear CPU rendering pixels
282                 for (int i = 0; i < width*height*4; ++i)
283                         m_cpu_rendering_pixels[i] = 255;
284         }
285 #ifdef QUADTREE_DISABLED
286         RenderRange(width, height, 0, m_document.ObjectCount());
287 #else
288         RenderQuadtreeNode(width, height, m_current_quadtree_node, m_quadtree_max_depth);
289 #endif
290         if (!m_use_gpu_rendering)
291         {
292                 m_screen.RenderPixels(0,0,width, height, m_cpu_rendering_pixels); //TODO: Make this work :(
293                 // Debug for great victory (do something similar for GPU and compare?)
294                 //ObjectRenderer::SaveBMP({m_cpu_rendering_pixels, width, height}, "cpu_rendering_last_frame.bmp");
295         }
296         m_cached_display.UnBind(); // resets render target to the screen
297         m_cached_display.Blit(); // blit FrameBuffer to screen
298         m_buffer_dirty = false;
299         glPopDebugGroup();
300         
301 #ifndef CONTROLPANEL_DISABLED
302         ControlPanel::Update();
303 #endif //CONTROLPANEL_DISABLED
304         //Debug("Completed Render");
305         
306 }
307
308 #ifndef QUADTREE_DISABLED
309 void View::RenderQuadtreeNode(int width, int height, QuadTreeIndex node, int remaining_depth)
310 {
311         Rect old_bounds = m_bounds;
312         if (node == QUADTREE_EMPTY) return;
313         if (!remaining_depth) return;
314         //Debug("Rendering QT node %d, (objs: %d -- %d)\n", node, m_document.GetQuadTree().nodes[node].object_begin, m_document.GetQuadTree().nodes[node].object_end);
315         m_bounds_dirty = true;
316         RenderRange(width, height, m_document.GetQuadTree().nodes[node].object_begin, m_document.GetQuadTree().nodes[node].object_end);
317
318         if (m_bounds.Intersects(Rect(-1,-1,1,1)))
319         {
320                 m_bounds = Rect(m_bounds.x - 1, m_bounds.y - 1, m_bounds.w, m_bounds.h);
321                 m_bounds_dirty = true;
322                 RenderQuadtreeNode(width, height, m_document.GetQuadTree().GetNeighbour(node, -1, -1), remaining_depth - 1);
323         }
324         if (m_bounds.Intersects(Rect(-1,0,1,1)))
325         {
326                 m_bounds = Rect(m_bounds.x - 1, m_bounds.y, m_bounds.w, m_bounds.h);
327                 m_bounds_dirty = true;
328                 RenderQuadtreeNode(width, height, m_document.GetQuadTree().GetNeighbour(node, -1, 0), remaining_depth - 1);
329         }
330         if (m_bounds.Intersects(Rect(-1,1,1,1)))
331         {
332                 m_bounds = Rect(m_bounds.x - 1, m_bounds.y + 1, m_bounds.w, m_bounds.h);
333                 m_bounds_dirty = true;
334                 RenderQuadtreeNode(width, height, m_document.GetQuadTree().GetNeighbour(node, -1, 1), remaining_depth - 1);
335         }
336         if (m_bounds.Intersects(Rect(0,-1,1,1)))
337         {
338                 m_bounds = Rect(m_bounds.x, m_bounds.y - 1, m_bounds.w, m_bounds.h);
339                 m_bounds_dirty = true;
340                 RenderQuadtreeNode(width, height, m_document.GetQuadTree().GetNeighbour(node, 0, -1), remaining_depth - 1);
341         }
342         if (m_bounds.Intersects(Rect(0,1,1,1)))
343         {
344                 m_bounds = Rect(m_bounds.x, m_bounds.y + 1, m_bounds.w, m_bounds.h);
345                 m_bounds_dirty = true;
346                 RenderQuadtreeNode(width, height, m_document.GetQuadTree().GetNeighbour(node, 0, 1), remaining_depth - 1);
347         }
348         if (m_bounds.Intersects(Rect(1,-1,1,1)))
349         {
350                 m_bounds = Rect(m_bounds.x + 1, m_bounds.y - 1, m_bounds.w, m_bounds.h);
351                 m_bounds_dirty = true;
352                 RenderQuadtreeNode(width, height, m_document.GetQuadTree().GetNeighbour(node, 1, -1), remaining_depth - 1);
353         }
354         if (m_bounds.Intersects(Rect(1,0,1,1)))
355         {
356                 m_bounds = Rect(m_bounds.x + 1, m_bounds.y, m_bounds.w, m_bounds.h);
357                 m_bounds_dirty = true;
358                 RenderQuadtreeNode(width, height, m_document.GetQuadTree().GetNeighbour(node, 1, 0), remaining_depth - 1);
359         }
360         if (m_bounds.Intersects(Rect(1,1,1,1)))
361         {
362                 m_bounds = Rect(m_bounds.x + 1, m_bounds.y + 1, m_bounds.w, m_bounds.h);
363                 m_bounds_dirty = true;
364                 RenderQuadtreeNode(width, height, m_document.GetQuadTree().GetNeighbour(node, 1, 1), remaining_depth - 1);
365         }
366         m_bounds = old_bounds;
367         m_bounds_dirty = true;
368
369 #if 0
370         m_bounds = TransformToQuadChild(old_bounds, QTC_TOP_LEFT);
371         m_bounds_dirty = true;
372         RenderQuadtreeNode(width, height, m_document.GetQuadTree().nodes[node].top_left, remaining_depth-1);
373         m_bounds = TransformToQuadChild(old_bounds, QTC_TOP_RIGHT);
374         m_bounds_dirty = true;
375         RenderQuadtreeNode(width, height, m_document.GetQuadTree().nodes[node].top_right, remaining_depth-1);
376         m_bounds = TransformToQuadChild(old_bounds, QTC_BOTTOM_LEFT);
377         m_bounds_dirty = true;
378         RenderQuadtreeNode(width, height, m_document.GetQuadTree().nodes[node].bottom_left, remaining_depth-1);
379         m_bounds = TransformToQuadChild(old_bounds, QTC_BOTTOM_RIGHT);
380         m_bounds_dirty = true;
381         RenderQuadtreeNode(width, height, m_document.GetQuadTree().nodes[node].bottom_right, remaining_depth-1);
382         m_bounds = old_bounds;
383         m_bounds_dirty = true;
384 #endif
385 }
386 #endif
387
388 void View::RenderRange(int width, int height, unsigned first_obj, unsigned last_obj)
389 {
390         glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 43, -1, "View::RenderRange()");
391         if (m_render_dirty) // document has changed
392                 PrepareRender();
393
394         if (m_buffer_dirty || m_bounds_dirty || !m_lazy_rendering) // object bounds have changed
395         {
396                 if (m_use_gpu_rendering)
397                         UpdateObjBoundsVBO(first_obj, last_obj);
398         }
399
400         if (m_use_gpu_transform)
401         {
402                 #ifdef TRANSFORM_OBJECTS_NOT_VIEW
403                                 GLfloat glbounds[] = {0.0f, 0.0f, 1.0f, 1.0f,
404                                         0.0f, 0.0f, float(width), float(height)};
405                 #else
406                 GLfloat glbounds[] = {static_cast<GLfloat>(Float(m_bounds.x)), static_cast<GLfloat>(Float(m_bounds.y)), static_cast<GLfloat>(Float(m_bounds.w)), static_cast<GLfloat>(Float(m_bounds.h)),
407                                         0.0, 0.0, static_cast<GLfloat>(width), static_cast<GLfloat>(height)};
408                 #endif
409                 m_bounds_ubo.Upload(sizeof(float)*8, glbounds);
410         }
411         else
412         {
413                 GLfloat glbounds[] = {0.0f, 0.0f, 1.0f, 1.0f,
414                                         0.0f, 0.0f, float(width), float(height)};
415                 m_bounds_ubo.Upload(sizeof(float)*8, glbounds);
416         }
417         m_bounds_dirty = false;
418
419
420         // Render using GPU
421         if (m_use_gpu_rendering) 
422         {
423                 if (m_colour.a < 1.0f)
424                 {
425                         glEnable(GL_BLEND);
426                         glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
427                 }
428                 m_objbounds_vbo.Bind();
429                 m_bounds_ubo.Bind();
430                 glEnableVertexAttribArray(0);
431                 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, 0);
432         
433                 for (unsigned i = 0; i < m_object_renderers.size(); ++i)
434                 {
435                         m_object_renderers[i]->RenderUsingGPU(first_obj, last_obj);
436                 }
437                 
438                 glDisableVertexAttribArray(0);
439                 if (m_colour.a < 1.0f)
440                 {
441                         glDisable(GL_BLEND);
442                 }
443         }
444         else // Rasterise on CPU then blit texture to GPU
445         {
446
447                 for (unsigned i = 0; i < m_object_renderers.size(); ++i)
448                 {
449                         m_object_renderers[i]->RenderUsingCPU(m_document.m_objects, *this, {m_cpu_rendering_pixels, width, height}, first_obj, last_obj);
450                 }
451         }
452         glPopDebugGroup();
453 }
454
455 void View::UpdateObjBoundsVBO(unsigned first_obj, unsigned last_obj)
456 {
457         //m_objbounds_vbo.Invalidate();
458         m_objbounds_vbo.SetType(GraphicsBuffer::BufferTypeVertex);
459         m_objbounds_vbo.SetName("Object Bounds VBO");
460         if (m_use_gpu_transform)
461         {
462                 m_objbounds_vbo.SetUsage(GraphicsBuffer::BufferUsageStaticDraw);
463         }
464         else
465         {
466                 m_objbounds_vbo.SetUsage(GraphicsBuffer::BufferUsageDynamicCopy);
467         }
468         m_objbounds_vbo.Resize(m_document.ObjectCount()*sizeof(GPUObjBounds));
469
470         BufferBuilder<GPUObjBounds> obj_bounds_builder(m_objbounds_vbo.MapRange(first_obj*sizeof(GPUObjBounds), (last_obj-first_obj)*sizeof(GPUObjBounds), false, true, true), m_objbounds_vbo.GetSize());
471
472         for (unsigned id = first_obj; id < last_obj; ++id)
473         {
474                 Rect obj_bounds;
475                 if (m_use_gpu_transform)
476                 {
477                         obj_bounds = m_document.m_objects.bounds[id];
478                 }
479                 else
480                 {
481                         obj_bounds = TransformToViewCoords(m_document.m_objects.bounds[id]);
482                 }
483                 GPUObjBounds gpu_bounds = {
484                         (float)Float(obj_bounds.x),
485                         (float)Float(obj_bounds.y),
486                         (float)Float(obj_bounds.x + obj_bounds.w),
487                         (float)Float(obj_bounds.y + obj_bounds.h)
488                 };
489                 obj_bounds_builder.Add(gpu_bounds);
490
491         }
492         m_objbounds_vbo.UnMap();
493 }
494 /**
495  * Prepare the document for rendering
496  * Will be called on View::Render if m_render_dirty is set
497  * (Called at least once, on the first Render)
498  */
499 void View::PrepareRender()
500 {
501         Debug("Recreate buffers with %u objects", m_document.ObjectCount());
502         // Prepare bounds vbo
503         if (UsingGPURendering())
504         {
505                 m_bounds_ubo.Invalidate();
506                 m_bounds_ubo.SetType(GraphicsBuffer::BufferTypeUniform);
507                 m_bounds_ubo.SetUsage(GraphicsBuffer::BufferUsageStreamDraw);
508                 m_bounds_ubo.SetName("m_bounds_ubo: Screen bounds.");
509         }
510         
511         // Instead of having each ObjectRenderer go through the whole document
512         //  we initialise them, go through the document once adding to the appropriate Renderers
513         //  and then finalise them
514         // This will totally be efficient if we have like, a lot of distinct ObjectTypes. Which could totally happen. You never know.
515
516         // Prepare the buffers
517         for (unsigned i = 0; i < m_object_renderers.size(); ++i)
518         {
519                 m_object_renderers[i]->PrepareBuffers(m_document.ObjectCount());
520         }
521
522         // Add objects from Document to buffers
523         for (unsigned id = 0; id < m_document.ObjectCount(); ++id)
524         {
525                 ObjectType type = m_document.m_objects.types[id];
526                 m_object_renderers.at(type)->AddObjectToBuffers(id); // Use at() in case the document is corrupt TODO: Better error handling?
527                 // (Also, Wow I just actually used std::vector::at())
528                 // (Also, I just managed to make it throw an exception because I'm a moron)
529                 //Debug("Object of type %d", type);
530         }
531
532
533         // Finish the buffers
534         for (unsigned i = 0; i < m_object_renderers.size(); ++i)
535         {
536                 m_object_renderers[i]->FinaliseBuffers();
537         }
538         if (UsingGPURendering())
539                 dynamic_cast<BezierRenderer*>(m_object_renderers[BEZIER])->PrepareBezierGPUBuffer(m_document.m_objects);
540         m_render_dirty = false;
541 }
542
543 void View::SaveCPUBMP(const char * filename)
544 {
545         bool prev = UsingGPURendering();
546         SetGPURendering(false);
547         Render(800, 600);
548         ObjectRenderer::SaveBMP({m_cpu_rendering_pixels, 800, 600}, filename);
549         SetGPURendering(prev);
550 }
551
552 void View::SaveGPUBMP(const char * filename)
553 {
554         bool prev = UsingGPURendering();
555         SetGPURendering(true);
556         Render(800,600);
557         m_screen.ScreenShot(filename);
558         SetGPURendering(prev);  
559 }

UCC git Repository :: git.ucc.asn.au