src/glcompiler.h

Thu, 20 Jun 2019 08:54:35 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Thu, 20 Jun 2019 08:54:35 +0300
changeset 1440
265b2e95a8e8
parent 1436
241d3e452b32
permissions
-rw-r--r--

uuid things

706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1 /*
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
2 * LDForge: LDraw parts authoring CAD
1326
69a90bd2dba2 Happy new year 2018
Teemu Piippo <teemu@hecknology.net>
parents: 1306
diff changeset
3 * Copyright (C) 2013 - 2018 Teemu Piippo
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
4 *
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
5 * This program is free software: you can redistribute it and/or modify
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
6 * it under the terms of the GNU General Public License as published by
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
7 * the Free Software Foundation, either version 3 of the License, or
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
8 * (at your option) any later version.
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
9 *
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
10 * This program is distributed in the hope that it will be useful,
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
13 * GNU General Public License for more details.
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
14 *
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
17 */
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
18
736
0446af72b2ee - use #pragma once for the gl compiler header
Santeri Piippo <crimsondusk64@gmail.com>
parents: 726
diff changeset
19 #pragma once
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
20 #include "main.h"
1144
4f226fd97826 Renamed glRenderer.cpp → glrenderer.cpp
Teemu Piippo <teemu@hecknology.net>
parents: 1123
diff changeset
21 #include "glrenderer.h"
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
22 #include "glShared.h"
1371
b8df4748d04e automatically center the model in the renderer
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
23 #include "types/boundingbox.h"
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
24 #include <QMap>
978
4603d8fd063e Make documents members of the main window
Teemu Piippo <crimsondusk64@gmail.com>
parents: 970
diff changeset
25 #include <QSet>
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
26
1436
241d3e452b32 moved GL stuff into a new gl namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1427
diff changeset
27 namespace gl
241d3e452b32 moved GL stuff into a new gl namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1427
diff changeset
28 {
241d3e452b32 moved GL stuff into a new gl namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1427
diff changeset
29 class Compiler;
241d3e452b32 moved GL stuff into a new gl namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1427
diff changeset
30 class Renderer;
241d3e452b32 moved GL stuff into a new gl namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1427
diff changeset
31 }
241d3e452b32 moved GL stuff into a new gl namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1427
diff changeset
32
1173
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
33 /*
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
34 * Compiles LDObjects into polygons for the GLRenderer to draw.
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
35 */
1436
241d3e452b32 moved GL stuff into a new gl namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1427
diff changeset
36 class gl::Compiler : public QObject, public HierarchyElement, protected QOpenGLFunctions
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
37 {
1113
5f3139c802bf Cleaned up GLCompiler. Among other changes, the compiler no longer has to be told what to compile.
Teemu Piippo <teemu@hecknology.net>
parents: 1098
diff changeset
38 Q_OBJECT
5f3139c802bf Cleaned up GLCompiler. Among other changes, the compiler no longer has to be told what to compile.
Teemu Piippo <teemu@hecknology.net>
parents: 1098
diff changeset
39
713
46377d340c23 - more debug stuff....
Santeri Piippo <crimsondusk64@gmail.com>
parents: 706
diff changeset
40 public:
1436
241d3e452b32 moved GL stuff into a new gl namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1427
diff changeset
41 Compiler (Renderer* renderer);
241d3e452b32 moved GL stuff into a new gl namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1427
diff changeset
42 ~Compiler();
1173
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
43
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 978
diff changeset
44 void initialize();
1371
b8df4748d04e automatically center the model in the renderer
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
45 Vertex modelCenter();
1173
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
46 void prepareVBO (int vbonum);
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 978
diff changeset
47 GLuint vbo (int vbonum) const;
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 978
diff changeset
48 int vboSize (int vbonum) const;
1251
e75cc5bff076 Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents: 1247
diff changeset
49 QItemSelectionModel* selectionModel() const;
e75cc5bff076 Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents: 1247
diff changeset
50 void setSelectionModel(QItemSelectionModel* _selectionModel);
1306
be85306198a2 red/green view rework complete
Teemu Piippo <teemu@hecknology.net>
parents: 1251
diff changeset
51 void fullUpdate();
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
52
1123
15e46ea3151f Reworked iterable enums: they all are enum classes now and the end value is marked with "_End"
Teemu Piippo <teemu@hecknology.net>
parents: 1121
diff changeset
53 static int vboNumber (VboClass surface, VboSubclass complement);
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
54
1246
0054d13ed614 used mvc selection models
Santeri Piippo
parents: 1245
diff changeset
55 public slots:
0054d13ed614 used mvc selection models
Santeri Piippo
parents: 1245
diff changeset
56 void selectionChanged(const QItemSelection& selected, const QItemSelection& deselected);
0054d13ed614 used mvc selection models
Santeri Piippo
parents: 1245
diff changeset
57
1372
641060842b92 fixed the scene bounding box not getting updated as it should
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
58 signals:
641060842b92 fixed the scene bounding box not getting updated as it should
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
59 void sceneChanged();
641060842b92 fixed the scene bounding box not getting updated as it should
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
60
713
46377d340c23 - more debug stuff....
Santeri Piippo <crimsondusk64@gmail.com>
parents: 706
diff changeset
61 private:
1173
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
62 struct ObjectVboData
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
63 {
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
64 QVector<GLfloat> data[NumVbos];
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
65 };
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
66
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 978
diff changeset
67 void compileStaged();
1400
ae83213bdd63 refactored LDPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1392
diff changeset
68 void compilePolygon(LDPolygon& poly, const QModelIndex& polygonOwnerIndex, ObjectVboData& objectInfo);
1440
265b2e95a8e8 uuid things
Teemu Piippo <teemu@hecknology.net>
parents: 1436
diff changeset
69 Q_SLOT void compileObject(const Uuid& index);
1427
b7ba2af33c13 add const
Teemu Piippo <teemu@hecknology.net>
parents: 1400
diff changeset
70 QColor getColorForPolygon(const LDPolygon& polygon, const QModelIndex& polygonOwnerIndex, VboSubclass complement);
1173
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
71 QColor indexColorForID (qint32 id) const;
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
72 void needMerge();
1113
5f3139c802bf Cleaned up GLCompiler. Among other changes, the compiler no longer has to be told what to compile.
Teemu Piippo <teemu@hecknology.net>
parents: 1098
diff changeset
73 Q_SLOT void recompile();
1440
265b2e95a8e8 uuid things
Teemu Piippo <teemu@hecknology.net>
parents: 1436
diff changeset
74 void dropObjectInfo (const Uuid& index);
265b2e95a8e8 uuid things
Teemu Piippo <teemu@hecknology.net>
parents: 1436
diff changeset
75 Q_SLOT void forgetObject(const Uuid& index);
265b2e95a8e8 uuid things
Teemu Piippo <teemu@hecknology.net>
parents: 1436
diff changeset
76 void stageForCompilation(const Uuid& index);
265b2e95a8e8 uuid things
Teemu Piippo <teemu@hecknology.net>
parents: 1436
diff changeset
77 void unstage (const Uuid& index);
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
78
1440
265b2e95a8e8 uuid things
Teemu Piippo <teemu@hecknology.net>
parents: 1436
diff changeset
79 QMap<Uuid, ObjectVboData> m_objectInfo;
265b2e95a8e8 uuid things
Teemu Piippo <teemu@hecknology.net>
parents: 1436
diff changeset
80 QSet<Uuid> m_staged; // Objects that need to be compiled
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 978
diff changeset
81 GLuint m_vbo[NumVbos];
1113
5f3139c802bf Cleaned up GLCompiler. Among other changes, the compiler no longer has to be told what to compile.
Teemu Piippo <teemu@hecknology.net>
parents: 1098
diff changeset
82 bool m_vboChanged[NumVbos] = {true};
1371
b8df4748d04e automatically center the model in the renderer
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
83 bool needBoundingBoxRebuild = true;
1113
5f3139c802bf Cleaned up GLCompiler. Among other changes, the compiler no longer has to be told what to compile.
Teemu Piippo <teemu@hecknology.net>
parents: 1098
diff changeset
84 int m_vboSizes[NumVbos] = {0};
1436
241d3e452b32 moved GL stuff into a new gl namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1427
diff changeset
85 gl::Renderer* m_renderer;
1251
e75cc5bff076 Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents: 1247
diff changeset
86 QItemSelectionModel* _selectionModel = nullptr;
1371
b8df4748d04e automatically center the model in the renderer
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
87 BoundingBox boundingBox;
1245
338d66111168 more work on mvc
Santeri Piippo
parents: 1244
diff changeset
88
338d66111168 more work on mvc
Santeri Piippo
parents: 1244
diff changeset
89 private slots:
338d66111168 more work on mvc
Santeri Piippo
parents: 1244
diff changeset
90 void handleRowInsertion(const QModelIndex&, int first, int last);
338d66111168 more work on mvc
Santeri Piippo
parents: 1244
diff changeset
91 void handleRowRemoval(const QModelIndex&, int first, int last);
338d66111168 more work on mvc
Santeri Piippo
parents: 1244
diff changeset
92 void handleDataChange(const QModelIndex& topLeft, const QModelIndex &bottomRight);
1247
7e1ce2fc066b converted highlighting to mvc
Santeri Piippo
parents: 1246
diff changeset
93 void handleObjectHighlightingChanged(const QModelIndex& oldIndex, const QModelIndex& newIndex);
1246
0054d13ed614 used mvc selection models
Santeri Piippo
parents: 1245
diff changeset
94 void clearSelectionModel();
1440
265b2e95a8e8 uuid things
Teemu Piippo <teemu@hecknology.net>
parents: 1436
diff changeset
95 void objectRemoved(const Uuid &id);
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
96 };
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
97
1392
0541d9b21968 fix compiler warnings
Teemu Piippo <teemu@hecknology.net>
parents: 1391
diff changeset
98 #define CHECK_GL_ERROR() { checkGLError(__FILE__, __LINE__); }
0541d9b21968 fix compiler warnings
Teemu Piippo <teemu@hecknology.net>
parents: 1391
diff changeset
99 void checkGLError (QString file, int line);

mercurial