Wed, 25 Sep 2013 11:02:44 +0300
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 | 13 | /* ============================================================================= |
14 | * ----------------------------------------------------------------------------- | |
15 | * VertexCompiler | |
16 | * | |
17 | * This class manages vertex arrays for the GL renderer, compiling vertices into | |
18 | * VAO-readable triangles which can be requested with getMergedBuffer. | |
19 | * | |
20 | * There are 5 main array types: | |
21 | * - the normal polygon array, for triangles | |
22 | * - edge line array, for lines | |
23 | * - BFC array, this is the same as the normal polygon array except that the | |
24 | * - polygons are listed twice, once normally and green and once reversed | |
25 | * - and red, this allows BFC red/green view. | |
26 | * - Picking array, this is the samea s the normal polygon array except the | |
27 | * - polygons are compiled with their index color, this way the picking | |
28 | * - method is capable of determining which object was selected by pixel | |
29 | * - color. | |
30 | * - Edge line picking array, the pick array version of the edge line array. | |
31 | * | |
32 | * There are also these same 5 arrays for every LDObject compiled. The main | |
33 | * arrays are generated on demand from the ones in the current file's | |
34 | * LDObjects and stored in cache for faster rendering. | |
35 | * | |
36 | * The nested Array class contains a vector-like buffer of the Vertex structs, | |
37 | * these structs are the VAOs that get passed to the renderer. | |
38 | */ | |
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 | 51 | uint8 numVerts; // 2 if a line |
52 | QRgb rgb; // Color of this poly normally | |
53 | QRgb pickrgb; // Color of this poly while picking | |
54 | bool isCondLine; // Is this a conditional line? | |
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 | 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 | 74 | void resizeToFit (Size newSize); |
75 | const Size& allocatedSize() const; | |
76 | Size writtenSize() const; | |
77 | const Vertex* data() const; | |
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 | 82 | Vertex* m_data; |
83 | Vertex* m_ptr; | |
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 | 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 | 95 | void needMerge(); |
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 | 101 | void compilePolygon (LDObject* drawobj, LDObject* trueobj, List<CompiledTriangle>& data); |
102 | void compileObject (LDObject* obj); | |
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 | 106 | QMap<LDObject*, Array*> m_objArrays; |
443 | 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 | 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 |