src/glcompiler.h

Mon, 06 Mar 2017 11:48:45 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Mon, 06 Mar 2017 11:48:45 +0200
changeset 1201
a3455a81c5c9
parent 1173
6cd85b28f43b
permissions
-rw-r--r--

Simplified GLCompiler vbo interface

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
1072
9ce9496427f2 Happy new year 2017!
Teemu Piippo <teemu@hecknology.net>
parents: 1014
diff changeset
3 * Copyright (C) 2013 - 2017 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"
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
23 #include <QMap>
978
4603d8fd063e Make documents members of the main window
Teemu Piippo <crimsondusk64@gmail.com>
parents: 970
diff changeset
24 #include <QSet>
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
25
1173
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
26 /*
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
27 * Compiles LDObjects into polygons for the GLRenderer to draw.
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
28 */
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
29 class GLCompiler : public QObject, public HierarchyElement, protected QOpenGLFunctions
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
30 {
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
31 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
32
713
46377d340c23 - more debug stuff....
Santeri Piippo <crimsondusk64@gmail.com>
parents: 706
diff changeset
33 public:
759
038985b4a154 - added a selection hover effect to the renderer. selecting objects just became a lot more convenient...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 736
diff changeset
34 GLCompiler (GLRenderer* renderer);
713
46377d340c23 - more debug stuff....
Santeri Piippo <crimsondusk64@gmail.com>
parents: 706
diff changeset
35 ~GLCompiler();
1173
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
36
1201
a3455a81c5c9 Simplified GLCompiler vbo interface
Teemu Piippo <teemu@hecknology.net>
parents: 1173
diff changeset
37 Q_SLOT void initialize();
a3455a81c5c9 Simplified GLCompiler vbo interface
Teemu Piippo <teemu@hecknology.net>
parents: 1173
diff changeset
38 GLuint vbo (VboClass surface, VboSubclass complement);
a3455a81c5c9 Simplified GLCompiler vbo interface
Teemu Piippo <teemu@hecknology.net>
parents: 1173
diff changeset
39 int vboSize (VboClass surface) const;
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
40
713
46377d340c23 - more debug stuff....
Santeri Piippo <crimsondusk64@gmail.com>
parents: 706
diff changeset
41 private:
1173
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
42 struct ObjectVboData
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
43 {
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
44 QVector<GLfloat> data[NumVbos];
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
45 };
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
46
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 978
diff changeset
47 void compileStaged();
1173
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
48 void compilePolygon (LDPolygon& poly, LDObject* polygonOwner, ObjectVboData& objectInfo);
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
49 Q_SLOT void compileObject (LDObject* obj);
1173
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
50 QColor getColorForPolygon (LDPolygon& poly, LDObject* topobj, VboSubclass complement);
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
51 QColor indexColorForID (qint32 id) const;
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
52 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
53 Q_SLOT void recompile();
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
54 void dropObjectInfo (LDObject* obj);
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
55 Q_SLOT void forgetObject(LDObject* object);
1173
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
56 void stageForCompilation (LDObject* obj);
1201
a3455a81c5c9 Simplified GLCompiler vbo interface
Teemu Piippo <teemu@hecknology.net>
parents: 1173
diff changeset
57 void prepareVBO (int vbonum);
1173
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
58 void unstage (LDObject* obj);
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
59
1201
a3455a81c5c9 Simplified GLCompiler vbo interface
Teemu Piippo <teemu@hecknology.net>
parents: 1173
diff changeset
60 static int vboNumber (VboClass surface, VboSubclass complement);
a3455a81c5c9 Simplified GLCompiler vbo interface
Teemu Piippo <teemu@hecknology.net>
parents: 1173
diff changeset
61
1173
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
62 QMap<LDObject*, ObjectVboData> m_objectInfo;
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 978
diff changeset
63 QSet<LDObject*> m_staged; // Objects that need to be compiled
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 978
diff changeset
64 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
65 bool m_vboChanged[NumVbos] = {true};
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
66 int m_vboSizes[NumVbos] = {0};
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 978
diff changeset
67 GLRenderer* m_renderer;
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
68 };
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
69
1173
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
70 #define CHECK_GL_ERROR() { checkGLError(this, __FILE__, __LINE__); }
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
71 void checkGLError (HierarchyElement* element, QString file, int line);

mercurial