src/gldata.h

changeset 672
0925d25ea32c
parent 671
14a6da9c0bfe
child 673
8e6f5b3f9d38
equal deleted inserted replaced
671:14a6da9c0bfe 672:0925d25ea32c
1 #ifndef LDFORGE_GLDATA_H
2 #define LDFORGE_GLDATA_H
3
4 #include "types.h"
5 #include "gldraw.h"
6 #include <QMap>
7 #include <QRgb>
8
9 /* =============================================================================
10 * -----------------------------------------------------------------------------
11 * VertexCompiler
12 *
13 * This class manages vertex arrays for the GL renderer, compiling vertices into
14 * VAO-readable triangles which can be requested with getMergedBuffer.
15 *
16 * There are 5 main array types:
17 * - the normal polygon array, for triangles
18 * - edge line array, for lines
19 * - BFC array, this is the same as the normal polygon array except that the
20 * - polygons are listed twice, once normally and green and once reversed
21 * - and red, this allows BFC red/green view.
22 * - Picking array, this is the samea s the normal polygon array except the
23 * - polygons are compiled with their index color, this way the picking
24 * - method is capable of determining which object was selected by pixel
25 * - color.
26 * - Edge line picking array, the pick array version of the edge line array.
27 *
28 * There are also these same 5 arrays for every LDObject compiled. The main
29 * arrays are generated on demand from the ones in the current file's
30 * LDObjects and stored in cache for faster renmm dering.
31 *
32 * The nested Array class contains a vector-like buffer of the Vertex structs,
33 * these structs are the VAOs that get passed to the renderer.
34 */
35
36 class VertexCompiler
37 {
38 public:
39 enum ColorType
40 {
41 Normal,
42 BFCFront,
43 BFCBack,
44 PickColor,
45 };
46
47 struct CompiledTriangle
48 {
49 ::Vertex verts[3];
50 uint8 numVerts; // 2 if a line
51 uint32 rgb; // Color of this poly normally
52 uint32 pickrgb; // Color of this poly while picking
53 bool isCondLine; // Is this a conditional line?
54 LDObject* obj; // Pointer to the object this poly represents
55 };
56
57 struct Vertex
58 {
59 float x, y, z;
60 uint32 color;
61 float pad[4];
62 };
63
64 using PolygonList = QList<CompiledTriangle>;
65 using Array = QVector<VertexCompiler::Vertex>;
66
67 VertexCompiler();
68 ~VertexCompiler();
69 void setFile (LDDocument* file);
70 void compileDocument();
71 void forgetObject (LDObject* obj);
72 void initObject (LDObject* obj);
73 const Array* getMergedBuffer (GL::VAOType type);
74 QColor getObjectColor (LDObject* obj, ColorType list) const;
75 void needMerge();
76 void stageForCompilation (LDObject* obj);
77
78 static uint32 getColorRGB (const QColor& color);
79
80 private:
81 void compilePolygon (LDObject* drawobj, LDObject* trueobj, PolygonList& data);
82 void compileObject (LDObject* obj);
83 void compileSubObject (LDObject* obj, LDObject* topobj, PolygonList& data);
84 Array* postprocess (const VertexCompiler::CompiledTriangle& i, GLRenderer::VAOType type);
85
86 QMap<LDObject*, Array*> m_objArrays;
87 Array m_mainArrays[GL::ENumArrays];
88 LDDocument* m_file;
89 bool m_changed[GL::ENumArrays];
90 LDObjectList m_staged; // Objects that need to be compiled
91 };
92
93 extern VertexCompiler g_vertexCompiler;
94
95 #endif // LDFORGE_GLDATA_H

mercurial