2 #include "bufferbuilder.h"
6 #ifndef CONTROLPANEL_DISABLED
7 #include "controlpanel.h"
8 #endif //CONTROLPANEL_DISABLED
11 #ifdef TRANSFORM_BEZIERS_TO_PATH
12 #ifndef TRANSFORM_OBJECTS_NOT_VIEW
13 //#error Cannot TRANSFORM_BEZIERS_TO_PATH _without_ TRANSFORM_OBJECTS_NOT_VIEW
22 * Allocates memory for ObjectRenderers
23 * @param document - The document to associate the View with
24 * @param bounds - Initial bounds of the View
25 * @param colour - Colour to use for rendering this view. TODO: Make sure this actually works, or just remove it
27 View::View(Document & document, Screen & screen, const VRect & bounds, const Colour & colour)
28 : m_use_gpu_transform(USE_GPU_TRANSFORM), m_use_gpu_rendering(USE_GPU_RENDERING), m_bounds_dirty(true), m_buffer_dirty(true),
29 m_render_dirty(true), m_document(document), m_screen(screen), m_cached_display(), m_bounds(bounds), m_colour(colour), m_bounds_ubo(),
30 m_objbounds_vbo(), m_object_renderers(NUMBER_OF_OBJECT_TYPES), m_cpu_rendering_pixels(NULL),
31 m_perform_shading(USE_SHADING), m_show_bezier_bounds(false), m_show_bezier_type(false),
32 m_show_fill_points(false), m_show_fill_bounds(false), m_lazy_rendering(true)
34 Debug("View Created - Bounds => {%s}", m_bounds.Str().c_str());
36 screen.SetView(this); // oh dear...
40 // Create ObjectRenderers - new's match delete's in View::~View
41 //TODO: Don't forget to put new renderers here or things will be segfaultastic
44 m_object_renderers[RECT_FILLED] = new RectFilledRenderer();
45 m_object_renderers[RECT_OUTLINE] = new RectOutlineRenderer();
46 m_object_renderers[CIRCLE_FILLED] = new CircleFilledRenderer();
47 m_object_renderers[BEZIER] = new BezierRenderer();
48 m_object_renderers[PATH] = new PathRenderer();
52 for (int i = RECT_FILLED; i <= PATH; ++i)
53 m_object_renderers[i] = new FakeRenderer();
56 // To add rendering for a new type of object;
57 // 1. Add enum to ObjectType in ipdf.h
58 // 2. Implement class inheriting from ObjectRenderer using that type in objectrenderer.h and objectrenderer.cpp
63 #ifndef QUADTREE_DISABLED
64 m_quadtree_max_depth = 2;
65 m_current_quadtree_node = document.GetQuadTree().root_id;
71 * Frees memory used by ObjectRenderers
75 for (unsigned i = 0; i < m_object_renderers.size(); ++i)
77 delete m_object_renderers[i]; // delete's match new's in constructor
79 m_object_renderers.clear();
80 delete [] m_cpu_rendering_pixels;
85 * @param x, y - Amount to translate
87 void View::Translate(VReal x, VReal y)
89 if (!m_use_gpu_transform)
90 m_buffer_dirty = true;
91 m_bounds_dirty = true;
92 #ifdef TRANSFORM_OBJECTS_NOT_VIEW
93 ObjectType type = NUMBER_OF_OBJECT_TYPES;
94 #ifdef TRANSFORM_BEZIERS_TO_PATH
97 m_document.TranslateObjects(-x.ToDouble(), -y.ToDouble(), type);
103 //Debug("View Bounds => %s", m_bounds.Str().c_str());
110 * @param bounds - New bounds
112 void View::SetBounds(const Rect & bounds)
114 m_bounds.x = bounds.x;
115 m_bounds.y = bounds.y;
116 m_bounds.w = bounds.w;
117 m_bounds.h = bounds.h;
118 if (!m_use_gpu_transform)
119 m_buffer_dirty = true;
120 m_bounds_dirty = true;
124 * Scale the View at a point
125 * @param x, y - Coordinates to scale at (eg: Mouse cursor position)
126 * @param scale_amount - Amount to scale by
128 void View::ScaleAroundPoint(VReal x, VReal y, VReal scale_amount)
131 // (x0, y0, w, h) -> (x*w - (x*w - x0)*s, y*h - (y*h - y0)*s, w*s, h*s)
132 // x and y are coordinates in the window
133 // Convert to local coords.
134 if (!m_use_gpu_transform)
135 m_buffer_dirty = true;
136 m_bounds_dirty = true;
139 #ifdef TRANSFORM_OBJECTS_NOT_VIEW
140 ObjectType type = NUMBER_OF_OBJECT_TYPES;
141 #ifdef TRANSFORM_BEZIERS_TO_PATH
144 m_document.ScaleObjectsAboutPoint(x, y, scale_amount, type);
151 VReal top = y - m_bounds.y;
152 VReal left = x - m_bounds.x;
155 left *= scale_amount;
157 m_bounds.x = x - left;
158 m_bounds.y = y - top;
159 m_bounds.w *= scale_amount;
160 m_bounds.h *= scale_amount;
161 //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());
167 * Transform a point in the document to a point relative to the top left corner of the view
168 * This is the CPU coordinate transform code; used only if the CPU is doing coordinate transforms
169 * @param inp - Input Rect {x,y,w,h} in the document
170 * @returns output Rect {x,y,w,h} in the View
172 Rect View::TransformToViewCoords(const Rect& inp) const
174 #ifdef TRANSFORM_OBJECTS_NOT_VIEW
177 return TransformRectCoordinates(m_bounds, inp);
182 * Updates FrameBuffer if the document, object bounds, or view bounds have changed, then Blits it
183 * Otherwise just Blits the cached FrameBuffer
184 * @param width - Width of View to render
185 * @param height - Height of View to render
187 void View::Render(int width, int height)
189 if (!m_screen.Valid()) return;
190 glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION,42,-1, "Beginning View::Render()");
191 // View dimensions have changed (ie: Window was resized)
192 int prev_width = m_cached_display.GetWidth();
193 int prev_height = m_cached_display.GetHeight();
194 if (width != prev_width || height != prev_height)
196 m_cached_display.Create(width, height);
197 m_bounds_dirty = true;
200 // View bounds have not changed; blit the FrameBuffer as it is
201 if (!m_bounds_dirty && m_lazy_rendering)
203 m_cached_display.UnBind();
204 m_cached_display.Blit();
208 m_cached_display.Bind(); //NOTE: This is redundant; Clear already calls Bind
209 m_cached_display.Clear();
211 #ifndef QUADTREE_DISABLED
212 if (m_bounds_dirty || !m_lazy_rendering)
214 if ( m_bounds.w > 1.0 || m_bounds.h > 1.0)
216 //TODO: Generate a new parent node.
217 if (m_document.GetQuadTree().nodes[m_current_quadtree_node].parent != QUADTREE_EMPTY)
219 m_bounds = TransformFromQuadChild(m_bounds, m_document.GetQuadTree().nodes[m_current_quadtree_node].child_type);
220 m_current_quadtree_node = m_document.GetQuadTree().nodes[m_current_quadtree_node].parent;
224 // TODO: Support generating new parent nodes.
225 if (false && m_document.GetQuadTree().nodes[m_current_quadtree_node].parent != QUADTREE_EMPTY)
227 if (m_bounds.x < -0.5)
229 m_bounds = Rect(m_bounds.x + 1, m_bounds.y, m_bounds.w, m_bounds.h);
230 m_current_quadtree_node = m_document.GetQuadTree().GetNeighbour(m_current_quadtree_node, -1, 0, &m_document);
232 if (m_bounds.y < -0.5)
234 m_bounds = Rect(m_bounds.x, m_bounds.y + 1, m_bounds.w, m_bounds.h);
235 m_current_quadtree_node = m_document.GetQuadTree().GetNeighbour(m_current_quadtree_node, 0, -1, &m_document);
237 if (m_bounds.w + m_bounds.x > 0.5)
239 m_bounds = Rect(m_bounds.x - 1, m_bounds.y, m_bounds.w, m_bounds.h);
240 m_current_quadtree_node = m_document.GetQuadTree().GetNeighbour(m_current_quadtree_node, 1, 0, &m_document);
242 if (m_bounds.h + m_bounds.y > 0.5)
244 m_bounds = Rect(m_bounds.x, m_bounds.y - 1, m_bounds.w, m_bounds.h);
245 m_current_quadtree_node = m_document.GetQuadTree().GetNeighbour(m_current_quadtree_node, 0, 1, &m_document);
249 if (ContainedInQuadChild(m_bounds, QTC_TOP_LEFT))
251 if (m_document.GetQuadTree().nodes[m_current_quadtree_node].top_left == QUADTREE_EMPTY)
253 // We want to reparent into a child node, but none exist. Get the document to create one.
254 m_document.GenQuadChild(m_current_quadtree_node, QTC_TOP_LEFT);
255 m_render_dirty = true;
257 m_bounds = TransformToQuadChild(m_bounds, QTC_TOP_LEFT);
258 m_current_quadtree_node = m_document.GetQuadTree().nodes[m_current_quadtree_node].top_left;
260 if (ContainedInQuadChild(m_bounds, QTC_TOP_RIGHT))
262 if (m_document.GetQuadTree().nodes[m_current_quadtree_node].top_right == QUADTREE_EMPTY)
264 // We want to reparent into a child node, but none exist. Get the document to create one.
265 m_document.GenQuadChild(m_current_quadtree_node, QTC_TOP_RIGHT);
266 m_render_dirty = true;
268 m_bounds = TransformToQuadChild(m_bounds, QTC_TOP_RIGHT);
269 m_current_quadtree_node = m_document.GetQuadTree().nodes[m_current_quadtree_node].top_right;
271 if (ContainedInQuadChild(m_bounds, QTC_BOTTOM_LEFT))
273 if (m_document.GetQuadTree().nodes[m_current_quadtree_node].bottom_left == QUADTREE_EMPTY)
275 // We want to reparent into a child node, but none exist. Get the document to create one.
276 m_document.GenQuadChild(m_current_quadtree_node, QTC_BOTTOM_LEFT);
277 m_render_dirty = true;
279 m_bounds = TransformToQuadChild(m_bounds, QTC_BOTTOM_LEFT);
280 m_current_quadtree_node = m_document.GetQuadTree().nodes[m_current_quadtree_node].bottom_left;
282 if (ContainedInQuadChild(m_bounds, QTC_BOTTOM_RIGHT))
284 if (m_document.GetQuadTree().nodes[m_current_quadtree_node].bottom_right == QUADTREE_EMPTY)
286 // We want to reparent into a child node, but none exist. Get the document to create one.
287 m_document.GenQuadChild(m_current_quadtree_node, QTC_BOTTOM_RIGHT);
288 m_render_dirty = true;
290 m_bounds = TransformToQuadChild(m_bounds, QTC_BOTTOM_RIGHT);
291 m_current_quadtree_node = m_document.GetQuadTree().nodes[m_current_quadtree_node].bottom_right;
295 m_screen.DebugFontPrintF("Current View QuadTree");
296 QuadTreeIndex overlay = m_current_quadtree_node;
297 while (overlay != -1)
299 m_screen.DebugFontPrintF(" Node: %d (objs: %d -> %d)", overlay, m_document.GetQuadTree().nodes[overlay].object_begin,
300 m_document.GetQuadTree().nodes[overlay].object_end);
301 overlay = m_document.GetQuadTree().nodes[overlay].next_overlay;
303 m_screen.DebugFontPrintF("\n");
305 Rect view_top_bounds = m_bounds;
306 QuadTreeIndex tmp = m_current_quadtree_node;
309 view_top_bounds = TransformFromQuadChild(view_top_bounds, m_document.GetQuadTree().nodes[tmp].child_type);
310 tmp = m_document.GetQuadTree().nodes[tmp].parent;
312 m_screen.DebugFontPrintF("Equivalent View Bounds: %s\n", view_top_bounds.Str().c_str());
315 if (!m_use_gpu_rendering)
317 // Dynamically resize CPU rendering target pixels if needed
318 if (m_cpu_rendering_pixels == NULL || width*height > prev_width*prev_height)
320 delete [] m_cpu_rendering_pixels;
321 m_cpu_rendering_pixels = new uint8_t[width*height*4];
322 if (m_cpu_rendering_pixels == NULL)
323 Fatal("Could not allocate %d*%d*4 = %d bytes for cpu rendered pixels", width, height, width*height*4);
325 // Clear CPU rendering pixels
326 for (int i = 0; i < width*height*4; ++i)
327 m_cpu_rendering_pixels[i] = 255;
329 #ifdef QUADTREE_DISABLED
330 RenderRange(width, height, 0, m_document.ObjectCount());
332 RenderQuadtreeNode(width, height, m_current_quadtree_node, m_quadtree_max_depth);
334 if (!m_use_gpu_rendering)
336 m_screen.RenderPixels(0,0,width, height, m_cpu_rendering_pixels); //TODO: Make this work :(
337 // Debug for great victory (do something similar for GPU and compare?)
338 //ObjectRenderer::SaveBMP({m_cpu_rendering_pixels, width, height}, "cpu_rendering_last_frame.bmp");
340 m_cached_display.UnBind(); // resets render target to the screen
341 m_cached_display.Blit(); // blit FrameBuffer to screen
342 m_buffer_dirty = false;
345 #ifndef CONTROLPANEL_DISABLED
346 ControlPanel::Update();
347 #endif //CONTROLPANEL_DISABLED
348 //Debug("Completed Render");
352 #ifndef QUADTREE_DISABLED
353 void View::RenderQuadtreeNode(int width, int height, QuadTreeIndex node, int remaining_depth)
355 Rect old_bounds = m_bounds;
356 if (node == QUADTREE_EMPTY) return;
357 if (!remaining_depth) return;
358 //Debug("Rendering QT node %d, (objs: %d -- %d)\n", node, m_document.GetQuadTree().nodes[node].object_begin, m_document.GetQuadTree().nodes[node].object_end);
359 m_bounds_dirty = true;
360 QuadTreeIndex overlay = node;
363 RenderRange(width, height, m_document.GetQuadTree().nodes[overlay].object_begin, m_document.GetQuadTree().nodes[overlay].object_end);
364 overlay = m_document.GetQuadTree().nodes[overlay].next_overlay;
367 if (m_bounds.Intersects(Rect(-1,-1,1,1)))
369 m_bounds = Rect(m_bounds.x - 1, m_bounds.y - 1, m_bounds.w, m_bounds.h);
370 m_bounds_dirty = true;
371 RenderQuadtreeNode(width, height, m_document.GetQuadTree().GetNeighbour(node, -1, -1, &m_document), remaining_depth - 1);
373 m_bounds = old_bounds;
374 if (m_bounds.Intersects(Rect(-1,0,1,1)))
376 m_bounds = Rect(m_bounds.x - 1, m_bounds.y, m_bounds.w, m_bounds.h);
377 m_bounds_dirty = true;
378 RenderQuadtreeNode(width, height, m_document.GetQuadTree().GetNeighbour(node, -1, 0, &m_document), remaining_depth - 1);
380 m_bounds = old_bounds;
381 if (m_bounds.Intersects(Rect(-1,1,1,1)))
383 m_bounds = Rect(m_bounds.x - 1, m_bounds.y + 1, m_bounds.w, m_bounds.h);
384 m_bounds_dirty = true;
385 RenderQuadtreeNode(width, height, m_document.GetQuadTree().GetNeighbour(node, -1, 1, &m_document), remaining_depth - 1);
387 m_bounds = old_bounds;
388 if (m_bounds.Intersects(Rect(0,-1,1,1)))
390 m_bounds = Rect(m_bounds.x, m_bounds.y - 1, m_bounds.w, m_bounds.h);
391 m_bounds_dirty = true;
392 RenderQuadtreeNode(width, height, m_document.GetQuadTree().GetNeighbour(node, 0, -1, &m_document), remaining_depth - 1);
394 m_bounds = old_bounds;
395 if (m_bounds.Intersects(Rect(0,1,1,1)))
397 m_bounds = Rect(m_bounds.x, m_bounds.y + 1, m_bounds.w, m_bounds.h);
398 m_bounds_dirty = true;
399 RenderQuadtreeNode(width, height, m_document.GetQuadTree().GetNeighbour(node, 0, 1, &m_document), remaining_depth - 1);
401 m_bounds = old_bounds;
402 if (m_bounds.Intersects(Rect(1,-1,1,1)))
404 m_bounds = Rect(m_bounds.x + 1, m_bounds.y - 1, m_bounds.w, m_bounds.h);
405 m_bounds_dirty = true;
406 RenderQuadtreeNode(width, height, m_document.GetQuadTree().GetNeighbour(node, 1, -1, &m_document), remaining_depth - 1);
408 m_bounds = old_bounds;
409 if (m_bounds.Intersects(Rect(1,0,1,1)))
411 m_bounds = Rect(m_bounds.x + 1, m_bounds.y, m_bounds.w, m_bounds.h);
412 m_bounds_dirty = true;
413 RenderQuadtreeNode(width, height, m_document.GetQuadTree().GetNeighbour(node, 1, 0, &m_document), remaining_depth - 1);
415 m_bounds = old_bounds;
416 if (m_bounds.Intersects(Rect(1,1,1,1)))
418 m_bounds = Rect(m_bounds.x + 1, m_bounds.y + 1, m_bounds.w, m_bounds.h);
419 m_bounds_dirty = true;
420 RenderQuadtreeNode(width, height, m_document.GetQuadTree().GetNeighbour(node, 1, 1, &m_document), remaining_depth - 1);
422 m_bounds = old_bounds;
423 m_bounds_dirty = true;
426 m_bounds = TransformToQuadChild(old_bounds, QTC_TOP_LEFT);
427 m_bounds_dirty = true;
428 RenderQuadtreeNode(width, height, m_document.GetQuadTree().nodes[node].top_left, remaining_depth-1);
429 m_bounds = TransformToQuadChild(old_bounds, QTC_TOP_RIGHT);
430 m_bounds_dirty = true;
431 RenderQuadtreeNode(width, height, m_document.GetQuadTree().nodes[node].top_right, remaining_depth-1);
432 m_bounds = TransformToQuadChild(old_bounds, QTC_BOTTOM_LEFT);
433 m_bounds_dirty = true;
434 RenderQuadtreeNode(width, height, m_document.GetQuadTree().nodes[node].bottom_left, remaining_depth-1);
435 m_bounds = TransformToQuadChild(old_bounds, QTC_BOTTOM_RIGHT);
436 m_bounds_dirty = true;
437 RenderQuadtreeNode(width, height, m_document.GetQuadTree().nodes[node].bottom_right, remaining_depth-1);
438 m_bounds = old_bounds;
439 m_bounds_dirty = true;
444 void View::RenderRange(int width, int height, unsigned first_obj, unsigned last_obj)
446 glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 43, -1, "View::RenderRange()");
447 if (m_render_dirty) // document has changed
450 if (m_buffer_dirty || m_bounds_dirty || !m_lazy_rendering) // object bounds have changed
452 if (m_use_gpu_rendering)
453 UpdateObjBoundsVBO(first_obj, last_obj);
456 if (m_use_gpu_transform)
458 #ifdef TRANSFORM_OBJECTS_NOT_VIEW
459 //Debug("Transform objects, not view");
460 GLfloat glbounds[] = {0.0f, 0.0f, 1.0f, 1.0f,
461 0.0f, 0.0f, float(width), float(height)};
463 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)),
464 0.0, 0.0, static_cast<GLfloat>(width), static_cast<GLfloat>(height)};
466 m_bounds_ubo.Upload(sizeof(float)*8, glbounds);
470 GLfloat glbounds[] = {0.0f, 0.0f, 1.0f, 1.0f,
471 0.0f, 0.0f, float(width), float(height)};
472 m_bounds_ubo.Upload(sizeof(float)*8, glbounds);
474 m_bounds_dirty = false;
478 if (m_use_gpu_rendering)
480 if (m_colour.a < 1.0f)
483 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
485 m_objbounds_vbo.Bind();
487 glEnableVertexAttribArray(0);
488 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, 0);
490 for (unsigned i = 0; i < m_object_renderers.size(); ++i)
492 m_object_renderers[i]->RenderUsingGPU(first_obj, last_obj);
495 glDisableVertexAttribArray(0);
496 if (m_colour.a < 1.0f)
501 else // Rasterise on CPU then blit texture to GPU
504 for (unsigned i = 0; i < m_object_renderers.size(); ++i)
506 m_object_renderers[i]->RenderUsingCPU(m_document.m_objects, *this, {m_cpu_rendering_pixels, width, height}, first_obj, last_obj);
512 void View::UpdateObjBoundsVBO(unsigned first_obj, unsigned last_obj)
514 //m_objbounds_vbo.Invalidate();
515 m_objbounds_vbo.SetType(GraphicsBuffer::BufferTypeVertex);
516 m_objbounds_vbo.SetName("Object Bounds VBO");
518 #ifndef TRANSFORM_OBJECTS_NOT_VIEW
519 if (m_use_gpu_transform)
521 m_objbounds_vbo.SetUsage(GraphicsBuffer::BufferUsageStaticDraw);
524 #endif //TRANSFORM_OBJECTS_NOT_VIEW
526 m_objbounds_vbo.SetUsage(GraphicsBuffer::BufferUsageDynamicCopy);
528 m_objbounds_vbo.Resize(m_document.ObjectCount()*sizeof(GPUObjBounds));
530 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());
532 #ifndef TRANSFORM_BEZIERS_TO_PATH
533 for (unsigned id = first_obj; id < last_obj; ++id)
536 if (m_use_gpu_transform)
538 obj_bounds = m_document.m_objects.bounds[id];
542 obj_bounds = TransformToViewCoords(m_document.m_objects.bounds[id]);
544 GPUObjBounds gpu_bounds = {
545 (float)Float(obj_bounds.x),
546 (float)Float(obj_bounds.y),
547 (float)Float(obj_bounds.x + obj_bounds.w),
548 (float)Float(obj_bounds.y + obj_bounds.h)
551 obj_bounds_builder.Add(gpu_bounds);
554 for (unsigned i = 0; i < m_document.m_objects.paths.size(); ++i)
556 Path & path = m_document.m_objects.paths[i];
557 Rect & pbounds = path.GetBounds(m_document.m_objects); // Not very efficient...
558 for (unsigned id = path.m_start; id <= path.m_end; ++id)
560 if (id < first_obj || id >= last_obj)
563 Rect obj_bounds = m_document.m_objects.bounds[id];
565 obj_bounds.x *= pbounds.w;
566 obj_bounds.x += pbounds.x;
567 obj_bounds.y *= pbounds.h;
568 obj_bounds.y += pbounds.y;
569 obj_bounds.w *= pbounds.w;
570 obj_bounds.h *= pbounds.h;
572 if (!m_use_gpu_transform)
573 obj_bounds = TransformToViewCoords(obj_bounds);
574 GPUObjBounds gpu_bounds = {
577 Float(obj_bounds.x + obj_bounds.w),
578 Float(obj_bounds.y + obj_bounds.h)
580 obj_bounds_builder.Add(gpu_bounds);
581 //Debug("Path %d %s -> %s via %s", id, m_document.m_objects.bounds[id].Str().c_str(), obj_bounds.Str().c_str(), pbounds.Str().c_str());
583 GPUObjBounds p_gpu_bounds = {
586 Float(pbounds.x + pbounds.w),
587 Float(pbounds.y + pbounds.h)
589 obj_bounds_builder.Add(p_gpu_bounds);
592 m_objbounds_vbo.UnMap();
595 * Prepare the document for rendering
596 * Will be called on View::Render if m_render_dirty is set
597 * (Called at least once, on the first Render)
599 void View::PrepareRender()
601 Debug("Recreate buffers with %u objects", m_document.ObjectCount());
602 // Prepare bounds vbo
603 if (UsingGPURendering())
605 m_bounds_ubo.Invalidate();
606 m_bounds_ubo.SetType(GraphicsBuffer::BufferTypeUniform);
607 m_bounds_ubo.SetUsage(GraphicsBuffer::BufferUsageStreamDraw);
608 m_bounds_ubo.SetName("m_bounds_ubo: Screen bounds.");
611 // Instead of having each ObjectRenderer go through the whole document
612 // we initialise them, go through the document once adding to the appropriate Renderers
613 // and then finalise them
614 // This will totally be efficient if we have like, a lot of distinct ObjectTypes. Which could totally happen. You never know.
616 // Prepare the buffers
617 for (unsigned i = 0; i < m_object_renderers.size(); ++i)
619 m_object_renderers[i]->PrepareBuffers(m_document.ObjectCount());
622 // Add objects from Document to buffers
623 for (unsigned id = 0; id < m_document.ObjectCount(); ++id)
625 ObjectType type = m_document.m_objects.types[id];
626 m_object_renderers.at(type)->AddObjectToBuffers(id); // Use at() in case the document is corrupt TODO: Better error handling?
627 // (Also, Wow I just actually used std::vector::at())
628 // (Also, I just managed to make it throw an exception because I'm a moron)
629 //Debug("Object of type %d", type);
633 // Finish the buffers
634 for (unsigned i = 0; i < m_object_renderers.size(); ++i)
636 m_object_renderers[i]->FinaliseBuffers();
638 if (UsingGPURendering())
640 dynamic_cast<BezierRenderer*>(m_object_renderers[BEZIER])->PrepareBezierGPUBuffer(m_document.m_objects);
642 m_render_dirty = false;
645 void View::SaveCPUBMP(const char * filename)
647 bool prev = UsingGPURendering();
648 SetGPURendering(false);
650 ObjectRenderer::SaveBMP({m_cpu_rendering_pixels, 800, 600}, filename);
651 SetGPURendering(prev);
654 void View::SaveGPUBMP(const char * filename)
656 bool prev = UsingGPURendering();
657 SetGPURendering(true);
659 m_screen.ScreenShot(filename);
660 SetGPURendering(prev);