14 * |
14 * |
15 * You should have received a copy of the GNU General Public License |
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/>. |
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 */ |
17 */ |
18 |
18 |
|
19 #include <GL/glew.h> |
19 #include <glm/ext/matrix_transform.hpp> |
20 #include <glm/ext/matrix_transform.hpp> |
20 #include <glm/ext/matrix_clip_space.hpp> |
21 #include <glm/ext/matrix_clip_space.hpp> |
21 #include <QOpenGLFramebufferObject> |
22 #include <QOpenGLFramebufferObject> |
22 #include <QPainter> |
23 #include <QPainter> |
23 #include <GL/glu.h> |
24 #include <GL/glu.h> |
27 #include "src/geometry.h" |
28 #include "src/geometry.h" |
28 #include "src/model.h" |
29 #include "src/model.h" |
29 #include "src/settings.h" |
30 #include "src/settings.h" |
30 #include "src/gl/partrenderer.h" |
31 #include "src/gl/partrenderer.h" |
31 #include "src/gl/compiler.h" |
32 #include "src/gl/compiler.h" |
32 #include "src/gl/debug.h" |
|
33 |
33 |
34 static constexpr double MIN_ZOOM = -3.0; |
34 static constexpr double MIN_ZOOM = -3.0; |
35 static constexpr double MAX_ZOOM = 3.0; |
35 static constexpr double MAX_ZOOM = 3.0; |
36 |
|
37 QOpenGLFunctions& glfunc() |
|
38 { |
|
39 static QOpenGLFunctions funcs; |
|
40 return funcs; |
|
41 } |
|
42 |
36 |
43 PartRenderer::PartRenderer( |
37 PartRenderer::PartRenderer( |
44 Model* model, |
38 Model* model, |
45 DocumentManager* documents, |
39 DocumentManager* documents, |
46 const ColorTable& colorTable, |
40 const ColorTable& colorTable, |
54 this->setFocusPolicy(Qt::WheelFocus); |
48 this->setFocusPolicy(Qt::WheelFocus); |
55 this->setCursor(Qt::CrossCursor); |
49 this->setCursor(Qt::CrossCursor); |
56 QSurfaceFormat surfaceFormat; |
50 QSurfaceFormat surfaceFormat; |
57 surfaceFormat.setSamples(8); |
51 surfaceFormat.setSamples(8); |
58 this->setFormat(surfaceFormat); |
52 this->setFormat(surfaceFormat); |
59 connect(&this->logger, &QOpenGLDebugLogger::messageLogged, [&](const QOpenGLDebugMessage& glmessage){ |
|
60 Q_EMIT this->message(debugMessageToString(glmessage)); |
|
61 }); |
|
62 connect(model, &Model::rowsInserted, [&]{ |
53 connect(model, &Model::rowsInserted, [&]{ |
63 this->needBuild = true; |
54 this->needBuild = true; |
64 }); |
55 }); |
65 connect(model, &Model::rowsRemoved, [&]{ this->needBuild = true; }); |
56 connect(model, &Model::rowsRemoved, [&]{ this->needBuild = true; }); |
66 const auto updateLayerMvpMatrix = [this]{ |
57 const auto updateLayerMvpMatrix = [this]{ |
79 |
70 |
80 PartRenderer::~PartRenderer() |
71 PartRenderer::~PartRenderer() |
81 { |
72 { |
82 } |
73 } |
83 |
74 |
84 static QVector3D calcQVector3DFromQColor(const QColor& color) |
|
85 { |
|
86 return { |
|
87 float_cast(color.redF()), |
|
88 float_cast(color.greenF()), |
|
89 float_cast(color.blueF()), |
|
90 }; |
|
91 } |
|
92 |
|
93 void PartRenderer::initializeGL() |
75 void PartRenderer::initializeGL() |
94 { |
76 { |
95 glfunc().initializeOpenGLFunctions(); |
77 glewInit(); |
96 gl::initializeModelShaders(&this->shaders); |
78 gl::initializeModelShaders(&this->shaders); |
97 for (RenderLayer* layer : this->activeRenderLayers) { |
79 for (RenderLayer* layer : this->activeRenderLayers) { |
98 layer->initializeGL(); |
80 layer->initializeGL(); |
99 } |
81 } |
100 for (RenderLayer* layer : this->inactiveRenderLayers) { |
82 for (RenderLayer* layer : this->inactiveRenderLayers) { |
101 layer->initializeGL(); |
83 layer->initializeGL(); |
102 } |
|
103 this->logger.initialize(); |
|
104 if (setting<Setting::LogOpenGLDebugMessages>()) { |
|
105 this->logger.startLogging(); |
|
106 } |
84 } |
107 connect(this->model, &Model::dataChanged, this, &PartRenderer::build); |
85 connect(this->model, &Model::dataChanged, this, &PartRenderer::build); |
108 this->initialized = true; |
86 this->initialized = true; |
109 this->modelQuaternion = glm::angleAxis(glm::radians(30.0f), glm::vec3{-1, 0, 0}); |
87 this->modelQuaternion = glm::angleAxis(glm::radians(30.0f), glm::vec3{-1, 0, 0}); |
110 this->modelQuaternion *= glm::angleAxis(glm::radians(225.0f), glm::vec3{-0, 1, 0}); |
88 this->modelQuaternion *= glm::angleAxis(glm::radians(225.0f), glm::vec3{-0, 1, 0}); |
497 this->renderPreferences = newPreferences; |
475 this->renderPreferences = newPreferences; |
498 if (mainColorChanged or backgroundColorChanged) |
476 if (mainColorChanged or backgroundColorChanged) |
499 { |
477 { |
500 this->build(); |
478 this->build(); |
501 } |
479 } |
502 if (this->initialized) { |
|
503 this->makeCurrent(); |
|
504 if (setting<Setting::LogOpenGLDebugMessages>()) { |
|
505 this->logger.startLogging(); |
|
506 } |
|
507 else { |
|
508 this->logger.stopLogging(); |
|
509 } |
|
510 } |
|
511 Q_EMIT this->renderPreferencesChanged(); |
480 Q_EMIT this->renderPreferencesChanged(); |
512 this->update(); |
481 this->update(); |
513 } |
482 } |
514 |
483 |
515 /** |
484 /** |