Fri, 24 Jan 2014 18:29:11 +0200
- converted to VBO
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 | { |
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 | 60 | enum E_ColorType |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
61 | { |
674 | 62 | E_NormalColor, |
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 | 103 | #endif // LDFORGE_GLCOMPILER_H |