src/gldata.h

Wed, 25 Sep 2013 11:02:44 +0300

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Wed, 25 Sep 2013 11:02:44 +0300
changeset 664
e3a32a79a10a
parent 490
fff86085017e
child 666
c595cfb4791c
permissions
-rw-r--r--

Merge branch 'master' into gl

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

mercurial