src/gl/common.h

Sat, 05 Mar 2022 13:38:22 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Sat, 05 Mar 2022 13:38:22 +0200
changeset 164
8305e2f968fb
parent 119
24275a4064f4
child 170
9b655f6fe5a1
permissions
-rw-r--r--

Render draw tool preview as a line when we only have 2 points

19
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
1 /*
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
2 * LDForge: LDraw parts authoring CAD
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
3 * Copyright (C) 2013 - 2018 Teemu Piippo
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
4 *
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
5 * This program is free software: you can redistribute it and/or modify
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
6 * it under the terms of the GNU General Public License as published by
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
7 * the Free Software Foundation, either version 3 of the License, or
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
8 * (at your option) any later version.
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
9 *
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
10 * This program is distributed in the hope that it will be useful,
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
13 * GNU General Public License for more details.
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
14 *
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
17 */
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
18
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
19 #pragma once
100
43ce3672648a fix build
Teemu Piippo <teemu@hecknology.net>
parents: 92
diff changeset
20 #include <QWidget>
19
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
21 #include <QColor>
53
3af627f7a40f added grid program
Teemu Piippo <teemu@hecknology.net>
parents: 48
diff changeset
22 #include <QOpenGLBuffer>
19
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
23 #include <QOpenGLFunctions>
53
3af627f7a40f added grid program
Teemu Piippo <teemu@hecknology.net>
parents: 48
diff changeset
24 #include <QOpenGLShader>
3af627f7a40f added grid program
Teemu Piippo <teemu@hecknology.net>
parents: 48
diff changeset
25 #include <QOpenGLShaderProgram>
3af627f7a40f added grid program
Teemu Piippo <teemu@hecknology.net>
parents: 48
diff changeset
26 #include <QOpenGLVertexArrayObject>
3af627f7a40f added grid program
Teemu Piippo <teemu@hecknology.net>
parents: 48
diff changeset
27 #include <glm/gtc/type_ptr.hpp>
19
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
28 #include "basics.h"
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
29 #include "colors.h"
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
30
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
31 namespace gl
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
32 {
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
33 struct Polygon;
53
3af627f7a40f added grid program
Teemu Piippo <teemu@hecknology.net>
parents: 48
diff changeset
34 class ShaderProgram;
3af627f7a40f added grid program
Teemu Piippo <teemu@hecknology.net>
parents: 48
diff changeset
35
3af627f7a40f added grid program
Teemu Piippo <teemu@hecknology.net>
parents: 48
diff changeset
36 void buildShaders(
3af627f7a40f added grid program
Teemu Piippo <teemu@hecknology.net>
parents: 48
diff changeset
37 QOpenGLShaderProgram* shaderProgram,
3af627f7a40f added grid program
Teemu Piippo <teemu@hecknology.net>
parents: 48
diff changeset
38 const char* vertexShaderSource,
3af627f7a40f added grid program
Teemu Piippo <teemu@hecknology.net>
parents: 48
diff changeset
39 const char* fragmentShaderSource);
3af627f7a40f added grid program
Teemu Piippo <teemu@hecknology.net>
parents: 48
diff changeset
40 void checkForGLErrors(QWidget* parent);
55
cb81ecb5fb23 grid stuff
Teemu Piippo <teemu@hecknology.net>
parents: 53
diff changeset
41 inline glm::vec3 colorToVector3(const QColor& color)
cb81ecb5fb23 grid stuff
Teemu Piippo <teemu@hecknology.net>
parents: 53
diff changeset
42 {
cb81ecb5fb23 grid stuff
Teemu Piippo <teemu@hecknology.net>
parents: 53
diff changeset
43 return {toFloat(color.redF()), toFloat(color.greenF()), toFloat(color.blueF())};
cb81ecb5fb23 grid stuff
Teemu Piippo <teemu@hecknology.net>
parents: 53
diff changeset
44 }
cb81ecb5fb23 grid stuff
Teemu Piippo <teemu@hecknology.net>
parents: 53
diff changeset
45 inline glm::vec4 colorToVector4(const QColor& color)
cb81ecb5fb23 grid stuff
Teemu Piippo <teemu@hecknology.net>
parents: 53
diff changeset
46 {
cb81ecb5fb23 grid stuff
Teemu Piippo <teemu@hecknology.net>
parents: 53
diff changeset
47 return {gl::colorToVector3(color), toFloat(color.alphaF())};
cb81ecb5fb23 grid stuff
Teemu Piippo <teemu@hecknology.net>
parents: 53
diff changeset
48 }
19
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
49 }
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
50
53
3af627f7a40f added grid program
Teemu Piippo <teemu@hecknology.net>
parents: 48
diff changeset
51 class gl::ShaderProgram : public QOpenGLShaderProgram
3af627f7a40f added grid program
Teemu Piippo <teemu@hecknology.net>
parents: 48
diff changeset
52 {
3af627f7a40f added grid program
Teemu Piippo <teemu@hecknology.net>
parents: 48
diff changeset
53 public:
3af627f7a40f added grid program
Teemu Piippo <teemu@hecknology.net>
parents: 48
diff changeset
54 using QOpenGLShaderProgram::QOpenGLShaderProgram;
3af627f7a40f added grid program
Teemu Piippo <teemu@hecknology.net>
parents: 48
diff changeset
55 // for some reason I cannot overload setUniformValue properly with this template thing
3af627f7a40f added grid program
Teemu Piippo <teemu@hecknology.net>
parents: 48
diff changeset
56 template<typename Float, glm::qualifier Prec>
3af627f7a40f added grid program
Teemu Piippo <teemu@hecknology.net>
parents: 48
diff changeset
57 void setUniformMatrix(const char* uniformName, const glm::mat<4, 4, Float, Prec>& value)
3af627f7a40f added grid program
Teemu Piippo <teemu@hecknology.net>
parents: 48
diff changeset
58 {
3af627f7a40f added grid program
Teemu Piippo <teemu@hecknology.net>
parents: 48
diff changeset
59 const float (*array)[4][4] = reinterpret_cast<const float(*)[4][4]>(glm::value_ptr(value));
3af627f7a40f added grid program
Teemu Piippo <teemu@hecknology.net>
parents: 48
diff changeset
60 this->setUniformValue(uniformName, *array);
3af627f7a40f added grid program
Teemu Piippo <teemu@hecknology.net>
parents: 48
diff changeset
61 }
55
cb81ecb5fb23 grid stuff
Teemu Piippo <teemu@hecknology.net>
parents: 53
diff changeset
62 template<typename Float, glm::qualifier Prec>
cb81ecb5fb23 grid stuff
Teemu Piippo <teemu@hecknology.net>
parents: 53
diff changeset
63 void setUniformVector(const char* uniformName, const glm::vec<4, Float, Prec>& value)
53
3af627f7a40f added grid program
Teemu Piippo <teemu@hecknology.net>
parents: 48
diff changeset
64 {
55
cb81ecb5fb23 grid stuff
Teemu Piippo <teemu@hecknology.net>
parents: 53
diff changeset
65 this->setUniformValue(uniformName, value.x, value.y, value.z, value.w);
53
3af627f7a40f added grid program
Teemu Piippo <teemu@hecknology.net>
parents: 48
diff changeset
66 }
3af627f7a40f added grid program
Teemu Piippo <teemu@hecknology.net>
parents: 48
diff changeset
67 };
3af627f7a40f added grid program
Teemu Piippo <teemu@hecknology.net>
parents: 48
diff changeset
68
19
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
69 struct gl::Polygon
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
70 {
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
71 enum Type : qint8
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
72 {
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
73 EdgeLine,
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
74 Triangle,
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
75 Quadrilateral,
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
76 ConditionalEdge
80
764381756899 simplification
Teemu Piippo <teemu@hecknology.net>
parents: 73
diff changeset
77 } type;
33
4c41bfe2ec6e replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
78 glm::vec3 vertices[4];
35
98906a94732f renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents: 34
diff changeset
79 ldraw::Color color;
73
97df974b5ed5 ldraw::Id is now templated for extra type safety
Teemu Piippo <teemu@hecknology.net>
parents: 55
diff changeset
80 ldraw::id_t id;
19
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
81
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
82 /**
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
83 * @return amount of vertices used for geometry
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
84 */
22
6da867fa5429 commit work on GL rendering
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
85 inline unsigned int numPolygonVertices() const
19
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
86 {
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
87 if (type == Type::ConditionalEdge)
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
88 return 2;
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
89 else
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
90 return numVertices();
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
91 }
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
92
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
93 /**
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
94 * @return amount of vertices
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
95 */
22
6da867fa5429 commit work on GL rendering
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
96 inline unsigned int numVertices() const
19
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
97 {
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
98 switch (type)
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
99 {
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
100 case Type::EdgeLine:
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
101 return 2;
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
102 case Type::Triangle:
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
103 return 3;
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
104 case Type::ConditionalEdge:
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
105 case Type::Quadrilateral:
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
106 return 4;
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
107 }
22
6da867fa5429 commit work on GL rendering
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
108 return 0;
19
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
109 }
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
110 };
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
111
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
112 Q_DECLARE_METATYPE(gl::Polygon)
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
113
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
114 namespace gl
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
115 {
80
764381756899 simplification
Teemu Piippo <teemu@hecknology.net>
parents: 73
diff changeset
116 constexpr Polygon::Type POLYGON_TYPES[] =
764381756899 simplification
Teemu Piippo <teemu@hecknology.net>
parents: 73
diff changeset
117 {
764381756899 simplification
Teemu Piippo <teemu@hecknology.net>
parents: 73
diff changeset
118 Polygon::Type::EdgeLine,
764381756899 simplification
Teemu Piippo <teemu@hecknology.net>
parents: 73
diff changeset
119 Polygon::Type::Triangle,
764381756899 simplification
Teemu Piippo <teemu@hecknology.net>
parents: 73
diff changeset
120 Polygon::Type::Quadrilateral,
764381756899 simplification
Teemu Piippo <teemu@hecknology.net>
parents: 73
diff changeset
121 Polygon::Type::ConditionalEdge
764381756899 simplification
Teemu Piippo <teemu@hecknology.net>
parents: 73
diff changeset
122 };
764381756899 simplification
Teemu Piippo <teemu@hecknology.net>
parents: 73
diff changeset
123
764381756899 simplification
Teemu Piippo <teemu@hecknology.net>
parents: 73
diff changeset
124 constexpr int NUM_POLYGON_TYPES = countof(POLYGON_TYPES);
764381756899 simplification
Teemu Piippo <teemu@hecknology.net>
parents: 73
diff changeset
125
73
97df974b5ed5 ldraw::Id is now templated for extra type safety
Teemu Piippo <teemu@hecknology.net>
parents: 55
diff changeset
126 inline Polygon edgeLine(const glm::vec3& v_1, const glm::vec3& v_2, ldraw::Color color, ldraw::id_t id)
19
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
127 {
21
Teemu Piippo <teemu@hecknology.net>
parents: 19
diff changeset
128 return {Polygon::EdgeLine, {v_1, v_2}, color, id};
19
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
129 }
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
130
21
Teemu Piippo <teemu@hecknology.net>
parents: 19
diff changeset
131 inline Polygon triangle(
33
4c41bfe2ec6e replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
132 const glm::vec3& v_1,
4c41bfe2ec6e replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
133 const glm::vec3& v_2,
4c41bfe2ec6e replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
134 const glm::vec3& v_3,
35
98906a94732f renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents: 34
diff changeset
135 ldraw::Color color,
73
97df974b5ed5 ldraw::Id is now templated for extra type safety
Teemu Piippo <teemu@hecknology.net>
parents: 55
diff changeset
136 ldraw::id_t id)
19
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
137 {
21
Teemu Piippo <teemu@hecknology.net>
parents: 19
diff changeset
138 return {Polygon::Triangle, {v_1, v_2, v_3}, color, id};
19
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
139 }
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
140
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
141 inline Polygon quadrilateral(
33
4c41bfe2ec6e replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
142 const glm::vec3& v_1,
4c41bfe2ec6e replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
143 const glm::vec3& v_2,
4c41bfe2ec6e replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
144 const glm::vec3& v_3,
4c41bfe2ec6e replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
145 const glm::vec3& v_4,
35
98906a94732f renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents: 34
diff changeset
146 ldraw::Color color,
73
97df974b5ed5 ldraw::Id is now templated for extra type safety
Teemu Piippo <teemu@hecknology.net>
parents: 55
diff changeset
147 ldraw::id_t id)
19
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
148 {
21
Teemu Piippo <teemu@hecknology.net>
parents: 19
diff changeset
149 return {Polygon::Quadrilateral, {v_1, v_2, v_3, v_4}, color, id};
19
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
150 }
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
151
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
152 inline Polygon conditionalEdge(
33
4c41bfe2ec6e replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
153 const glm::vec3& v_1,
4c41bfe2ec6e replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
154 const glm::vec3& v_2,
4c41bfe2ec6e replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
155 const glm::vec3& control_1,
4c41bfe2ec6e replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
156 const glm::vec3& control_2,
35
98906a94732f renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents: 34
diff changeset
157 ldraw::Color color,
73
97df974b5ed5 ldraw::Id is now templated for extra type safety
Teemu Piippo <teemu@hecknology.net>
parents: 55
diff changeset
158 ldraw::id_t id)
19
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
159 {
21
Teemu Piippo <teemu@hecknology.net>
parents: 19
diff changeset
160 return {Polygon::ConditionalEdge, {v_1, v_2, control_1, control_2}, color, id};
19
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
161 }
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
162
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
163 // Vbo names
26
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 22
diff changeset
164 enum class ArrayClass : std::uint8_t
19
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
165 {
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
166 Lines,
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
167 Triangles,
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
168 Quads,
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
169 ConditionalLines
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
170 };
35
98906a94732f renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents: 34
diff changeset
171
115
ed884a2fb009 fix too long lines
Teemu Piippo <teemu@hecknology.net>
parents: 100
diff changeset
172 constexpr ArrayClass ARRAY_CLASSES[] = {
ed884a2fb009 fix too long lines
Teemu Piippo <teemu@hecknology.net>
parents: 100
diff changeset
173 ArrayClass::Lines,
ed884a2fb009 fix too long lines
Teemu Piippo <teemu@hecknology.net>
parents: 100
diff changeset
174 ArrayClass::Triangles,
ed884a2fb009 fix too long lines
Teemu Piippo <teemu@hecknology.net>
parents: 100
diff changeset
175 ArrayClass::Quads,
ed884a2fb009 fix too long lines
Teemu Piippo <teemu@hecknology.net>
parents: 100
diff changeset
176 ArrayClass::ConditionalLines,
ed884a2fb009 fix too long lines
Teemu Piippo <teemu@hecknology.net>
parents: 100
diff changeset
177 };
26
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 22
diff changeset
178 constexpr int NUM_ARRAY_CLASSES = countof(ARRAY_CLASSES);
19
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
179
91
9eb5e06f34c3 add comments
Teemu Piippo <teemu@hecknology.net>
parents: 73
diff changeset
180 // Different ways to render the scene
19
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
181 enum class RenderStyle
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
182 {
91
9eb5e06f34c3 add comments
Teemu Piippo <teemu@hecknology.net>
parents: 73
diff changeset
183 // Normal rendering style
19
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
184 Normal,
91
9eb5e06f34c3 add comments
Teemu Piippo <teemu@hecknology.net>
parents: 73
diff changeset
185 // Render all polygons as lines
19
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
186 Wireframe,
91
9eb5e06f34c3 add comments
Teemu Piippo <teemu@hecknology.net>
parents: 73
diff changeset
187 // Use green colour for front faces and red colour for back faces
19
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
188 BfcRedGreen,
91
9eb5e06f34c3 add comments
Teemu Piippo <teemu@hecknology.net>
parents: 73
diff changeset
189 // Use a different colour for each object
46
98645c8e7704 added the pick scene
Teemu Piippo <teemu@hecknology.net>
parents: 45
diff changeset
190 RandomColors,
91
9eb5e06f34c3 add comments
Teemu Piippo <teemu@hecknology.net>
parents: 73
diff changeset
191 // Render so that the colour of an object has an one to one correspondence with its id
119
Teemu Piippo <teemu@hecknology.net>
parents: 115
diff changeset
192 PickScene,
Teemu Piippo <teemu@hecknology.net>
parents: 115
diff changeset
193 // Render a scene where vertices can be picked
Teemu Piippo <teemu@hecknology.net>
parents: 115
diff changeset
194 VertexPickScene,
19
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
195 };
91
9eb5e06f34c3 add comments
Teemu Piippo <teemu@hecknology.net>
parents: 73
diff changeset
196
9eb5e06f34c3 add comments
Teemu Piippo <teemu@hecknology.net>
parents: 73
diff changeset
197 // Different ways to render fragments.
37
90443fb328ea wired renderstyle up
Teemu Piippo <teemu@hecknology.net>
parents: 35
diff changeset
198 // These are also defined in shaders
90443fb328ea wired renderstyle up
Teemu Piippo <teemu@hecknology.net>
parents: 35
diff changeset
199 enum class FragmentStyle
90443fb328ea wired renderstyle up
Teemu Piippo <teemu@hecknology.net>
parents: 35
diff changeset
200 {
91
9eb5e06f34c3 add comments
Teemu Piippo <teemu@hecknology.net>
parents: 73
diff changeset
201 // Use normal colours
37
90443fb328ea wired renderstyle up
Teemu Piippo <teemu@hecknology.net>
parents: 35
diff changeset
202 Normal = 0,
91
9eb5e06f34c3 add comments
Teemu Piippo <teemu@hecknology.net>
parents: 73
diff changeset
203 // Use a distinctive green colour for BFC red/green view
37
90443fb328ea wired renderstyle up
Teemu Piippo <teemu@hecknology.net>
parents: 35
diff changeset
204 BfcGreen = 1,
91
9eb5e06f34c3 add comments
Teemu Piippo <teemu@hecknology.net>
parents: 73
diff changeset
205 // Use a distinctive red colour for BFC red/green view
37
90443fb328ea wired renderstyle up
Teemu Piippo <teemu@hecknology.net>
parents: 35
diff changeset
206 BfcRed = 2,
91
9eb5e06f34c3 add comments
Teemu Piippo <teemu@hecknology.net>
parents: 73
diff changeset
207 // Use a colour based on the object to distinguish objects
37
90443fb328ea wired renderstyle up
Teemu Piippo <teemu@hecknology.net>
parents: 35
diff changeset
208 RandomColors = 3,
91
9eb5e06f34c3 add comments
Teemu Piippo <teemu@hecknology.net>
parents: 73
diff changeset
209 // Use a colour that codes the object's id
46
98645c8e7704 added the pick scene
Teemu Piippo <teemu@hecknology.net>
parents: 45
diff changeset
210 Id = 4,
119
Teemu Piippo <teemu@hecknology.net>
parents: 115
diff changeset
211 // Render everything black
Teemu Piippo <teemu@hecknology.net>
parents: 115
diff changeset
212 Black = 5,
37
90443fb328ea wired renderstyle up
Teemu Piippo <teemu@hecknology.net>
parents: 35
diff changeset
213 };
39
caac957e9834 Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents: 37
diff changeset
214
caac957e9834 Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents: 37
diff changeset
215 // User options for rendering
caac957e9834 Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents: 37
diff changeset
216 struct RenderPreferences
caac957e9834 Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents: 37
diff changeset
217 {
caac957e9834 Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents: 37
diff changeset
218 gl::RenderStyle style = gl::RenderStyle::Normal;
caac957e9834 Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents: 37
diff changeset
219 QColor mainColor{255, 255, 64};
40
30cb5e836736 added configurable background color
Teemu Piippo <teemu@hecknology.net>
parents: 39
diff changeset
220 QColor backgroundColor{48, 48, 48};
48
3c10f0e2fbe0 added selection highlighting
Teemu Piippo <teemu@hecknology.net>
parents: 46
diff changeset
221 QColor selectedColor{32, 32, 255};
44
c6114b3af3a6 added configurable line thickness
Teemu Piippo <teemu@hecknology.net>
parents: 41
diff changeset
222 GLfloat lineThickness = 2.0f;
45
272c84c7c87e added configurable line anti-aliasing
Teemu Piippo <teemu@hecknology.net>
parents: 44
diff changeset
223 bool lineAntiAliasing = true;
39
caac957e9834 Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents: 37
diff changeset
224 };
19
ed9685f44ab3 added missing files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
225 }

mercurial