Wed, 26 Feb 2020 02:21:07 +0200
grid stuff
24 | 1 | /* |
2 | * LDForge: LDraw parts authoring CAD | |
3 | * Copyright (C) 2013 - 2020 Teemu Piippo | |
4 | * | |
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. | |
9 | * | |
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. | |
14 | * | |
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/>. | |
17 | */ | |
18 | ||
26 | 19 | #include <GL/glut.h> |
28 | 20 | #include <glm/ext/matrix_transform.hpp> |
21 | #include <glm/ext/matrix_clip_space.hpp> | |
17 | 22 | #include <QMouseEvent> |
26 | 23 | #include <QMessageBox> |
47 | 24 | #include <QAbstractButton> |
55 | 25 | #include "geometry.h" |
17 | 26 | #include "partrenderer.h" |
27 | ||
35
98906a94732f
renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents:
34
diff
changeset
|
28 | PartRenderer::PartRenderer( |
98906a94732f
renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents:
34
diff
changeset
|
29 | Model* model, |
98906a94732f
renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents:
34
diff
changeset
|
30 | DocumentManager* documents, |
98906a94732f
renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents:
34
diff
changeset
|
31 | const ldraw::ColorTable& colorTable, |
98906a94732f
renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents:
34
diff
changeset
|
32 | QWidget* parent) : |
21 | 33 | QOpenGLWidget{parent}, |
34 | model{model}, | |
35 | documents{documents}, | |
26 | 36 | colorTable{colorTable}, |
53 | 37 | compiler{new gl::Compiler{this->colorTable, this}}, |
38 | gridProgram{this} | |
17 | 39 | { |
40 | this->setMouseTracking(true); | |
41 | } | |
42 | ||
26 | 43 | PartRenderer::~PartRenderer() |
44 | { | |
45 | } | |
46 | ||
53 | 47 | static QVector3D vec3FromQColor(const QColor& color) |
48 | { | |
49 | return {(float)color.redF(), (float)color.greenF(), (float)color.blueF()}; | |
50 | } | |
51 | ||
17 | 52 | void PartRenderer::initializeGL() |
53 | { | |
54 | this->initializeOpenGLFunctions(); | |
22
6da867fa5429
commit work on GL rendering
Teemu Piippo <teemu@hecknology.net>
parents:
21
diff
changeset
|
55 | if (glGetError() != GL_NO_ERROR) |
17 | 56 | { |
57 | abort(); | |
58 | } | |
53 | 59 | this->gridProgram.emplace(this); |
60 | this->gridProgram->initialize(); | |
27
c57fb7a5ffa3
commit work done on plugging vao to the gl renderer, renders nonsense for now
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
61 | this->compiler->initialize(); |
39
caac957e9834
Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents:
37
diff
changeset
|
62 | this->compiler->build(this->model, this->documents, this->renderPreferences); |
17 | 63 | this->initialized = true; |
32 | 64 | this->modelQuaternion = glm::angleAxis(glm::radians(30.0f), glm::vec3{-1, 0, 0}); |
65 | this->modelQuaternion *= glm::angleAxis(glm::radians(225.0f), glm::vec3{-0, 1, 0}); | |
55 | 66 | this->setupBackgroundColor(); |
67 | this->updateModelMatrix(); | |
31
b6df269a2c6b
fix remaining rendering control issues
Teemu Piippo <teemu@hecknology.net>
parents:
30
diff
changeset
|
68 | this->updateViewMatrix(); |
30 | 69 | this->update(); |
17 | 70 | } |
71 | ||
72 | void PartRenderer::resizeGL(int width, int height) | |
73 | { | |
28 | 74 | glViewport(0, 0, width, height); |
55 | 75 | this->viewportMatrix = { |
76 | {1, 0, 0}, | |
77 | {0, 1, 0}, | |
78 | {width * 0.5f, height * 0.5f, 1} | |
79 | }; | |
28 | 80 | this->projectionMatrix = glm::perspective( |
31
b6df269a2c6b
fix remaining rendering control issues
Teemu Piippo <teemu@hecknology.net>
parents:
30
diff
changeset
|
81 | glm::radians(45.0f), |
28 | 82 | static_cast<float>(width) / static_cast<float>(height), |
83 | 0.1f, | |
31
b6df269a2c6b
fix remaining rendering control issues
Teemu Piippo <teemu@hecknology.net>
parents:
30
diff
changeset
|
84 | 10000.f); |
34
1de2b8d64e9f
added some sort of lighting
Teemu Piippo <teemu@hecknology.net>
parents:
32
diff
changeset
|
85 | this->compiler->setUniformMatrix("projectionMatrix", this->projectionMatrix); |
53 | 86 | this->gridProgram->setProjectionMatrix(this->projectionMatrix); |
17 | 87 | } |
88 | ||
26 | 89 | static GLenum getGlTypeForArrayClass(const gl::ArrayClass vboClass) |
21 | 90 | { |
91 | switch (vboClass) | |
92 | { | |
26 | 93 | case gl::ArrayClass::Lines: |
94 | case gl::ArrayClass::ConditionalLines: | |
21 | 95 | return GL_LINES; |
26 | 96 | case gl::ArrayClass::Triangles: |
21 | 97 | return GL_TRIANGLES; |
26 | 98 | case gl::ArrayClass::Quads: |
21 | 99 | return GL_QUADS; |
100 | } | |
101 | throw std::runtime_error{"Bad vbo class passed to getGlTypeForVboClass"}; | |
102 | } | |
103 | ||
17 | 104 | void PartRenderer::paintGL() |
105 | { | |
47 | 106 | glEnable(GL_DEPTH_TEST); |
107 | glShadeModel(GL_SMOOTH); | |
108 | this->renderScene(); | |
109 | } | |
110 | ||
111 | void PartRenderer::renderScene() | |
112 | { | |
53 | 113 | this->checkForGLErrors(); |
46 | 114 | if (this->renderPreferences.lineAntiAliasing && this->renderPreferences.style != gl::RenderStyle::PickScene) |
45
272c84c7c87e
added configurable line anti-aliasing
Teemu Piippo <teemu@hecknology.net>
parents:
44
diff
changeset
|
115 | { |
272c84c7c87e
added configurable line anti-aliasing
Teemu Piippo <teemu@hecknology.net>
parents:
44
diff
changeset
|
116 | glEnable(GL_LINE_SMOOTH); |
272c84c7c87e
added configurable line anti-aliasing
Teemu Piippo <teemu@hecknology.net>
parents:
44
diff
changeset
|
117 | glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); |
272c84c7c87e
added configurable line anti-aliasing
Teemu Piippo <teemu@hecknology.net>
parents:
44
diff
changeset
|
118 | } |
272c84c7c87e
added configurable line anti-aliasing
Teemu Piippo <teemu@hecknology.net>
parents:
44
diff
changeset
|
119 | else { |
272c84c7c87e
added configurable line anti-aliasing
Teemu Piippo <teemu@hecknology.net>
parents:
44
diff
changeset
|
120 | glDisable(GL_LINE_SMOOTH); |
272c84c7c87e
added configurable line anti-aliasing
Teemu Piippo <teemu@hecknology.net>
parents:
44
diff
changeset
|
121 | } |
46 | 122 | if (this->renderPreferences.style != gl::RenderStyle::PickScene) |
123 | { | |
47 | 124 | const QColor& backgroundColor = this->renderPreferences.backgroundColor; |
46 | 125 | glClearColor( |
126 | static_cast<float>(backgroundColor.redF()), | |
127 | static_cast<float>(backgroundColor.greenF()), | |
128 | static_cast<float>(backgroundColor.blueF()), | |
129 | 1.0f); | |
51 | 130 | this->compiler->setUniform("useLighting", GL_TRUE); |
46 | 131 | } |
132 | else | |
133 | { | |
134 | glClearColor(0.0f, 0.0f, 0.0f, 1.0f); | |
51 | 135 | this->compiler->setUniform("useLighting", GL_FALSE); |
46 | 136 | } |
53 | 137 | this->checkForGLErrors(); |
48
3c10f0e2fbe0
added selection highlighting
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
138 | this->compiler->setUniform("selectedColor", vec3FromQColor(this->renderPreferences.selectedColor)); |
3c10f0e2fbe0
added selection highlighting
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
139 | this->compiler->setUniform("highlighted", this->highlighted.value); |
51 | 140 | this->checkForGLErrors(); |
26 | 141 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
142 | glEnable(GL_DEPTH_TEST); | |
143 | glEnable(GL_POLYGON_OFFSET_FILL); | |
144 | glPolygonOffset(1.0f, 1.0f); | |
44
c6114b3af3a6
added configurable line thickness
Teemu Piippo <teemu@hecknology.net>
parents:
40
diff
changeset
|
145 | glLineWidth(this->renderPreferences.lineThickness); |
39
caac957e9834
Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents:
37
diff
changeset
|
146 | switch (this->renderPreferences.style) |
18 | 147 | { |
148 | case gl::RenderStyle::Normal: | |
37 | 149 | this->setFragmentStyle(gl::FragmentStyle::Normal); |
150 | this->renderAllArrays(); | |
151 | break; | |
18 | 152 | case gl::RenderStyle::BfcRedGreen: |
37 | 153 | glEnable(GL_CULL_FACE); |
154 | glCullFace(GL_BACK); | |
155 | this->setFragmentStyle(gl::FragmentStyle::BfcGreen); | |
156 | renderVao(gl::ArrayClass::Triangles); | |
157 | renderVao(gl::ArrayClass::Quads); | |
158 | glCullFace(GL_FRONT); | |
159 | this->setFragmentStyle(gl::FragmentStyle::BfcRed); | |
160 | renderVao(gl::ArrayClass::Triangles); | |
161 | renderVao(gl::ArrayClass::Quads); | |
162 | glDisable(GL_CULL_FACE); | |
163 | this->setFragmentStyle(gl::FragmentStyle::Normal); | |
164 | renderVao(gl::ArrayClass::Lines); | |
18 | 165 | case gl::RenderStyle::RandomColors: |
37 | 166 | this->setFragmentStyle(gl::FragmentStyle::RandomColors); |
167 | this->renderAllArrays(); | |
18 | 168 | break; |
46 | 169 | case gl::RenderStyle::PickScene: |
170 | glLineWidth(3.0f); | |
171 | this->setFragmentStyle(gl::FragmentStyle::Id); | |
172 | this->renderAllArrays(); | |
173 | break; | |
18 | 174 | case gl::RenderStyle::Wireframe: |
175 | glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); | |
37 | 176 | this->setFragmentStyle(gl::FragmentStyle::Normal); |
177 | this->renderAllArrays(); | |
18 | 178 | break; |
179 | } | |
53 | 180 | glEnable(GL_BLEND); |
181 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | |
182 | this->gridProgram->draw(); | |
183 | glDisable(GL_BLEND); | |
37 | 184 | glDisable(GL_POLYGON_OFFSET_FILL); |
185 | } | |
186 | ||
187 | void PartRenderer::renderAllArrays() | |
188 | { | |
26 | 189 | // Lines need to be rendered last so that anti-aliasing does not interfere with polygon rendering. |
190 | renderVao(gl::ArrayClass::Triangles); | |
191 | renderVao(gl::ArrayClass::Quads); | |
192 | renderVao(gl::ArrayClass::Lines); | |
193 | } | |
194 | ||
37 | 195 | |
31
b6df269a2c6b
fix remaining rendering control issues
Teemu Piippo <teemu@hecknology.net>
parents:
30
diff
changeset
|
196 | void PartRenderer::updateViewMatrix() |
b6df269a2c6b
fix remaining rendering control issues
Teemu Piippo <teemu@hecknology.net>
parents:
30
diff
changeset
|
197 | { |
b6df269a2c6b
fix remaining rendering control issues
Teemu Piippo <teemu@hecknology.net>
parents:
30
diff
changeset
|
198 | // I'm not quite sure why using the exponent function on the zoom factor causes linear zoom behavior |
b6df269a2c6b
fix remaining rendering control issues
Teemu Piippo <teemu@hecknology.net>
parents:
30
diff
changeset
|
199 | const double z = 2 * std::exp(this->zoom) * (1 + this->compiler->modelDistance()); |
b6df269a2c6b
fix remaining rendering control issues
Teemu Piippo <teemu@hecknology.net>
parents:
30
diff
changeset
|
200 | this->viewMatrix = glm::lookAt(glm::vec3{0, 0, z}, {0, 0, 0}, {0, -1, 0}); |
34
1de2b8d64e9f
added some sort of lighting
Teemu Piippo <teemu@hecknology.net>
parents:
32
diff
changeset
|
201 | this->compiler->setUniformMatrix("viewMatrix", this->viewMatrix); |
53 | 202 | this->gridProgram->setViewMatrix(this->viewMatrix); |
31
b6df269a2c6b
fix remaining rendering control issues
Teemu Piippo <teemu@hecknology.net>
parents:
30
diff
changeset
|
203 | } |
b6df269a2c6b
fix remaining rendering control issues
Teemu Piippo <teemu@hecknology.net>
parents:
30
diff
changeset
|
204 | |
55 | 205 | void PartRenderer::updateModelMatrix() |
206 | { | |
207 | const glm::mat4 modelMatrix = glm::mat4_cast(this->modelQuaternion); | |
208 | this->compiler->setUniformMatrix("modelMatrix", modelMatrix); | |
209 | this->gridProgram->setModelMatrix(modelMatrix); | |
210 | this->update(); | |
211 | } | |
212 | ||
213 | void PartRenderer::setupBackgroundColor() | |
214 | { | |
215 | if (this->gridProgram.has_value()) | |
216 | { | |
217 | const bool isDark = luma(this->renderPreferences.backgroundColor) < 0.25; | |
218 | this->gridProgram->setGridColor(isDark ? Qt::white : Qt::black); | |
219 | } | |
220 | } | |
221 | ||
27
c57fb7a5ffa3
commit work done on plugging vao to the gl renderer, renders nonsense for now
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
222 | void PartRenderer::renderVao(const gl::ArrayClass arrayClass) |
26 | 223 | { |
224 | this->compiler->bindVertexArray(arrayClass); | |
34
1de2b8d64e9f
added some sort of lighting
Teemu Piippo <teemu@hecknology.net>
parents:
32
diff
changeset
|
225 | const std::size_t vertexCount = this->compiler->vertexCount(arrayClass); |
51 | 226 | this->checkForGLErrors(); |
26 | 227 | glDrawArrays(getGlTypeForArrayClass(arrayClass), 0, static_cast<GLsizei>(vertexCount)); |
51 | 228 | this->checkForGLErrors(); |
26 | 229 | this->compiler->releaseVertexArray(arrayClass); |
230 | this->checkForGLErrors(); | |
231 | } | |
232 | ||
233 | void PartRenderer::checkForGLErrors() | |
234 | { | |
53 | 235 | gl::checkForGLErrors(this); |
236 | } | |
237 | ||
238 | void gl::checkForGLErrors(QWidget* parent) | |
239 | { | |
26 | 240 | GLenum glError; |
241 | QStringList errors; | |
242 | while ((glError = glGetError()) != GL_NO_ERROR) | |
21 | 243 | { |
244 | const QString glErrorString = QString::fromLatin1(reinterpret_cast<const char*>(::gluErrorString(glError))); | |
26 | 245 | errors.append(glErrorString); |
246 | } | |
247 | if (not errors.isEmpty()) | |
248 | { | |
53 | 249 | QMessageBox box{parent}; |
47 | 250 | box.setIcon(QMessageBox::Critical); |
53 | 251 | box.setText(QObject::tr("OpenGL error: %1").arg(errors.join("\n"))); |
252 | box.setWindowTitle(QObject::tr("OpenGL error")); | |
47 | 253 | box.setStandardButtons(QMessageBox::Close); |
53 | 254 | box.button(QMessageBox::Close)->setText(QObject::tr("Damn it")); |
47 | 255 | box.exec(); |
21 | 256 | } |
17 | 257 | } |
258 | ||
259 | void PartRenderer::mouseMoveEvent(QMouseEvent* event) | |
260 | { | |
261 | const bool left = event->buttons() & Qt::LeftButton; | |
262 | const QPointF move = pointToPointF(event->pos()) - this->lastMousePosition; | |
263 | if (left and not move.isNull()) | |
264 | { | |
31
b6df269a2c6b
fix remaining rendering control issues
Teemu Piippo <teemu@hecknology.net>
parents:
30
diff
changeset
|
265 | // q_x is the rotation of the brick along the vertical y-axis, because turning the |
b6df269a2c6b
fix remaining rendering control issues
Teemu Piippo <teemu@hecknology.net>
parents:
30
diff
changeset
|
266 | // vertical axis causes horizontal (=x) rotation. Likewise q_y is the rotation of the |
b6df269a2c6b
fix remaining rendering control issues
Teemu Piippo <teemu@hecknology.net>
parents:
30
diff
changeset
|
267 | // brick along the horizontal x-axis, which causes vertical rotation. |
b6df269a2c6b
fix remaining rendering control issues
Teemu Piippo <teemu@hecknology.net>
parents:
30
diff
changeset
|
268 | const auto scalar = 0.006f; |
b6df269a2c6b
fix remaining rendering control issues
Teemu Piippo <teemu@hecknology.net>
parents:
30
diff
changeset
|
269 | const float move_x = static_cast<float>(move.x()); |
b6df269a2c6b
fix remaining rendering control issues
Teemu Piippo <teemu@hecknology.net>
parents:
30
diff
changeset
|
270 | const float move_y = static_cast<float>(move.y()); |
b6df269a2c6b
fix remaining rendering control issues
Teemu Piippo <teemu@hecknology.net>
parents:
30
diff
changeset
|
271 | const glm::quat q_x = glm::angleAxis(scalar * move_x, glm::vec3{0, -1, 0}); |
b6df269a2c6b
fix remaining rendering control issues
Teemu Piippo <teemu@hecknology.net>
parents:
30
diff
changeset
|
272 | const glm::quat q_y = glm::angleAxis(scalar * move_y, glm::vec3{-1, 0, 0}); |
b6df269a2c6b
fix remaining rendering control issues
Teemu Piippo <teemu@hecknology.net>
parents:
30
diff
changeset
|
273 | this->modelQuaternion = q_x * q_y * this->modelQuaternion; |
55 | 274 | this->updateModelMatrix(); |
17 | 275 | } |
276 | this->lastMousePosition = pointToPointF(event->pos()); | |
277 | } | |
18 | 278 | |
31
b6df269a2c6b
fix remaining rendering control issues
Teemu Piippo <teemu@hecknology.net>
parents:
30
diff
changeset
|
279 | void PartRenderer::wheelEvent(QWheelEvent* event) |
b6df269a2c6b
fix remaining rendering control issues
Teemu Piippo <teemu@hecknology.net>
parents:
30
diff
changeset
|
280 | { |
b6df269a2c6b
fix remaining rendering control issues
Teemu Piippo <teemu@hecknology.net>
parents:
30
diff
changeset
|
281 | static constexpr double WHEEL_STEP = 1 / 1000.0; |
b6df269a2c6b
fix remaining rendering control issues
Teemu Piippo <teemu@hecknology.net>
parents:
30
diff
changeset
|
282 | const double move = (-event->angleDelta().y()) * WHEEL_STEP; |
b6df269a2c6b
fix remaining rendering control issues
Teemu Piippo <teemu@hecknology.net>
parents:
30
diff
changeset
|
283 | this->zoom = std::clamp(this->zoom + move, MIN_ZOOM, MAX_ZOOM); |
b6df269a2c6b
fix remaining rendering control issues
Teemu Piippo <teemu@hecknology.net>
parents:
30
diff
changeset
|
284 | this->updateViewMatrix(); |
b6df269a2c6b
fix remaining rendering control issues
Teemu Piippo <teemu@hecknology.net>
parents:
30
diff
changeset
|
285 | this->update(); |
b6df269a2c6b
fix remaining rendering control issues
Teemu Piippo <teemu@hecknology.net>
parents:
30
diff
changeset
|
286 | } |
b6df269a2c6b
fix remaining rendering control issues
Teemu Piippo <teemu@hecknology.net>
parents:
30
diff
changeset
|
287 | |
55 | 288 | std::optional<glm::vec3> PartRenderer::cameraToGrid(const QPoint& point) |
289 | { | |
290 | glm::vec3 pp = {point.x(), this->height() - point.y(), 1}; | |
291 | pp = glm::inverse(this->viewportMatrix) * pp; | |
292 | glm::mat4 matrix; | |
293 | matrix = this->projectionMatrix * this->viewMatrix * glm::mat4_cast(this->modelQuaternion); | |
294 | matrix = glm::transpose(glm::inverse(matrix)); | |
295 | auto p1 = matrix * glm::vec4{pp.x, pp.y, 0, 1}; | |
296 | auto p2 = matrix * glm::vec4{pp.x, pp.y, 1, 1}; | |
297 | geom::Line line = geom::lineFromPoints(p1, p2); | |
298 | return geom::linePlaneIntersection(line, geom::XY); | |
299 | } | |
300 | ||
301 | QPointF PartRenderer::worldToCamera(const glm::vec3& point) | |
302 | { | |
303 | glm::vec4 p = {point, 1}; | |
304 | p = glm::mat4_cast(this->modelQuaternion) * p; | |
305 | p = this->viewMatrix * p; | |
306 | p = this->projectionMatrix * p; | |
307 | glm::vec2 pp = this->viewportMatrix * glm::vec3{p.x, p.y, 1}; | |
308 | return toQPointF(pp); | |
309 | /* | |
310 | const glm::mat4 matrix = this->projectionMatrix * this->viewMatrix * glm::mat4_cast(this->modelQuaternion); | |
311 | return toQPointF(matrix * glm::vec4{point, 1}); | |
312 | */ | |
313 | } | |
314 | ||
47 | 315 | ldraw::Id PartRenderer::pick(const QPoint& where) |
316 | { | |
317 | const gl::RenderStyle oldRenderStyle = this->renderPreferences.style; | |
318 | this->renderPreferences.style = gl::RenderStyle::PickScene; | |
319 | this->makeCurrent(); | |
320 | this->renderScene(); | |
321 | std::array<GLbyte, 3> data; | |
51 | 322 | this->checkForGLErrors(); |
47 | 323 | glReadPixels(where.x(), this->height() - where.y(), 1, 1, GL_RGB, GL_UNSIGNED_BYTE, &data[0]); |
51 | 324 | this->checkForGLErrors(); |
47 | 325 | this->renderPreferences.style = oldRenderStyle; |
326 | this->update(); | |
327 | return gl::Compiler::idFromColor(data); | |
328 | } | |
329 | ||
37 | 330 | /** |
331 | * @brief Changes the color of rendered fragments | |
332 | * @param newFragmentStyle new fragment style to use | |
333 | */ | |
334 | void PartRenderer::setFragmentStyle(gl::FragmentStyle newFragmentStyle) | |
335 | { | |
336 | this->compiler->setUniform("fragmentStyle", static_cast<int>(newFragmentStyle)); | |
337 | } | |
338 | ||
339 | /** | |
340 | * @brief Changes the way the scene is rendered | |
341 | * @param newStyle new render style to use | |
342 | */ | |
39
caac957e9834
Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents:
37
diff
changeset
|
343 | void PartRenderer::setRenderPreferences(const gl::RenderPreferences& newPreferences) |
18 | 344 | { |
39
caac957e9834
Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents:
37
diff
changeset
|
345 | bool mainColorChanged = this->renderPreferences.mainColor != newPreferences.mainColor; |
44
c6114b3af3a6
added configurable line thickness
Teemu Piippo <teemu@hecknology.net>
parents:
40
diff
changeset
|
346 | bool backgroundColorChanged = this->renderPreferences.backgroundColor != newPreferences.backgroundColor; |
39
caac957e9834
Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents:
37
diff
changeset
|
347 | this->renderPreferences = newPreferences; |
44
c6114b3af3a6
added configurable line thickness
Teemu Piippo <teemu@hecknology.net>
parents:
40
diff
changeset
|
348 | if (mainColorChanged or backgroundColorChanged) |
39
caac957e9834
Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents:
37
diff
changeset
|
349 | { |
caac957e9834
Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents:
37
diff
changeset
|
350 | this->compiler->build(this->model, this->documents, this->renderPreferences); |
55 | 351 | this->setupBackgroundColor(); |
352 | ||
39
caac957e9834
Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents:
37
diff
changeset
|
353 | } |
18 | 354 | this->update(); |
355 | } |