src/glShared.h

Thu, 23 Feb 2017 20:25:47 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Thu, 23 Feb 2017 20:25:47 +0200
changeset 1161
e6a5ff67c057
parent 1151
0eddb5bcf25b
child 1173
6cd85b28f43b
permissions
-rw-r--r--

Removed the Origin and axes global constants.

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: 1049
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
740
dbf9f1294d94 - apply #pragma once to glShared.h
Santeri Piippo <crimsondusk64@gmail.com>
parents: 739
diff changeset
19 #pragma once
856
6bdc03091441 - and fixed compilation on linux systems too
Teemu Piippo <crimsondusk64@gmail.com>
parents: 855
diff changeset
20
1049
71946fed475a Removed the USE_QT5 macro now that we're Qt5 only.
Teemu Piippo <teemu@hecknology.net>
parents: 1036
diff changeset
21 #include <QOpenGLFunctions>
1151
0eddb5bcf25b Made fixed cameras matrix-based. This simplifies some math.
Teemu Piippo <teemu@hecknology.net>
parents: 1123
diff changeset
22 #include <QGenericMatrix>
1023
9450ac3cd930 Split grid stuff into a new class Grid in grid.cpp/grid.h
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
23 #include "basics.h"
856
6bdc03091441 - and fixed compilation on linux systems too
Teemu Piippo <crimsondusk64@gmail.com>
parents: 855
diff changeset
24
1151
0eddb5bcf25b Made fixed cameras matrix-based. This simplifies some math.
Teemu Piippo <teemu@hecknology.net>
parents: 1123
diff changeset
25 class GLRotationMatrix : public QGenericMatrix<4, 4, GLfloat>
0eddb5bcf25b Made fixed cameras matrix-based. This simplifies some math.
Teemu Piippo <teemu@hecknology.net>
parents: 1123
diff changeset
26 {
0eddb5bcf25b Made fixed cameras matrix-based. This simplifies some math.
Teemu Piippo <teemu@hecknology.net>
parents: 1123
diff changeset
27 public:
0eddb5bcf25b Made fixed cameras matrix-based. This simplifies some math.
Teemu Piippo <teemu@hecknology.net>
parents: 1123
diff changeset
28 GLRotationMatrix() {}
0eddb5bcf25b Made fixed cameras matrix-based. This simplifies some math.
Teemu Piippo <teemu@hecknology.net>
parents: 1123
diff changeset
29 GLRotationMatrix(GLfloat values[16]) :
0eddb5bcf25b Made fixed cameras matrix-based. This simplifies some math.
Teemu Piippo <teemu@hecknology.net>
parents: 1123
diff changeset
30 QGenericMatrix<4, 4, GLfloat> {values} {}
0eddb5bcf25b Made fixed cameras matrix-based. This simplifies some math.
Teemu Piippo <teemu@hecknology.net>
parents: 1123
diff changeset
31 GLRotationMatrix(std::initializer_list<GLfloat>&& values)
0eddb5bcf25b Made fixed cameras matrix-based. This simplifies some math.
Teemu Piippo <teemu@hecknology.net>
parents: 1123
diff changeset
32 {
0eddb5bcf25b Made fixed cameras matrix-based. This simplifies some math.
Teemu Piippo <teemu@hecknology.net>
parents: 1123
diff changeset
33 auto iterator = values.begin();
0eddb5bcf25b Made fixed cameras matrix-based. This simplifies some math.
Teemu Piippo <teemu@hecknology.net>
parents: 1123
diff changeset
34
0eddb5bcf25b Made fixed cameras matrix-based. This simplifies some math.
Teemu Piippo <teemu@hecknology.net>
parents: 1123
diff changeset
35 for (int i = 0; i < 4; ++i)
0eddb5bcf25b Made fixed cameras matrix-based. This simplifies some math.
Teemu Piippo <teemu@hecknology.net>
parents: 1123
diff changeset
36 for (int j = 0; j < 4; ++j)
0eddb5bcf25b Made fixed cameras matrix-based. This simplifies some math.
Teemu Piippo <teemu@hecknology.net>
parents: 1123
diff changeset
37 {
0eddb5bcf25b Made fixed cameras matrix-based. This simplifies some math.
Teemu Piippo <teemu@hecknology.net>
parents: 1123
diff changeset
38 (*this)(i, j) = *iterator;
0eddb5bcf25b Made fixed cameras matrix-based. This simplifies some math.
Teemu Piippo <teemu@hecknology.net>
parents: 1123
diff changeset
39 ++iterator;
0eddb5bcf25b Made fixed cameras matrix-based. This simplifies some math.
Teemu Piippo <teemu@hecknology.net>
parents: 1123
diff changeset
40 }
0eddb5bcf25b Made fixed cameras matrix-based. This simplifies some math.
Teemu Piippo <teemu@hecknology.net>
parents: 1123
diff changeset
41 }
0eddb5bcf25b Made fixed cameras matrix-based. This simplifies some math.
Teemu Piippo <teemu@hecknology.net>
parents: 1123
diff changeset
42 };
0eddb5bcf25b Made fixed cameras matrix-based. This simplifies some math.
Teemu Piippo <teemu@hecknology.net>
parents: 1123
diff changeset
43
0eddb5bcf25b Made fixed cameras matrix-based. This simplifies some math.
Teemu Piippo <teemu@hecknology.net>
parents: 1123
diff changeset
44 inline void glMultMatrixf(const GLRotationMatrix& matrix)
0eddb5bcf25b Made fixed cameras matrix-based. This simplifies some math.
Teemu Piippo <teemu@hecknology.net>
parents: 1123
diff changeset
45 {
0eddb5bcf25b Made fixed cameras matrix-based. This simplifies some math.
Teemu Piippo <teemu@hecknology.net>
parents: 1123
diff changeset
46 glMultMatrixf(matrix.constData());
0eddb5bcf25b Made fixed cameras matrix-based. This simplifies some math.
Teemu Piippo <teemu@hecknology.net>
parents: 1123
diff changeset
47 }
0eddb5bcf25b Made fixed cameras matrix-based. This simplifies some math.
Teemu Piippo <teemu@hecknology.net>
parents: 1123
diff changeset
48
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
49 class LDObject;
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
50
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
51 struct LDPolygon
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
52 {
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
53 char num;
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
54 Vertex vertices[4];
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
55 int id;
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
56 int color;
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
57
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
58 inline int numVertices() const
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
59 {
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
60 return (num == 5) ? 4 : num;
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
61 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
62 };
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
63
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: 1119
diff changeset
64 enum class VboClass
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
65 {
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: 1119
diff changeset
66 Lines,
15e46ea3151f Reworked iterable enums: they all are enum classes now and the end value is marked with "_End"
Teemu Piippo <teemu@hecknology.net>
parents: 1119
diff changeset
67 Triangles,
15e46ea3151f Reworked iterable enums: they all are enum classes now and the end value is marked with "_End"
Teemu Piippo <teemu@hecknology.net>
parents: 1119
diff changeset
68 Quads,
15e46ea3151f Reworked iterable enums: they all are enum classes now and the end value is marked with "_End"
Teemu Piippo <teemu@hecknology.net>
parents: 1119
diff changeset
69 ConditionalLines,
15e46ea3151f Reworked iterable enums: they all are enum classes now and the end value is marked with "_End"
Teemu Piippo <teemu@hecknology.net>
parents: 1119
diff changeset
70 _End
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
71 };
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
72
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: 1119
diff changeset
73 MAKE_ITERABLE_ENUM(VboClass)
1033
32153a1dbb15 - Refactoring...
Teemu Piippo <teemu@compsta2.com>
parents: 1023
diff changeset
74
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: 1119
diff changeset
75 enum class VboSubclass
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
76 {
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: 1119
diff changeset
77 Surfaces,
15e46ea3151f Reworked iterable enums: they all are enum classes now and the end value is marked with "_End"
Teemu Piippo <teemu@hecknology.net>
parents: 1119
diff changeset
78 NormalColors,
15e46ea3151f Reworked iterable enums: they all are enum classes now and the end value is marked with "_End"
Teemu Piippo <teemu@hecknology.net>
parents: 1119
diff changeset
79 PickColors,
15e46ea3151f Reworked iterable enums: they all are enum classes now and the end value is marked with "_End"
Teemu Piippo <teemu@hecknology.net>
parents: 1119
diff changeset
80 BfcFrontColors,
15e46ea3151f Reworked iterable enums: they all are enum classes now and the end value is marked with "_End"
Teemu Piippo <teemu@hecknology.net>
parents: 1119
diff changeset
81 BfcBackColors,
15e46ea3151f Reworked iterable enums: they all are enum classes now and the end value is marked with "_End"
Teemu Piippo <teemu@hecknology.net>
parents: 1119
diff changeset
82 RandomColors,
15e46ea3151f Reworked iterable enums: they all are enum classes now and the end value is marked with "_End"
Teemu Piippo <teemu@hecknology.net>
parents: 1119
diff changeset
83 Normals,
15e46ea3151f Reworked iterable enums: they all are enum classes now and the end value is marked with "_End"
Teemu Piippo <teemu@hecknology.net>
parents: 1119
diff changeset
84 _End
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
85 };
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
86
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: 1119
diff changeset
87 MAKE_ITERABLE_ENUM(VboSubclass)
1033
32153a1dbb15 - Refactoring...
Teemu Piippo <teemu@compsta2.com>
parents: 1023
diff changeset
88
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
89 enum
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
90 {
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: 1119
diff changeset
91 NumVbos = EnumLimits<VboClass>::Count * EnumLimits<VboSubclass>::Count
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
92 };
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
93
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
94 // KDevelop doesn't seem to understand some VBO stuff
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
95 #ifdef IN_IDE_PARSER
708
3155f2c05f89 - more debugging...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 706
diff changeset
96 using GLint = int;
3155f2c05f89 - more debugging...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 706
diff changeset
97 using GLsizei = int;
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
98 using GLenum = unsigned int;
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
99 using GLuint = unsigned int;
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
100 void glBindBuffer (GLenum, GLuint);
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
101 void glGenBuffers (GLuint, GLuint*);
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
102 void glDeleteBuffers (GLuint, GLuint*);
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
103 void glBufferData (GLuint, GLuint, void*, GLuint);
708
3155f2c05f89 - more debugging...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 706
diff changeset
104 void glBufferSubData (GLenum, GLint, GLsizei, void*);
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
105 #endif

mercurial