src/gldata.h

Fri, 16 Aug 2013 11:05:21 +0300

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Fri, 16 Aug 2013 11:05:21 +0300
changeset 443
a70dd25dd4bb
parent 442
4852e815df29
child 487
a350c4b25133
permissions
-rw-r--r--

rework

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

mercurial