6 #include "framebuffer.h"
7 #include "objectrenderer.h"
9 #include "transformationtype.h"
11 #define USE_GPU_TRANSFORM true
12 #define USE_GPU_RENDERING true
13 #define USE_SHADING !(USE_GPU_RENDERING) && true
15 #ifdef TRANSFORM_BEZIERS_TO_PATH
17 #include "paranoidnumber.h"
22 #ifdef TRANSFORM_BEZIERS_TO_PATH
27 typedef TRect<VReal> VRect;
31 * The View class manages a rectangular view into the document.
32 * It is responsible for coordinate transforms and rendering the document.
33 * ObjectRenderer's for each type of Object should be created in the constructor.
38 View(Document & document, Screen & screen, const VRect & bounds = VRect(0,0,1,1), const Colour & colour = Colour(0.f,0.f,0.f,1.f));
41 void Render(int width = 0, int height = 0);
43 void Translate(Real x, Real y);
44 void ScaleAroundPoint(Real x, Real y, Real scale_amount);
45 void SetBounds(const Rect & new_bounds);
47 Rect TransformToViewCoords(const Rect& inp) const;
49 const VRect& GetBounds() const { return m_bounds; }
52 const bool UsingGPUTransform() const { return m_use_gpu_transform; } // whether view transform calculated on CPU or GPU
53 const bool UsingGPURendering() const { return m_use_gpu_rendering; } // whether GPU shaders are used or CPU rendering
54 void ToggleGPUTransform() { m_use_gpu_transform = (!m_use_gpu_transform); m_bounds_dirty = true; m_buffer_dirty = true; }
55 void ToggleGPURendering() { m_use_gpu_rendering = (!m_use_gpu_rendering); m_bounds_dirty = true; m_buffer_dirty = true; }
56 void SetGPUTransform(bool state) {m_use_gpu_transform = state; m_bounds_dirty = true; m_buffer_dirty = true;}
58 void SetGPURendering(bool state) {m_use_gpu_rendering = state; m_bounds_dirty = true; m_buffer_dirty = true;}
60 bool ShowingBezierBounds() const {return m_show_bezier_bounds;} // render bounds rectangles
61 void ShowBezierBounds(bool state) {m_show_bezier_bounds = state; m_bounds_dirty = true; m_buffer_dirty = true;}
62 bool ShowingBezierType() const {return m_show_bezier_type;}
63 void ShowBezierType(bool state) {m_show_bezier_type = state; m_bounds_dirty = true; m_buffer_dirty = true;}
64 bool ShowingFillPoints() const {return m_show_fill_points;}
65 void ShowFillPoints(bool state) {m_show_fill_points = state; m_bounds_dirty = true; m_buffer_dirty = true;}
66 bool ShowingFillBounds() const {return m_show_fill_bounds;}
67 void ShowFillBounds(bool state) {m_show_fill_bounds = true;}
69 bool PerformingShading() const {return m_perform_shading;}
70 void PerformShading(bool state) {m_perform_shading = state; m_bounds_dirty = true; m_buffer_dirty = true;}
72 void ForceBoundsDirty() {m_bounds_dirty = true;}
73 void ForceBufferDirty() {m_buffer_dirty = true;}
74 void ForceRenderDirty() {m_render_dirty = true;}
76 void SetLazyRendering(bool state = true) {m_lazy_rendering = state;}
77 bool UsingLazyRendering() const {return m_lazy_rendering;}
79 void SaveBMP(const char * filename) {if (UsingGPURendering()) SaveGPUBMP(filename); else SaveCPUBMP(filename);}
81 void SaveCPUBMP(const char * filename);
82 void SaveGPUBMP(const char * filename);
84 Document & Doc() {return m_document;}
91 } __attribute__((packed));
93 void PrepareRender(); // call when m_render_dirty is true
94 void UpdateObjBoundsVBO(unsigned first_obj, unsigned last_obj); // call when m_buffer_dirty is true
96 void RenderRange(int width, int height, unsigned first_obj, unsigned last_obj);
98 bool m_use_gpu_transform;
99 bool m_use_gpu_rendering;
100 bool m_bounds_dirty; // the view bounds has changed (occurs when changing view)
101 bool m_buffer_dirty; // the object bounds have changed (also occurs when changing view, but only when not using GPU transforms)
102 bool m_render_dirty; // the document has changed (occurs when document first loaded)
103 Document & m_document;
105 FrameBuffer m_cached_display;
109 // Stores the view bounds.
110 GraphicsBuffer m_bounds_ubo; //bounds_dirty means this one has changed
111 // Stores the bounds for _all_ objects.
112 GraphicsBuffer m_objbounds_vbo; //buffer_dirty means this one has changed
114 // ObjectRenderers to be initialised in constructor
115 // Trust me it will be easier to generalise things this way. Even though there are pointers.
116 std::vector<ObjectRenderer*> m_object_renderers;
117 uint8_t * m_cpu_rendering_pixels; // pixels to be used for CPU rendering
121 bool m_perform_shading;
124 bool m_show_bezier_bounds;
125 bool m_show_bezier_type;
126 bool m_show_fill_points;
127 bool m_show_fill_bounds;
129 bool m_lazy_rendering;// don't redraw frames unless we need to
132 #ifndef QUADTREE_DISABLED
133 QuadTreeIndex m_current_quadtree_node; // The highest node we will traverse.
134 int m_quadtree_max_depth; // The maximum quadtree depth.
135 void RenderQuadtreeNode(int width, int height, QuadTreeIndex node, int remaining_depth);