Slighlymoreworkingish
[ipdf/code.git] / src / view.h
1 #ifndef _VIEW_H
2 #define _VIEW_H
3
4 #include "ipdf.h"
5 #include "document.h"
6 #include "framebuffer.h"
7 #include "objectrenderer.h"
8
9 #define USE_GPU_TRANSFORM true 
10 #define USE_GPU_RENDERING true
11 #define USE_SHADING !(USE_GPU_RENDERING) && true
12
13 namespace IPDF
14 {
15         class Screen;
16         /**
17          * The View class manages a rectangular view into the document.
18          * It is responsible for coordinate transforms and rendering the document.
19          * ObjectRenderer's for each type of Object should be created in the constructor.
20          */
21         class View
22         {
23                 public:
24                         View(Document & document, Screen & screen, const Rect & bounds = Rect(0,0,1,1), const Colour & colour = Colour(0.f,0.f,0.f,1.f));
25                         virtual ~View();
26
27                         void Render(int width = 0, int height = 0);
28                         
29                         void Translate(Real x, Real y);
30                         void ScaleAroundPoint(Real x, Real y, Real scale_amount);
31                         void SetBounds(const Rect & new_bounds);
32                         
33                         Rect TransformToViewCoords(const Rect& inp) const;
34                         
35                         const Rect& GetBounds() const { return m_bounds; }
36                         
37                         
38                         const bool UsingGPUTransform() const { return m_use_gpu_transform; } // whether view transform calculated on CPU or GPU
39                         const bool UsingGPURendering() const { return m_use_gpu_rendering; } // whether GPU shaders are used or CPU rendering
40                         void ToggleGPUTransform() { m_use_gpu_transform = (!m_use_gpu_transform); m_bounds_dirty = true; m_buffer_dirty = true; }
41                         void ToggleGPURendering() { m_use_gpu_rendering = (!m_use_gpu_rendering); m_bounds_dirty = true; m_buffer_dirty = true; }
42                         
43                         void SetGPURendering(bool state) {m_use_gpu_rendering = state; m_bounds_dirty = true; m_buffer_dirty = true;}
44
45                         bool ShowingObjectBounds() const {return m_show_object_bounds;} // render bounds rectangles
46                         void ShowObjectBounds(bool state) {m_show_object_bounds = state; m_bounds_dirty = true; m_buffer_dirty = true;}
47                         
48                         bool PerformingShading() const {return m_perform_shading;}
49                         void PerformShading(bool state) {m_perform_shading = state; m_bounds_dirty = true; m_buffer_dirty = true;}
50
51                         void ForceBoundsDirty() {m_bounds_dirty = true;}                
52                         void ForceBufferDirty() {m_buffer_dirty = true;}                
53                         void ForceRenderDirty() {m_render_dirty = true;}
54
55                 private:
56                         struct GPUObjBounds
57                         {
58                                 float x0, y0;
59                                 float x1, y1;
60                         } __attribute__((packed));
61
62                         void PrepareRender(); // call when m_render_dirty is true
63                         void UpdateObjBoundsVBO(unsigned first_obj, unsigned last_obj); // call when m_buffer_dirty is true
64
65                         void RenderRange(int width, int height, unsigned first_obj, unsigned last_obj);
66
67                         bool m_use_gpu_transform;
68                         bool m_use_gpu_rendering;
69                         bool m_bounds_dirty; // the view bounds has changed (occurs when changing view)
70                         bool m_buffer_dirty; // the object bounds have changed (also occurs when changing view, but only when not using GPU transforms)
71                         bool m_render_dirty; // the document has changed (occurs when document first loaded)
72                         Document & m_document;
73                         Screen & m_screen;
74                         FrameBuffer m_cached_display;
75                         Rect m_bounds;
76                         Colour m_colour;
77
78                         // Stores the view bounds.
79                         GraphicsBuffer m_bounds_ubo; //bounds_dirty means this one has changed
80                         // Stores the bounds for _all_ objects.
81                         GraphicsBuffer m_objbounds_vbo; //buffer_dirty means this one has changed
82
83                         // ObjectRenderers to be initialised in constructor
84                         // Trust me it will be easier to generalise things this way. Even though there are pointers.
85                         std::vector<ObjectRenderer*> m_object_renderers; 
86                         uint8_t * m_cpu_rendering_pixels; // pixels to be used for CPU rendering
87                         
88                         // Debug rendering
89                         bool m_show_object_bounds;
90                         bool m_perform_shading;
91
92 #ifndef QUADTREE_DISABLED
93                         QuadTreeIndex m_current_quadtree_node;  // The highest node we will traverse.
94                         int m_quadtree_max_depth;               // The maximum quadtree depth.
95                         void RenderQuadtreeNode(int width, int height, QuadTreeIndex node, int remaining_depth);
96
97 #endif
98         };
99 }
100
101 #endif //_VIEW_H

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