src/gldata.h

changeset 443
a70dd25dd4bb
parent 442
4852e815df29
child 487
a350c4b25133
equal deleted inserted replaced
442:4852e815df29 443:a70dd25dd4bb
4 #include "types.h" 4 #include "types.h"
5 #include <QMap> 5 #include <QMap>
6 6
7 class QColor; 7 class QColor;
8 class LDFile; 8 class LDFile;
9
10 /* =============================================================================
11 * -----------------------------------------------------------------------------
12 * VertexCompiler
13 *
14 * This class manages vertex arrays for the GL renderer, compiling vertices into
15 * VAO-readable triangles which can be requested with getMergedBuffer.
16 *
17 * There are 5 main array types:
18 * - the normal polygon array, for triangles
19 * - edge line array, for lines
20 * - BFC array, this is the same as the normal polygon array except that the
21 * - polygons are listed twice, once normally and green and once reversed
22 * - and red, this allows BFC red/green view.
23 * - Picking array, this is the samea s the normal polygon array except the
24 * - polygons are compiled with their index color, this way the picking
25 * - method is capable of determining which object was selected by pixel
26 * - color.
27 * - Edge line picking array, the pick array version of the edge line array.
28 *
29 * There are also these same 5 arrays for every LDObject compiled. The main
30 * arrays are generated on demand from the ones in the current file's
31 * LDObjects and stored in cache for faster rendering.
32 *
33 * The nested Array class contains a vector-like buffer of the Vertex structs,
34 * these structs are the VAOs that get passed to the renderer.
35 */
9 36
10 class VertexCompiler { 37 class VertexCompiler {
11 public: 38 public:
12 enum ColorType { 39 enum ColorType {
13 Normal, 40 Normal,
14 BFCFront, 41 BFCFront,
15 BFCBack, 42 BFCBack,
16 PickColor, 43 PickColor,
17 }; 44 };
18 45
19 enum MergedArrayType { 46 enum ArrayType {
20 MainArray, 47 MainArray,
21 EdgeArray, 48 EdgeArray,
22 BFCArray, 49 BFCArray,
23 PickArray, 50 PickArray,
24 EdgePickArray, 51 EdgePickArray,
31 float pad[4]; 58 float pad[4];
32 }; 59 };
33 60
34 class Array { 61 class Array {
35 public: 62 public:
36 typedef int32 SizeType; 63 typedef int32 Size;
37 typedef Vertex DataType;
38 64
39 Array(); 65 Array();
40 Array (const Array& other) = delete; 66 Array (const Array& other) = delete;
41 ~Array(); 67 ~Array();
42 68
43 void clear(); 69 void clear();
44 void merge (Array* other); 70 void merge (Array* other);
45 void resizeToFit (SizeType newSize); 71 void resizeToFit (Size newSize);
46 const SizeType& allocatedSize() const; 72 const Size& allocatedSize() const;
47 SizeType writtenSize() const; 73 Size writtenSize() const;
48 const DataType* data() const; 74 const Vertex* data() const;
49 void write (DataType f); 75 void write (const VertexCompiler::Vertex& f);
50 Array& operator= (const Array& other) = delete; 76 Array& operator= (const Array& other) = delete;
51 77
52 private: 78 private:
53 DataType* m_data; 79 Vertex* m_data;
54 DataType* m_ptr; 80 Vertex* m_ptr;
55 SizeType m_size; 81 Size m_size;
56 }; 82 };
57 83
58 VertexCompiler(); 84 VertexCompiler();
59 ~VertexCompiler(); 85 ~VertexCompiler();
60 void setFile (LDFile* file); 86 void setFile (LDFile* file);
61 void compileFile(); 87 void compileFile();
62 void compileObject (LDObject* obj); 88 void compileObject (LDObject* obj, LDObject* topobj);
63 void forgetObject (LDObject* obj); 89 void forgetObject (LDObject* obj);
64 Array* getMergedBuffer (MergedArrayType type); 90 Array* getMergedBuffer (ArrayType type);
65 QColor getObjectColor (LDObject* obj, ColorType list) const; 91 QColor getObjectColor (LDObject* obj, ColorType list) const;
66 92
67 private: 93 private:
68 void compilePolygon (LDObject* drawobj, LDObject* trueobj); 94 void compilePolygon (LDObject* drawobj, LDObject* trueobj);
69 void compileVertex (vertex v, QColor col, VertexCompiler::Array* array); 95 void compileVertex (vertex v, QColor col, VertexCompiler::Array* array);
70 96
71 QMap<LDObject*, Array**> m_objArrays; 97 QMap<LDObject*, Array**> m_objArrays;
98 QMap<LDFile*, Array*> m_fileCache;
72 Array* m_mainArrays[NumArrays]; 99 Array* m_mainArrays[NumArrays];
73 LDFile* m_file; 100 LDFile* m_file;
74 bool m_changed[NumArrays]; 101 bool m_changed[NumArrays];
75 }; 102 };
76 103

mercurial