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

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