src/gldata.h

Mon, 20 Jan 2014 16:42:18 +0200

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Mon, 20 Jan 2014 16:42:18 +0200
changeset 668
6a05c4969074
parent 666
c595cfb4791c
child 671
14a6da9c0bfe
permissions
-rw-r--r--

- now compiles again

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

mercurial