src/GLCompiler.h

Fri, 24 Jan 2014 18:31:25 +0200

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Fri, 24 Jan 2014 18:31:25 +0200
changeset 677
b3c32a2741be
parent 676
f7f965742fd5
child 678
0526d8404097
permissions
-rw-r--r--

- removed some unneeded code

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 {
676
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
57 PROPERTY (public, LDDocumentPointer, Document, NO_OPS, STOCK_WRITE)
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
58
672
0925d25ea32c - renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
59 public:
674
3d8ab0f89102 - refactoring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 673
diff changeset
60 enum E_ColorType
672
0925d25ea32c - renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
61 {
674
3d8ab0f89102 - refactoring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 673
diff changeset
62 E_NormalColor,
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 GLCompiler();
0925d25ea32c - renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
67 ~GLCompiler();
676
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
68 void compileDocument();
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
69 void forgetObject (LDObject* obj);
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
70 void initObject (LDObject* obj);
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
71 QColor getObjectColor (LDObject* obj, E_ColorType colortype) const;
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
72 void needMerge();
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
73 void prepareVBOArray (E_VBOArray type);
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
74 void stageForCompilation (LDObject* obj);
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
75
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
76 static uint32 getColorRGB (const QColor& color);
672
0925d25ea32c - renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
77
676
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
78 inline GLuint getVBOIndex (E_VBOArray array) const
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
79 {
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
80 return m_mainVBOIndices[array];
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
81 }
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
82
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
83 inline int getVBOCount (E_VBOArray array) const
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
84 {
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
85 return m_mainArrays[array].size() / 3;
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
86 }
672
0925d25ea32c - renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
87
0925d25ea32c - renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
88 private:
676
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
89 void compileStaged();
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
90 void compileObject (LDObject* obj);
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
91 void compileSubObject (LDObject* obj, LDObject* topobj);
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
92 void writeColor (QVector< float >& array, const QColor& color);
672
0925d25ea32c - renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
93
676
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
94 QMap<LDObject*, QVector<float>*> m_objArrays;
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
95 QVector<float> m_mainArrays[VBO_NumArrays];
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
96 GLuint m_mainVBOIndices[VBO_NumArrays];
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
97 bool m_changed[VBO_NumArrays];
672
0925d25ea32c - renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
98 LDObjectList m_staged; // Objects that need to be compiled
0925d25ea32c - renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
99 };
0925d25ea32c - renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
100
0925d25ea32c - renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
101 extern GLCompiler g_vertexCompiler;
0925d25ea32c - renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
102
674
3d8ab0f89102 - refactoring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 673
diff changeset
103 #endif // LDFORGE_GLCOMPILER_H

mercurial