6 #include "framebuffer.h"
7 #include "objectrenderer.h"
9 #include "transformationtype.h"
11 #define USE_GPU_TRANSFORM false
12 #define USE_GPU_RENDERING true
13 #define USE_SHADING !(USE_GPU_RENDERING) && true
21 typedef TRect<VReal> VRect;
25 * The View class manages a rectangular view into the document.
26 * It is responsible for coordinate transforms and rendering the document.
27 * ObjectRenderer's for each type of Object should be created in the constructor.
32 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));
35 void Render(int width = 0, int height = 0);
37 void Translate(Real x, Real y);
38 void ScaleAroundPoint(Real x, Real y, Real scale_amount);
39 void SetBounds(const Rect & new_bounds);
41 Rect TransformToViewCoords(const Rect& inp) const;
43 const VRect& GetBounds() const { return m_bounds; }
46 const bool UsingGPUTransform() const { return m_use_gpu_transform; } // whether view transform calculated on CPU or GPU
47 const bool UsingGPURendering() const { return m_use_gpu_rendering; } // whether GPU shaders are used or CPU rendering
48 void ToggleGPUTransform() { m_use_gpu_transform = (!m_use_gpu_transform); m_bounds_dirty = true; m_buffer_dirty = true; }
49 void ToggleGPURendering() { m_use_gpu_rendering = (!m_use_gpu_rendering); m_bounds_dirty = true; m_buffer_dirty = true; }
50 void SetGPUTransform(bool state) {m_use_gpu_transform = state; m_bounds_dirty = true; m_buffer_dirty = true;}
52 void SetGPURendering(bool state) {m_use_gpu_rendering = state; m_bounds_dirty = true; m_buffer_dirty = true;}
54 bool ShowingBezierBounds() const {return m_show_bezier_bounds;} // render bounds rectangles
55 void ShowBezierBounds(bool state) {m_show_bezier_bounds = state; m_bounds_dirty = true; m_buffer_dirty = true;}
56 bool ShowingBezierType() const {return m_show_bezier_type;}
57 void ShowBezierType(bool state) {m_show_bezier_type = state; m_bounds_dirty = true; m_buffer_dirty = true;}
58 bool ShowingFillPoints() const {return m_show_fill_points;}
59 void ShowFillPoints(bool state) {m_show_fill_points = state; m_bounds_dirty = true; m_buffer_dirty = true;}
60 bool ShowingFillBounds() const {return m_show_fill_bounds;}
61 void ShowFillBounds(bool state) {m_show_fill_bounds = true;}
63 bool PerformingShading() const {return m_perform_shading;}
64 void PerformShading(bool state) {m_perform_shading = state; m_bounds_dirty = true; m_buffer_dirty = true;}
66 void ForceBoundsDirty() {m_bounds_dirty = true;}
67 void ForceBufferDirty() {m_buffer_dirty = true;}
68 void ForceRenderDirty() {m_render_dirty = true;}
70 void QueryGPUBounds(const char * filename, const char * mode="r");
72 void SetLazyRendering(bool state = true) {m_lazy_rendering = state;}
73 bool UsingLazyRendering() const {return m_lazy_rendering;}
75 void SaveBMP(const char * filename) {if (UsingGPURendering()) SaveGPUBMP(filename); else SaveCPUBMP(filename);}
77 void SaveCPUBMP(const char * filename);
78 void SaveGPUBMP(const char * filename);
80 Document & Doc() {return m_document;}
87 } __attribute__((packed));
91 void PrepareRender(); // call when m_render_dirty is true
92 void UpdateObjBoundsVBO(unsigned first_obj, unsigned last_obj); // call when m_buffer_dirty is true
94 void RenderRange(int width, int height, unsigned first_obj, unsigned last_obj);
96 bool m_use_gpu_transform;
97 bool m_use_gpu_rendering;
98 bool m_bounds_dirty; // the view bounds has changed (occurs when changing view)
99 bool m_buffer_dirty; // the object bounds have changed (also occurs when changing view, but only when not using GPU transforms)
100 bool m_render_dirty; // the document has changed (occurs when document first loaded)
101 Document & m_document;
103 FrameBuffer m_cached_display;
107 // Stores the view bounds.
108 GraphicsBuffer m_bounds_ubo; //bounds_dirty means this one has changed
109 // Stores the bounds for _all_ objects.
110 GraphicsBuffer m_objbounds_vbo; //buffer_dirty means this one has changed
112 // ObjectRenderers to be initialised in constructor
113 // Trust me it will be easier to generalise things this way. Even though there are pointers.
114 std::vector<ObjectRenderer*> m_object_renderers;
115 uint8_t * m_cpu_rendering_pixels; // pixels to be used for CPU rendering
119 bool m_perform_shading;
122 bool m_show_bezier_bounds;
123 bool m_show_bezier_type;
124 bool m_show_fill_points;
125 bool m_show_fill_bounds;
127 bool m_lazy_rendering;// don't redraw frames unless we need to
129 FILE * m_query_gpu_bounds_on_next_frame;
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);