src/GLCompiler.h

Tue, 21 Jan 2014 02:09:14 +0200

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Tue, 21 Jan 2014 02:09:14 +0200
changeset 675
450827da2376
parent 674
3d8ab0f89102
child 676
f7f965742fd5
permissions
-rw-r--r--

Merge ../ldforge into gl

Conflicts:
src/GLRenderer.cc
src/GLRenderer.h
src/LDObject.cc

674
3d8ab0f89102 - refactoring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 673
diff changeset
1 /*
3d8ab0f89102 - refactoring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 673
diff changeset
2 * LDForge: LDraw parts authoring CAD
3d8ab0f89102 - refactoring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 673
diff changeset
3 * Copyright (C) 2013, 2014 Santeri Piippo
672
0925d25ea32c - renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
4 *
674
3d8ab0f89102 - refactoring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 673
diff changeset
5 * This program is free software: you can redistribute it and/or modify
3d8ab0f89102 - refactoring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 673
diff changeset
6 * it under the terms of the GNU General Public License as published by
3d8ab0f89102 - refactoring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 673
diff changeset
7 * the Free Software Foundation, either version 3 of the License, or
3d8ab0f89102 - refactoring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 673
diff changeset
8 * (at your option) any later version.
672
0925d25ea32c - renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
9 *
674
3d8ab0f89102 - refactoring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 673
diff changeset
10 * This program is distributed in the hope that it will be useful,
3d8ab0f89102 - refactoring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 673
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
3d8ab0f89102 - refactoring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 673
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3d8ab0f89102 - refactoring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 673
diff changeset
13 * GNU General Public License for more details.
672
0925d25ea32c - renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
14 *
674
3d8ab0f89102 - refactoring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 673
diff changeset
15 * You should have received a copy of the GNU General Public License
3d8ab0f89102 - refactoring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 673
diff changeset
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
3d8ab0f89102 - refactoring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 673
diff changeset
19 #ifndef LDFORGE_GLCOMPILER_H
3d8ab0f89102 - refactoring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 673
diff changeset
20 #define LDFORGE_GLCOMPILER_H
3d8ab0f89102 - refactoring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 673
diff changeset
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
3d8ab0f89102 - refactoring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 673
diff changeset
24 #include "GLShared.h"
3d8ab0f89102 - refactoring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 673
diff changeset
25 #include <QMap>
3d8ab0f89102 - refactoring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 673
diff changeset
26
3d8ab0f89102 - refactoring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 673
diff changeset
27 // =============================================================================
3d8ab0f89102 - refactoring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 673
diff changeset
28 // GLCompiler
3d8ab0f89102 - refactoring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 673
diff changeset
29 //
3d8ab0f89102 - refactoring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 673
diff changeset
30 // This class manages vertex arrays for the GL renderer, compiling vertices into
3d8ab0f89102 - refactoring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 673
diff changeset
31 // VAO-readable triangles which can be requested with getMergedBuffer.
3d8ab0f89102 - refactoring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 673
diff changeset
32 //
3d8ab0f89102 - refactoring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 673
diff changeset
33 // There are 6 main array types:
3d8ab0f89102 - refactoring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 673
diff changeset
34 // - the normal polygon array, for triangles
3d8ab0f89102 - refactoring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 673
diff changeset
35 // - edge line array, for lines
3d8ab0f89102 - refactoring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 673
diff changeset
36 // - conditional line array, for conditional lines. Kept separate so that they
3d8ab0f89102 - refactoring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 673
diff changeset
37 // can be drawn as dashed liness
3d8ab0f89102 - refactoring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 673
diff changeset
38 // - BFC array, this is the same as the normal polygon array except that the
3d8ab0f89102 - refactoring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 673
diff changeset
39 // polygons are listed twice, once normally and green and once reversed
3d8ab0f89102 - refactoring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 673
diff changeset
40 // and red, this allows BFC red/green view.
3d8ab0f89102 - refactoring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 673
diff changeset
41 // - Picking array, this is the same as the normal polygon array except the
3d8ab0f89102 - refactoring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 673
diff changeset
42 // polygons are compiled with their index color, this way the picking
3d8ab0f89102 - refactoring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 673
diff changeset
43 // method is capable of determining which object was selected by pixel
3d8ab0f89102 - refactoring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 673
diff changeset
44 // color.
3d8ab0f89102 - refactoring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 673
diff changeset
45 // - Edge line picking array, the pick array version of the edge line array.
3d8ab0f89102 - refactoring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 673
diff changeset
46 // Conditional lines are grouped with normal edgelines here.
3d8ab0f89102 - refactoring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 673
diff changeset
47 //
3d8ab0f89102 - refactoring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 673
diff changeset
48 // There are also these same 5 arrays for every LDObject compiled. The main
3d8ab0f89102 - refactoring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 673
diff changeset
49 // arrays are generated on demand from the ones in the current file's
3d8ab0f89102 - refactoring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 673
diff changeset
50 // LDObjects and stored in cache for faster renmm dering.
3d8ab0f89102 - refactoring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 673
diff changeset
51 //
3d8ab0f89102 - refactoring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 673
diff changeset
52 // The nested Array class contains a vector-like buffer of the Vertex structs,
3d8ab0f89102 - refactoring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 673
diff changeset
53 // these structs are the VAOs that get passed to the renderer.
3d8ab0f89102 - refactoring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 673
diff changeset
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
3d8ab0f89102 - refactoring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 673
diff changeset
58 enum E_ColorType
672
0925d25ea32c - renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
59 {
674
3d8ab0f89102 - refactoring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 673
diff changeset
60 E_NormalColor,
3d8ab0f89102 - refactoring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 673
diff changeset
61 E_BFCFrontColor,
3d8ab0f89102 - refactoring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 673
diff changeset
62 E_BFCBackColor,
3d8ab0f89102 - refactoring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 673
diff changeset
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
3d8ab0f89102 - refactoring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 673
diff changeset
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
3d8ab0f89102 - refactoring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 673
diff changeset
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
3d8ab0f89102 - refactoring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 673
diff changeset
92 const VertexArray* getMergedBuffer (E_VertexArrayType type);
3d8ab0f89102 - refactoring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 673
diff changeset
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
3d8ab0f89102 - refactoring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 673
diff changeset
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
3d8ab0f89102 - refactoring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 673
diff changeset
105 QMap<LDObject*, VertexArray*> m_objArrays;
3d8ab0f89102 - refactoring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 673
diff changeset
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
3d8ab0f89102 - refactoring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 673
diff changeset
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
3d8ab0f89102 - refactoring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 673
diff changeset
114 #endif // LDFORGE_GLCOMPILER_H

mercurial