Mon, 20 Jan 2014 16:42:18 +0200
- 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 | 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 rendering. | |
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 | ||
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 |