Tue, 21 Jan 2014 02:09:14 +0200
Merge ../ldforge into gl
Conflicts:
src/GLRenderer.cc
src/GLRenderer.h
src/LDObject.cc
674 | 1 | /* |
2 | * LDForge: LDraw parts authoring CAD | |
3 | * Copyright (C) 2013, 2014 Santeri Piippo | |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
4 | * |
674 | 5 | * This program is free software: you can redistribute it and/or modify |
6 | * it under the terms of the GNU General Public License as published by | |
7 | * the Free Software Foundation, either version 3 of the License, or | |
8 | * (at your option) any later version. | |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
9 | * |
674 | 10 | * This program is distributed in the hope that it will be useful, |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | * GNU General Public License for more details. | |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
14 | * |
674 | 15 | * You should have received a copy of the GNU General Public License |
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
17 | */ |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
18 | |
674 | 19 | #ifndef LDFORGE_GLCOMPILER_H |
20 | #define LDFORGE_GLCOMPILER_H | |
21 | ||
675
450827da2376
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
674
diff
changeset
|
22 | #include "Main.h" |
450827da2376
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
674
diff
changeset
|
23 | #include "GLRenderer.h" |
674 | 24 | #include "GLShared.h" |
25 | #include <QMap> | |
26 | ||
27 | // ============================================================================= | |
28 | // GLCompiler | |
29 | // | |
30 | // This class manages vertex arrays for the GL renderer, compiling vertices into | |
31 | // VAO-readable triangles which can be requested with getMergedBuffer. | |
32 | // | |
33 | // There are 6 main array types: | |
34 | // - the normal polygon array, for triangles | |
35 | // - edge line array, for lines | |
36 | // - conditional line array, for conditional lines. Kept separate so that they | |
37 | // can be drawn as dashed liness | |
38 | // - BFC array, this is the same as the normal polygon array except that the | |
39 | // polygons are listed twice, once normally and green and once reversed | |
40 | // and red, this allows BFC red/green view. | |
41 | // - Picking array, this is the same as the normal polygon array except the | |
42 | // polygons are compiled with their index color, this way the picking | |
43 | // method is capable of determining which object was selected by pixel | |
44 | // color. | |
45 | // - Edge line picking array, the pick array version of the edge line array. | |
46 | // Conditional lines are grouped with normal edgelines here. | |
47 | // | |
48 | // There are also these same 5 arrays for every LDObject compiled. The main | |
49 | // arrays are generated on demand from the ones in the current file's | |
50 | // LDObjects and stored in cache for faster renmm dering. | |
51 | // | |
52 | // The nested Array class contains a vector-like buffer of the Vertex structs, | |
53 | // these structs are the VAOs that get passed to the renderer. | |
54 | // | |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
55 | class GLCompiler |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
56 | { |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
57 | public: |
674 | 58 | enum E_ColorType |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
59 | { |
674 | 60 | E_NormalColor, |
61 | E_BFCFrontColor, | |
62 | E_BFCBackColor, | |
63 | E_PickColor, | |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
64 | }; |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
65 | |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
66 | struct CompiledTriangle |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
67 | { |
674 | 68 | Vertex verts[3]; |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
69 | uint8 numVerts; // 2 if a line |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
70 | uint32 rgb; // Color of this poly normally |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
71 | uint32 pickrgb; // Color of this poly while picking |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
72 | bool isCondLine; // Is this a conditional line? |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
73 | LDObject* obj; // Pointer to the object this poly represents |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
74 | }; |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
75 | |
673
8e6f5b3f9d38
- rename GLCompiler::Vertex to GLCompiler::VAO to avoid name conflicts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
672
diff
changeset
|
76 | struct VAO |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
77 | { |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
78 | float x, y, z; |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
79 | uint32 color; |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
80 | float pad[4]; |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
81 | }; |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
82 | |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
83 | using PolygonList = QList<CompiledTriangle>; |
674 | 84 | using VertexArray = QVector<VAO>; |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
85 | |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
86 | GLCompiler(); |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
87 | ~GLCompiler(); |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
88 | void setFile (LDDocument* file); |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
89 | void compileDocument(); |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
90 | void forgetObject (LDObject* obj); |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
91 | void initObject (LDObject* obj); |
674 | 92 | const VertexArray* getMergedBuffer (E_VertexArrayType type); |
93 | QColor getObjectColor (LDObject* obj, E_ColorType colortype) const; | |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
94 | void needMerge(); |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
95 | void stageForCompilation (LDObject* obj); |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
96 | |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
97 | static uint32 getColorRGB (const QColor& color); |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
98 | |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
99 | private: |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
100 | void compilePolygon (LDObject* drawobj, LDObject* trueobj, PolygonList& data); |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
101 | void compileObject (LDObject* obj); |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
102 | void compileSubObject (LDObject* obj, LDObject* topobj, PolygonList& data); |
674 | 103 | VertexArray* postprocess (const CompiledTriangle& poly, E_VertexArrayType type); |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
104 | |
674 | 105 | QMap<LDObject*, VertexArray*> m_objArrays; |
106 | VertexArray m_mainArrays[E_NumVertexArrays]; | |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
107 | LDDocument* m_file; |
674 | 108 | bool m_changed[E_NumVertexArrays]; |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
109 | LDObjectList m_staged; // Objects that need to be compiled |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
110 | }; |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
111 | |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
112 | extern GLCompiler g_vertexCompiler; |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
113 | |
674 | 114 | #endif // LDFORGE_GLCOMPILER_H |